Move redirect and cookie handling into a shared `HttpClient` base class · Issue #2307 · apify/crawlee-python · GitHub
Skip to content

Move redirect and cookie handling into a shared HttpClient base class #2307

Open

Description

@vdusek

HttpClient has three abstract entry points (crawl, send_request, stream in http_clients/_base.py). Each implementation re-implements redirect hops, the per-hop Cookie header, stripping credentials on cross-origin redirects and saving Set-Cookie into the session: ImpitHttpClient._request_with_redirects, the HttpxHttpClient transport adapter, and the curl client. A custom client has to get all of that right on its own.

JS v4 moved cookie and redirect handling into a BaseHttpClient, and a custom client implements a single fetch-like method. This is the concrete shape for #874.

Proposed solution

  • An abstract per-hop primitive that a client implements. The base class follows redirects, assembles cookies from the session and persists response cookies, once for all clients.
  • Merge a Cookie header passed by the caller with the session cookies by name, with the caller winning per cookie. Today the caller's header replaces the session cookies entirely, in both impit and httpx. Consider a per-call cookie jar override, as in JS.
  • Rename persist_cookies_per_session to save_response_cookies, and decide whether it becomes a crawler option, as in JS.

This will be a breaking change.

JS references

✍️ Drafted by Claude Code

Activity

  1. added this to the 2.0 milestone on Oct 13, 2026
  2. added
    t-toolingIssues with this label are in the ownership of the tooling team.
    debtCode quality improvement or decrease of technical debt.
    on Oct 13, 2026
  3. janbuchar commented on Oct 15, 2026

    @janbuchar
    Collaborator

    This will be a breaking change.

    Explain how? 😁

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    debtCode quality improvement or decrease of technical debt.t-toolingIssues with this label are in the ownership of the tooling team.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions