summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubdussamad <samadhaque23@gmail.com>2021-05-17 18:46:55 +0530
committerGitHub <noreply@github.com>2021-05-17 08:16:55 -0500
commit066ed766de83accb990b86a2b714feec0a32697d (patch)
tree72de10ab8a8774b5c4ed307a93dfdb852273ce59
parent52079f1df9d1e3810e02762458bc665c1a438778 (diff)
downloadurllib3-066ed766de83accb990b86a2b714feec0a32697d.tar.gz
Added HTTPHeaderDict to top level module
-rw-r--r--CONTRIBUTORS.txt3
-rw-r--r--docs/user-guide.rst17
-rw-r--r--src/urllib3/__init__.py2
3 files changed, 22 insertions, 0 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index 2ff36d71..0c904979 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -312,5 +312,8 @@ In chronological order:
* Dmitry Mazin <https://archvile.net>
* _put_conn changes and unit tests
+* Ubdussamad <ubdussamad@gmail.com>
+ * Added HTTPHeaderDict to top level objects and added relevant usage documentation for the same.
+
* [Your name or handle] <[email or website]>
* [Brief summary of your changes]
diff --git a/docs/user-guide.rst b/docs/user-guide.rst
index 53464d6a..5fb9bc7f 100644
--- a/docs/user-guide.rst
+++ b/docs/user-guide.rst
@@ -147,6 +147,23 @@ You can specify headers as a dictionary in the ``headers`` argument in :meth:`~p
>>> json.loads(r.data.decode('utf-8'))['headers']
{'X-Something': 'value', ...}
+Or you can use the ``HTTPHeaderDict`` class to create multi-valued HTTP headers:
+
+.. code-block:: pycon
+
+ >>> from urllib3 import HTTPHeaderDict
+ >>> headers = HTTPHeaderDict()
+ >>> headers.add('Accept', 'application/json')
+ >>> headers.add('Accept', 'text/plain')
+ >>> r = http.request(
+ ... 'GET',
+ ... 'http://httpbin.org/headers',
+ ... headers=headers
+ ... )
+ >>> json.loads(r.data.decode('utf-8'))['headers']
+ {'Accept': 'application/json, text/plain', ...}
+
+
Query Parameters
~~~~~~~~~~~~~~~~
diff --git a/src/urllib3/__init__.py b/src/urllib3/__init__.py
index 4e189c34..5b4ca4a4 100644
--- a/src/urllib3/__init__.py
+++ b/src/urllib3/__init__.py
@@ -8,6 +8,7 @@ import warnings
from logging import NullHandler
from . import exceptions
+from ._collections import HTTPHeaderDict
from ._version import __version__
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
from .filepost import encode_multipart_formdata
@@ -23,6 +24,7 @@ __version__ = __version__
__all__ = (
"HTTPConnectionPool",
+ "HTTPHeaderDict",
"HTTPSConnectionPool",
"PoolManager",
"ProxyManager",