From 69e26b8bc8ce205cea4c92c7baa67cd7d16aa093 Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Mon, 17 Dec 2012 17:02:27 +0100 Subject: [PATCH] Requests 1.0: prefetch; default_headers. --- httpie/client.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/httpie/client.py b/httpie/client.py index c3d94f47..35c0d369 100644 --- a/httpie/client.py +++ b/httpie/client.py @@ -4,7 +4,7 @@ from pprint import pformat import requests import requests.auth -from requests.defaults import defaults +from requests.utils import default_headers from . import sessions from . import __version__ @@ -40,14 +40,15 @@ def get_response(args, config_dir): def get_requests_kwargs(args): """Translate our `args` into `requests.request` keyword arguments.""" - base_headers = defaults['base_headers'].copy() - base_headers['User-Agent'] = DEFAULT_UA + implicit_headers = { + 'User-Agent': DEFAULT_UA + } auto_json = args.data and not args.form if args.json or auto_json: - base_headers['Accept'] = 'application/json' + implicit_headers['Accept'] = 'application/json' if args.data: - base_headers['Content-Type'] = JSON + implicit_headers['Content-Type'] = JSON if isinstance(args.data, dict): if args.data: @@ -60,7 +61,11 @@ def get_requests_kwargs(args): elif args.form and not args.files: # If sending files, `requests` will set # the `Content-Type` for us. - base_headers['Content-Type'] = FORM + implicit_headers['Content-Type'] = FORM + + for name, value in implicit_headers.items(): + if name not in args.headers: + args.headers[name] = value credentials = None if args.auth: @@ -70,7 +75,7 @@ def get_requests_kwargs(args): }[args.auth_type](args.auth.key, args.auth.value) kwargs = { - 'prefetch': False, + 'stream': True, 'method': args.method.lower(), 'url': args.url, 'headers': args.headers, @@ -85,9 +90,6 @@ def get_requests_kwargs(args): 'files': args.files, 'allow_redirects': args.follow, 'params': args.params, - 'config': { - 'base_headers': base_headers - } } return kwargs