This repository was archived by the owner on Jan 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
Add connection/read timeout for requests adapter #342
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
153cfac
Add connection/read timeout for requests adapter
1e7739a
Add connection/read timeout for requests adapter
hyxbiao 7be26b6
update requests integration test
hyxbiao 8c310c7
explicit timeout and more timeout tests
hyxbiao 28c5699
update timeout tests for py3
hyxbiao 1417c51
update timeout tests for py3
hyxbiao 09dfa86
explicit timeout in send method and update timeout tests
hyxbiao f0bc05c
add timeout in common/HTTPConnection and update timeout tests
hyxbiao ead832b
move timeout in _h1/2_kwargs; add timeout for _create_tunnel funciton…
hyxbiao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,6 +150,15 @@ def __init__(self, host, port=None, secure=None, ssl_context=None, | |
| #: the standard hyper parsing interface. | ||
| self.parser = Parser() | ||
|
|
||
| # timeout | ||
| timeout = kwargs.get('timeout') | ||
|
||
| if isinstance(timeout, tuple): | ||
| self._connect_timeout = timeout[0] | ||
| self._read_timeout = timeout[1] | ||
| else: | ||
| self._connect_timeout = timeout | ||
| self._read_timeout = timeout | ||
|
|
||
| def connect(self): | ||
| """ | ||
| Connect to the server specified when the object was created. This is a | ||
|
|
@@ -172,10 +181,11 @@ def connect(self): | |
| # Simple http proxy | ||
| sock = socket.create_connection( | ||
| (self.proxy_host, self.proxy_port), | ||
| 5 | ||
| timeout=self._connect_timeout | ||
| ) | ||
| else: | ||
| sock = socket.create_connection((self.host, self.port), 5) | ||
| sock = socket.create_connection((self.host, self.port), | ||
| timeout=self._connect_timeout) | ||
| proto = None | ||
|
|
||
| if self.secure: | ||
|
|
@@ -184,6 +194,9 @@ def connect(self): | |
| log.debug("Selected protocol: %s", proto) | ||
| sock = BufferedSocket(sock, self.network_buffer_size) | ||
|
|
||
| # Set read timeout | ||
| sock.settimeout(self._read_timeout) | ||
|
|
||
| if proto not in ('http/1.1', None): | ||
| raise TLSUpgrade(proto, sock) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We shouldn't be sending arbitrary kwargs from Requests to hyper: there's no reason to assume that those kwargs will match in any sensible way. We should aim to be explicit here.
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.
OK, I had change to explicit timeout and add more timeout tests