Skip to content
Myr

Support for proxies

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by moliware · committed by moliware · parent bbd1e40 · Browse files · 3 files+29 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+29 added−13 removed

  • other:+29 added−13 removed

3 files+29 added−13 removed

modified:requests/api.py+22 added-12 removed
17 unmodified lines
1819__all__ = ('request', 'get', 'head', 'post', 'put', 'delete')2021def request(method, url, params=None, data=None, headers=None, cookies=None, files=None, auth=None,22 timeout=None, allow_redirects=False):22 timeout=None, allow_redirects=False, proxies=None):23 """Constructs and sends a :class:`Request <models.Request>`. Returns :class:`Response <models.Response>` object.2425 :param method: method for the new :class:`Request` object.26 :param url: URL for the new :class:`Request` object.
4 unmodified lines
31 :param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.32 :param auth: (optional) AuthObject to enable Basic HTTP Auth.33 :param timeout: (optional) Float describing the timeout of the request.34 :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.35 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.36 """3738 r = Request(39 method = method,
4 unmodified lines
44 cookiejar = cookies,45 files = files,46 auth = auth or auth_manager.get_auth(url),47 timeout = timeout or config.settings.timeout,47 allow_redirects = allow_redirects48 allow_redirects = allow_redirects,49 proxies = proxies50 )5152 r.send()5354 return r.response5554def get(url, params=None, headers=None, cookies=None, auth=None, timeout=None):56def get(url, params=None, headers=None, cookies=None, auth=None, timeout=None, proxies=None):57 """Sends a GET request. Returns :class:`Response` object.5859 :param url: URL for the new :class:`Request` object.60 :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`.61 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.62 :param cookies: (optional) CookieJar object to send with the :class:`Request`.63 :param auth: (optional) AuthObject to enable Basic HTTP Auth.64 :param timeout: (optional) Float describing the timeout of the request.65 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.66 """6765 return request('GET', url, params=params, headers=headers, cookies=cookies, auth=auth, timeout=timeout)68 return request('GET', url, params=params, headers=headers, cookies=cookies, auth=auth, timeout=timeout,69 proxies=proxies)707168def head(url, params=None, headers=None, cookies=None, auth=None, timeout=None):72def head(url, params=None, headers=None, cookies=None, auth=None, timeout=None, proxies=None):73 """Sends a HEAD request. Returns :class:`Response` object.7475 :param url: URL for the new :class:`Request` object.76 :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`.77 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.78 :param cookies: (optional) CookieJar object to send with the :class:`Request`.79 :param auth: (optional) AuthObject to enable Basic HTTP Auth.80 :param timeout: (optional) Float describing the timeout of the request.81 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.82 """8379 return request('HEAD', url, params=params, headers=headers, cookies=cookies, auth=auth, timeout=timeout)84 return request('HEAD', url, params=params, headers=headers, cookies=cookies, auth=auth, timeout=timeout,85 proxies=proxies)868788def post(url, data='', headers=None, files=None, cookies=None, auth=None,83 timeout=None, allow_redirects=False, params=None):89 timeout=None, allow_redirects=False, params=None, proxies=None):90 """Sends a POST request. Returns :class:`Response` object.9192 :param url: URL for the new :class:`Request` object.93 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.
3 unmodified lines
97 :param auth: (optional) AuthObject to enable Basic HTTP Auth.98 :param timeout: (optional) Float describing the timeout of the request.99 :param allow_redirects: (optional) Boolean. Set to True if redirect following is allowed.100 :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`.101 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.102 """103104 return request('POST', url, params=params, data=data, headers=headers,105 files=files, cookies=cookies, auth=auth, timeout=timeout,99 allow_redirects=allow_redirects)106 allow_redirects=allow_redirects, proxies=proxies)107108109def put(url, data='', headers=None, files=None, cookies=None, auth=None,103 timeout=None, allow_redirects=False, params=None):110 timeout=None, allow_redirects=False, params=None, proxies=None):111 """Sends a PUT request. Returns :class:`Response` object.112113 :param url: URL for the new :class:`Request` object.114 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.
3 unmodified lines
118 :param auth: (optional) AuthObject to enable Basic HTTP Auth.119 :param timeout: (optional) Float describing the timeout of the request.120 :param allow_redirects: (optional) Boolean. Set to True if redirect following is allowed.121 :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`.122 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.123 """124125 return request('PUT', url, params=params, data=data, headers=headers,126 files=files, cookies=cookies, auth=auth, timeout=timeout,119 allow_redirects=allow_redirects)127 allow_redirects=allow_redirects, proxies=proxies)128129122def delete(url, params=None, headers=None, cookies=None, auth=None, timeout=None, allow_redirects=False):130def delete(url, params=None, headers=None, cookies=None, auth=None, timeout=None, allow_redirects=False,131 proxies=None):132 """Sends a DELETE request. Returns :class:`Response` object.133134 :param url: URL for the new :class:`Request` object.135 :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`.
1 unmodified line
137 :param cookies: (optional) CookieJar object to send with the :class:`Request`.138 :param auth: (optional) AuthObject to enable Basic HTTP Auth.139 :param timeout: (optional) Float describing the timeout of the request.140 :param allow_redirects: (optional) Boolean. Set to True if redirect following is allowed.141 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.142 """143144 return request('DELETE', url, params=params, headers=headers, cookies=cookies, auth=auth,135 timeout=timeout, allow_redirects=allow_redirects)145 timeout=timeout, allow_redirects=allow_redirects, proxies=proxies)
modified:requests/models.py+6 added-1 removed
30 unmodified lines
31 _METHODS = ('GET', 'HEAD', 'PUT', 'POST', 'DELETE')3233 def __init__(self, url=None, headers=dict(), files=None, method=None,34 data=dict(), params=dict(), auth=None, cookiejar=None,35 timeout=None, redirect=False, allow_redirects=False):35 timeout=None, redirect=False, allow_redirects=False,36 proxies=None):3738 socket.setdefaulttimeout(timeout)3940 #: Request URL.
14 unmodified lines
55 #: and HTTPError storage).56 self.redirect = redirect57 #: Set to True if full redirects are allowed (e.g. re-POST-ing of data at new ``Location``)58 self.allow_redirects = allow_redirects59 # Dictionary mapping protocol to the URL of the proxy (e.g. {'http': 'foo.bar:3128'})60 self.proxies = proxies6162 self.data, self._enc_data = self._encode_params(data)63 self.params, self._enc_params = self._encode_params(params)64
47 unmodified lines
112 auth_manager.add_auth(self.url, self.auth)113114 _handlers.append(self.auth.handler)115116 if self.proxies:117 _handlers.append(urllib2.ProxyHandler(self.proxies))118119 _handlers.append(HTTPRedirectHandler)120121 if not _handlers:
413 unmodified lines
modified:AUTHORS+1 added
22 unmodified lines
23- Daniel Schauenberg24- Zbigniew Siciarz25- Daniele Tricoli 'Eriol'26- Richard Boulton27- Miguel Olivares <miguel@moliware.com>