Skip to content

fix(httpx): Handle cookies correctly on every request path - #2179

Open
Mantisus wants to merge 3 commits into
apify:masterfrom
Mantisus:httpx-cookie
Open

fix(httpx): Handle cookies correctly on every request path#2179
Mantisus wants to merge 3 commits into
apify:masterfrom
Mantisus:httpx-cookie

Conversation

@Mantisus

Copy link
Copy Markdown
Collaborator

Description

  • Unified cookie handling across all the ways HttpxHttpClient sends a request.
  • Fixed possible incorrect cookie handling when the client goes through a proxy.
  • Optimized header generation for HttpxHttpClient.

Testing

  • Added new testing to check the processing cookies.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates HttpxHttpClient to unify cookie handling across request paths (including redirects and proxies) and adjusts header generation so the default “browser-like” headers come from a single sampled profile. It also reshuffles/extends unit tests to validate cookie behavior across clients and introduces a deprecation warning for HeaderGenerator.get_common_headers().

Changes:

  • Reworked HttpxHttpClient request construction and transport behavior to rebuild Cookie headers per hop and to keep cookie state in Session (including when proxying).
  • Updated header generation to request a consistent set of headers from HeaderGenerator.get_specific_headers() (single profile sample) and added tests around this.
  • Consolidated cookie/session tests across HTTP clients and added proxy + redirect coverage; deprecated get_common_headers() with a warning and updated tests accordingly.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/unit/http_clients/test_impit.py Removes Impit-specific cookie/session tests that were moved to shared HTTP client test coverage.
tests/unit/http_clients/test_httpx.py Adds Httpx-specific tests for same-origin logic, proxy-kwarg behavior, and header sampling behavior.
tests/unit/http_clients/test_http_clients.py Adds shared cookie/session behavior tests across all HTTP clients, including proxy scenarios.
tests/unit/fingerprint_suite/test_header_generator.py Updates test to assert the new deprecation warning for get_common_headers().
src/crawlee/http_clients/_httpx.py Implements unified cookie handling across request paths (redirects + proxies), refactors request building, and optimizes generated header selection.
src/crawlee/fingerprint_suite/_header_generator.py Marks get_common_headers() as deprecated and emits a DeprecationWarning.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/unit/http_clients/test_httpx.py Outdated
Comment thread src/crawlee/http_clients/_httpx.py Outdated
Mantisus and others added 2 commits August 20, 2026 14:35
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Mantisus
Mantisus requested review from Pijukatel and vdusek August 20, 2026 11:59
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