@@ -132,16 +132,16 @@ The :mod:`urllib.request` module defines the following functions:
132132
133133The following classes are provided:
134134
135- .. class :: Request(url, data=None, headers={}, origin_req_host=None, unverifiable=False)
135+ .. class :: Request(url, data=None, headers={}, origin_req_host=None, unverifiable=False, method=None )
136136
137137 This class is an abstraction of a URL request.
138138
139139 *url * should be a string containing a valid URL.
140140
141141 *data * may be a string specifying additional data to send to the
142142 server, or ``None `` if no such data is needed. Currently HTTP
143- requests are the only ones that use *data *; the HTTP request will
144- be a POST instead of a GET when the * data * parameter is provided .
143+ requests are the only ones that use *data *, in order to choose between
144+ `` 'GET' `` and `` ' POST' `` when * method * is not specified .
145145 *data * should be a buffer in the standard
146146 :mimetype: `application/x-www-form-urlencoded ` format. The
147147 :func: `urllib.parse.urlencode ` function takes a mapping or sequence
@@ -157,8 +157,8 @@ The following classes are provided:
157157 :mod: `urllib `'s default user agent string is
158158 ``"Python-urllib/2.6" `` (on Python 2.6).
159159
160- The final two arguments are only of interest for correct handling
161- of third-party HTTP cookies:
160+ The following two arguments, * origin_req_host * and * unverifiable *,
161+ are only of interest for correct handling of third-party HTTP cookies:
162162
163163 *origin_req_host * should be the request-host of the origin
164164 transaction, as defined by :rfc: `2965 `. It defaults to
@@ -175,6 +175,13 @@ The following classes are provided:
175175 document, and the user had no option to approve the automatic
176176 fetching of the image, this should be true.
177177
178+ *method * should be a string that indicates the HTTP request method that
179+ will be used (e.g. ``'HEAD' ``). Its value is stored in the
180+ :attr: `Request.method ` attribute and is used by :meth: `Request.get_method() `.
181+
182+ .. versionchanged :: 3.3
183+ :attr: `Request.method ` argument is added to the Request class.
184+
178185
179186.. class :: OpenerDirector()
180187
@@ -369,6 +376,15 @@ request.
369376 boolean, indicates whether the request is unverifiable as defined
370377 by RFC 2965.
371378
379+ .. attribute :: Request.method
380+
381+ The HTTP request method to use. This value is used by
382+ :meth: `Request.get_method ` to override the computed HTTP request
383+ method that would otherwise be returned. This attribute is
384+ initialized with the value of the *method * argument passed to the constructor.
385+
386+ ..versionadded:: 3.3
387+
372388.. method :: Request.add_data(data)
373389
374390 Set the :class: `Request ` data to *data *. This is ignored by all handlers except
@@ -378,8 +394,13 @@ request.
378394
379395.. method :: Request.get_method()
380396
381- Return a string indicating the HTTP request method. This is only meaningful for
382- HTTP requests, and currently always returns ``'GET' `` or ``'POST' ``.
397+ Return a string indicating the HTTP request method. If
398+ :attr: `Request.method ` is not ``None ``, return its value, otherwise return
399+ ``'GET' `` if :attr: `Request.data ` is ``None ``, or ``'POST' `` if it's not.
400+ This is only meaningful for HTTP requests.
401+
402+ .. versionchanged :: 3.3
403+ get_method now looks at the value of :attr: `Request.method ` first.
383404
384405
385406.. method :: Request.has_data()
0 commit comments