__all__ = ['RecentlyUsedContainer', 'HTTPHeaderDict']
-MULTIPLE_HEADERS_ALLOWED = frozenset(['cookie', 'set-cookie', 'set-cookie2'])
-
_Null = object()
def __init__(self, headers=None, **kwargs):
dict.__init__(self)
if headers is not None:
- self.extend(headers)
+ if isinstance(headers, HTTPHeaderDict):
+ self._copy_from(headers)
+ else:
+ self.extend(headers)
if kwargs:
self.extend(kwargs)
vals.append(val)
else:
# vals should be a tuple then, i.e. only one item so far
- if key_lower in MULTIPLE_HEADERS_ALLOWED:
- # Need to convert the tuple to list for further extension
- _dict_setitem(self, key_lower, [vals[0], vals[1], val])
- else:
- _dict_setitem(self, key_lower, new_vals)
+ # Need to convert the tuple to list for further extension
+ _dict_setitem(self, key_lower, [vals[0], vals[1], val])
def extend(*args, **kwargs):
"""Generic import function for any type of header-like object.
def __repr__(self):
return "%s(%s)" % (type(self).__name__, dict(self.itermerged()))
- def copy(self):
- clone = type(self)()
- for key in self:
- val = _dict_getitem(self, key)
+ def _copy_from(self, other):
+ for key in other:
+ val = _dict_getitem(other, key)
if isinstance(val, list):
# Don't need to convert tuples
val = list(val)
- _dict_setitem(clone, key, val)
+ _dict_setitem(self, key, val)
+
+ def copy(self):
+ clone = type(self)()
+ clone._copy_from(self)
return clone
def iteritems(self):
from binascii import hexlify, unhexlify
from hashlib import md5, sha1, sha256
-from ..exceptions import SSLError
+from ..exceptions import SSLError, InsecurePlatformWarning
SSLContext = None
import errno
import ssl
+import warnings
try: # Test for SSL features
from ssl import wrap_socket, CERT_NONE, PROTOCOL_SSLv23
self.ciphers = cipher_suite
def wrap_socket(self, socket, server_hostname=None):
+ warnings.warn(
+ 'A true SSLContext object is not available. This prevents '
+ 'urllib3 from configuring SSL appropriately and may cause '
+ 'certain SSL connections to fail. For more information, see '
+ 'https://urllib3.readthedocs.org/en/latest/security.html'
+ '#insecureplatformwarning.',
+ InsecurePlatformWarning
+ )
kwargs = {
'keyfile': self.keyfile,
'certfile': self.certfile,