summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Petrov <andrey.petrov@shazow.net>2014-06-25 12:30:04 -0700
committerAndrey Petrov <andrey.petrov@shazow.net>2014-06-25 15:54:55 -0700
commita26ec330bd72d276b84da33c548d776213438cd7 (patch)
treef87e8020e98779cf0f53af390437f8eb39c442f5
parent2c8d3db32896737edeb75eb9944975fec0d72ce5 (diff)
downloadurllib3-a26ec330bd72d276b84da33c548d776213438cd7.tar.gz
More rebase fixen.
-rw-r--r--urllib3/response.py2
-rw-r--r--urllib3/util/__init__.py3
-rw-r--r--urllib3/util/request.py31
-rw-r--r--urllib3/util/response.py13
4 files changed, 28 insertions, 21 deletions
diff --git a/urllib3/response.py b/urllib3/response.py
index 92c5c31c..c1620da6 100644
--- a/urllib3/response.py
+++ b/urllib3/response.py
@@ -11,7 +11,7 @@ from socket import timeout as SocketTimeout
from ._collections import HTTPHeaderDict
from .exceptions import ConnectionError, DecodeError, ReadTimeoutError
from .packages.six import string_types as basestring, binary_type
-from .connection import HTTPException, BaseSSLError
+from .connection import HTTPException
from .util.response import is_fp_closed
diff --git a/urllib3/util/__init__.py b/urllib3/util/__init__.py
index dd3e17b4..1d655073 100644
--- a/urllib3/util/__init__.py
+++ b/urllib3/util/__init__.py
@@ -6,7 +6,8 @@
# For backwards compatibility, provide imports that used to be here.
from .connection import is_connection_dropped
-from .request import is_fp_closed, make_headers
+from .request import make_headers
+from .response import is_fp_closed
from .ssl_ import (
SSLContext,
HAS_SNI,
diff --git a/urllib3/util/request.py b/urllib3/util/request.py
index 160ce7b2..7211669d 100644
--- a/urllib3/util/request.py
+++ b/urllib3/util/request.py
@@ -6,26 +6,13 @@
from base64 import b64encode
-from ..packages import six
+from ..packages.six import b
-
-def is_fp_closed(obj):
- """
- Checks whether a given file-like object is closed.
-
- :param obj:
- The file-like object to check.
- """
- if hasattr(obj, 'fp'):
- # Object is a container for another file-like object that gets released
- # on exhaustion (e.g. HTTPResponse)
- return obj.fp is None
-
- return obj.closed
+ACCEPT_ENCODING = 'gzip,deflate'
def make_headers(keep_alive=None, accept_encoding=None, user_agent=None,
- basic_auth=None, proxy_basic_auth=None):
+ basic_auth=None, proxy_basic_auth=None, disable_cache=None):
"""
Shortcuts for generating request headers.
@@ -50,6 +37,9 @@ def make_headers(keep_alive=None, accept_encoding=None, user_agent=None,
Colon-separated username:password string for 'proxy-authorization: basic ...'
auth header.
+ :param disable_cache:
+ If ``True``, adds 'cache-control: no-cache' header.
+
Example: ::
>>> make_headers(keep_alive=True, user_agent="Batman/1.0")
@@ -64,7 +54,7 @@ def make_headers(keep_alive=None, accept_encoding=None, user_agent=None,
elif isinstance(accept_encoding, list):
accept_encoding = ','.join(accept_encoding)
else:
- accept_encoding = 'gzip,deflate'
+ accept_encoding = ACCEPT_ENCODING
headers['accept-encoding'] = accept_encoding
if user_agent:
@@ -75,10 +65,13 @@ def make_headers(keep_alive=None, accept_encoding=None, user_agent=None,
if basic_auth:
headers['authorization'] = 'Basic ' + \
- b64encode(six.b(basic_auth)).decode('utf-8')
+ b64encode(b(basic_auth)).decode('utf-8')
if proxy_basic_auth:
headers['proxy-authorization'] = 'Basic ' + \
- b64encode(six.b(proxy_basic_auth)).decode('utf-8')
+ b64encode(b(proxy_basic_auth)).decode('utf-8')
+
+ if disable_cache:
+ headers['cache-control'] = 'no-cache'
return headers
diff --git a/urllib3/util/response.py b/urllib3/util/response.py
new file mode 100644
index 00000000..d0325bc6
--- /dev/null
+++ b/urllib3/util/response.py
@@ -0,0 +1,13 @@
+def is_fp_closed(obj):
+ """
+ Checks whether a given file-like object is closed.
+
+ :param obj:
+ The file-like object to check.
+ """
+ if hasattr(obj, 'fp'):
+ # Object is a container for another file-like object that gets released
+ # on exhaustion (e.g. HTTPResponse)
+ return obj.fp is None
+
+ return obj.closed