Skip to content

Conversation

@Ajay9704
Copy link

Summary

This PR fixes an issue where custom cookie policies set on a Session's cookie jar were not being preserved during request preparation.

Details

In Session.prepare_request(), when merging cookies from the session and request, the code was creating a new RequestsCookieJar() without preserving the cookie policy from the session's cookie jar. This meant that any custom cookie policy (like MyCustomCookiePolicy in issue #7122) would be lost during request preparation.

Fix

Modified the cookie merging logic to check if the session's cookies are a RequestsCookieJar and, if so, preserve the cookie policy by copying it to the new jar using set_policy().

Testing

The fix has been tested to ensure:

  • Custom cookie policies are now preserved during Session.prepare_request
  • Policy methods are properly consulted during request preparation
  • Restrictive policies correctly prevent cookies from being sent
  • Permissive policies still allow cookies to be sent as expected
  • Existing functionality remains unaffected

Fixes #7122

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.

Unable to override cookie policy in Session.prepare_request

1 participant