-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
5677: Respect variable precedence in session #5735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -527,18 +527,16 @@ def request(self, method, url, | |
| ) | ||
| prep = self.prepare_request(req) | ||
|
|
||
| proxies = proxies or {} | ||
|
|
||
| settings = self.merge_environment_settings( | ||
| prep.url, proxies, stream, verify, cert | ||
| ) | ||
|
|
||
| # Send the request. | ||
| send_kwargs = { | ||
| 'timeout': timeout, | ||
| 'allow_redirects': allow_redirects, | ||
| 'verify': verify, | ||
| 'proxies': proxies, | ||
| 'stream': stream, | ||
| 'cert': cert, | ||
| } | ||
| send_kwargs.update(settings) | ||
|
|
||
| # Send the request. | ||
| resp = self.send(prep, **send_kwargs) | ||
|
|
||
| return resp | ||
|
|
@@ -628,23 +626,28 @@ def send(self, request, **kwargs): | |
|
|
||
| :rtype: requests.Response | ||
| """ | ||
| # Set defaults that the hooks can utilize to ensure they always have | ||
| # the correct parameters to reproduce the previous request. | ||
| kwargs.setdefault('stream', self.stream) | ||
| kwargs.setdefault('verify', self.verify) | ||
| kwargs.setdefault('cert', self.cert) | ||
| kwargs.setdefault('proxies', self.rebuild_proxies(request, self.proxies)) | ||
|
|
||
| # It's possible that users might accidentally send a Request object. | ||
| # Guard against that specific failure case. | ||
| if isinstance(request, Request): | ||
| raise ValueError('You can only send PreparedRequests.') | ||
|
|
||
| # Set defaults that the hooks can utilize to ensure they always have | ||
| # the correct parameters to reproduce the previous request. | ||
| stream = kwargs.get('stream') | ||
| verify = kwargs.get('verify') | ||
| cert = kwargs.get('cert') | ||
| proxies = kwargs.get('proxies') | ||
|
|
||
| # Set up variables needed for resolve_redirects and dispatching of hooks | ||
| allow_redirects = kwargs.pop('allow_redirects', True) | ||
| stream = kwargs.get('stream') | ||
| hooks = request.hooks | ||
|
|
||
| # Merge with environment variables | ||
| settings = self.merge_environment_settings( | ||
| request.url, proxies, stream, verify, cert | ||
| ) | ||
| kwargs.update(settings) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally I don't like to reuse |
||
|
|
||
| # Get the appropriate adapter to use | ||
| adapter = self.get_adapter(url=request.url) | ||
|
|
||
|
|
@@ -704,6 +707,15 @@ def merge_environment_settings(self, url, proxies, stream, verify, cert): | |
|
|
||
| :rtype: dict | ||
| """ | ||
|
|
||
| # Merge all the kwargs. | ||
| proxies = merge_setting(proxies, self.proxies) | ||
| stream = merge_setting(stream, self.stream) | ||
| verify = merge_setting(verify, self.verify) | ||
| cert = merge_setting(cert, self.cert) | ||
|
|
||
| proxies = proxies or {} | ||
|
|
||
| # Gather clues from the surrounding environment. | ||
| if self.trust_env: | ||
| # Set environment's proxies. | ||
|
|
@@ -716,13 +728,7 @@ def merge_environment_settings(self, url, proxies, stream, verify, cert): | |
| # with cURL. | ||
| if verify is True or verify is None: | ||
| verify = (os.environ.get('REQUESTS_CA_BUNDLE') or | ||
| os.environ.get('CURL_CA_BUNDLE')) | ||
|
|
||
| # Merge all the kwargs. | ||
| proxies = merge_setting(proxies, self.proxies) | ||
| stream = merge_setting(stream, self.stream) | ||
| verify = merge_setting(verify, self.verify) | ||
| cert = merge_setting(cert, self.cert) | ||
| os.environ.get('CURL_CA_BUNDLE') or verify) | ||
|
|
||
| return {'verify': verify, 'proxies': proxies, 'stream': stream, | ||
| 'cert': cert} | ||
|
|
||
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.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
Before #5681, the
sendmethod was not using the environment variables at all, this was here to ensure that those would be read at some point.However, this MR also moves the call for
merge_environment_settingstosend, thus rebuilding proxies is not necessary. Before, it was only issued in therequestmethod.