Skip to content

Fix self.headers got modified during request#41

Open
keatonLiu wants to merge 17 commits intorawandahmad698:masterfrom
keatonLiu:master
Open

Fix self.headers got modified during request#41
keatonLiu wants to merge 17 commits intorawandahmad698:masterfrom
keatonLiu:master

Conversation

@keatonLiu
Copy link

@keatonLiu keatonLiu commented Sep 29, 2025

When the json parameter is set, execute_request does not ignore the previously inferred content_type, even if data is None.

This behavior is caused by the following logic:

# set content type if it isn't set
if content_type is not None and "content-type" not in self.headers:
    self.headers["Content-Type"] = content_type

The issue is that self.headers may have already been modified by a previous request. For example, if the inferred Content-Type of the previous request was application/x-www-form-urlencoded, it remains in self.headers. As a result, the current request may incorrectly reuse that Content-Type, which is unexpected when json is used.

To fix this, we should:

  1. First merge/process the headers (including any user-provided Content-Type).
  2. Then check whether Content-Type is already set using the CaseInsensitiveDict behavior.
  3. Only if it is not set, apply the inferred content_type.

This ensures that:

  • User-specified headers always take precedence.
  • The inferred Content-Type is only applied when truly missing.
  • A previous request’s header does not unintentionally leak into the next request.

@keatonLiu
Copy link
Author

Could I know why is it closed?

@rawandahmad698
Copy link
Owner

Could I know why is it closed?

Please resolve the conflicts we can resolve open and merge it today

@keatonLiu
Copy link
Author

Could I know why is it closed?

Please resolve the conflicts we can resolve open and merge it today

I have resolved the confilcts, please check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants