Merge request_kwargs headers with defaults (closes #3551)#3831
Open
genisis0x wants to merge 1 commit intoApeWorX:mainfrom
Open
Merge request_kwargs headers with defaults (closes #3551)#3831genisis0x wants to merge 1 commit intoApeWorX:mainfrom
genisis0x wants to merge 1 commit intoApeWorX:mainfrom
Conversation
`(Async)HTTPProvider.get_request_kwargs` previously yielded the default
headers only when `headers` was absent from `request_kwargs`. Passing
`request_kwargs={"headers": {"Authorization": "Bearer ..."}}` therefore
silently dropped the required `Content-Type: application/json` and
`User-Agent` defaults.
Merge user-supplied headers on top of the defaults so callers can extend
the headers without losing the defaults; user keys still take precedence
on conflict (e.g. a custom `User-Agent` is honored).
Adds tests covering the merge, override, and unrelated kwargs cases for
both `HTTPProvider` and `AsyncHTTPProvider`.
Closes ApeWorX#3551
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What was wrong?
Closes #3551.
(Async)HTTPProvider.get_request_kwargsonly yields the default headers fromget_request_headers()whenheadersis absent fromrequest_kwargs:So passing any custom headers silently drops the required defaults:
This matches what @souliane reported in #3551: passing
request_kwargs["headers"]should extend the defaults fromHTTPProvider.get_request_headers, not replace them.How was it fixed?
get_request_kwargsnow merges the defaults with the user-supplied headers (user keys win on conflict), and yields the remainingrequest_kwargsitems unchanged.Same change applied to
AsyncHTTPProvider.Cute Animal Picture
Type of change
Test plan
tests/core/providers/test_http_provider.pyandtests/core/providers/test_async_http_provider.pycovering:Content-Type/User-Agentpreserved alongsideAuthorization)User-Agent)request_kwargs(e.g.timeout) are preserved alongside merged headerstest_get_request_headersparametrized test continues to pass (defaults unchanged when no override).newsfragments/3551.bugfix.rst.Notes
The behavior change is opt-in to anyone who was already passing
request_kwargs["headers"]; previously they were dropping the defaults. After this change those callers will additionally receive the defaults, which is what the public docstring onget_request_headersalready implies.