Add urllib3 transport #659
Add urllib3 transport #659
Conversation
refresh_status_codes (Sequence): Which HTTP status code indicate that | ||
credentials should be refreshed and the request should be retried. | ||
""" | ||
def __init__(self, http, credentials, refresh_status_codes): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
self.refresh_status_codes = refresh_status_codes | ||
|
||
def urlopen(self, method, url, body=None, headers=None, | ||
_credential_refresh_attempt=0, **kwargs): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
headers = self.headers | ||
|
||
# Copy the request headers because this may be called recursively. | ||
request_headers = _helpers.initialize_headers(headers).copy() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return urllib3.PoolManager(*args, **kwargs) | ||
|
||
|
||
class AuthorizedHttp(request.RequestMethods): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
# A stored token may expire between the time it is retrieved and | ||
# the time the request is made, so we may need to try twice. | ||
# The reason urllib3's retries aren't used is because they | ||
# don't allow you to modify the request headers. :/ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
The behavior is transport-specific, but all transports will return a new | ||
http object that provides credentials to requests and refreshed credentials | ||
when a response in REFRESH_STATUS_CODES is received. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
The arguments match :func:`oauth2client.transport.request`. Additional | ||
arguments are passed through to | ||
:meth:`urllib3.request.RequestMethods.request`. | ||
|
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
urllib3.response.HTTPResponse: The HTTP response. | ||
""" | ||
response = http.request(method, uri, body=body, headers=headers, **kwargs) | ||
return response |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -24,7 +24,7 @@ | |||
NXDOMAIN = 'test.invalid' | |||
|
|||
|
|||
def test_server_app(): | |||
def server_app(): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
import urllib3 | ||
import urllib3.exceptions | ||
import mock |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
a8c9095
to
efda9c8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.