Skip to content

Commit 395d089

Browse files
davidfstrmerwok
authored andcommitted
pythongh-102327: Extend docs for "url" and "headers" parameters to HTTPConnection.request()
Added example on how to use the HTTPConnection object for making GET request. Original issue: python#102327 --------- (cherry picked from commit 7ba6288) Co-authored-by: David Foster <[email protected]> Co-authored-by: Éric <[email protected]>
1 parent 663b321 commit 395d089

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

Doc/library/http.client.rst

+18-2
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ HTTPConnection Objects
262262
encode_chunked=False)
263263

264264
This will send a request to the server using the HTTP request
265-
method *method* and the selector *url*.
265+
method *method* and the request URI *url*. The provided *url* must be
266+
an absolute path to conform with :rfc:`RFC 2616 §5.1.2 <2616#section-5.1.2>`
267+
(unless connecting to an HTTP proxy server or using the ``OPTIONS`` or
268+
``CONNECT`` methods).
266269

267270
If *body* is specified, the specified data is sent after the headers are
268271
finished. It may be a :class:`str`, a :term:`bytes-like object`, an
@@ -277,7 +280,10 @@ HTTPConnection Objects
277280
iterable are sent as is until the iterable is exhausted.
278281

279282
The *headers* argument should be a mapping of extra HTTP headers to send
280-
with the request.
283+
with the request. A :rfc:`Host header <2616#section-14.23>`
284+
must be provided to conform with :rfc:`RFC 2616 §5.1.2 <2616#section-5.1.2>`
285+
(unless connecting to an HTTP proxy server or using the ``OPTIONS`` or
286+
``CONNECT`` methods).
281287

282288
If *headers* contains neither Content-Length nor Transfer-Encoding,
283289
but there is a request body, one of those
@@ -296,6 +302,16 @@ HTTPConnection Objects
296302
HTTPConnection object assumes that all encoding is handled by the
297303
calling code. If it is ``True``, the body will be chunk-encoded.
298304

305+
For example, to perform a ``GET`` request to ``https://docs.python.org/3/``::
306+
307+
>>> import http.client
308+
>>> host = "docs.python.org"
309+
>>> conn = http.client.HTTPSConnection(host)
310+
>>> conn.request("GET", "/3/", headers={"Host": host})
311+
>>> response = conn.getresponse()
312+
>>> print(response.status, response.reason)
313+
200 OK
314+
299315
.. note::
300316
Chunked transfer encoding has been added to the HTTP protocol
301317
version 1.1. Unless the HTTP server is known to handle HTTP 1.1,

0 commit comments

Comments
 (0)