Skip to content

Allow to pass own http_client to ApifyClient and ApifyClientAsync #416

Closed

Description

@Pijukatel

This enables customization of the client for use cases which are not covered by the default client.

Discussed here: #400
Another use case described by @drobnikj

Activity

  1. added
    enhancementNew feature or request.
    t-toolingIssues with this label are in the ownership of the tooling team.
    on Jun 6, 2025
  2. Pijukatel commented on Sep 16, 2025

    @Pijukatel
    ContributorAuthor

    Previously, when users wanted to create their own headers, they could do something like this:

    apify_client = ApifyClient(...)
    apify_client.http_client.httpx_client.headers.update(custom_headers)
    

    After changing to impit, this no longer seems possible. Setting custom headers is not uncommon and should be supported by the client without any problems.

    Now, when they want to change headers, they have to resort to monkeypatching and manipulating private methods, for example:

    custom_header = {"bla": "blo"}
    
    client=ApifyClientAsync(token="asd")
    orig_prepare_request_call = client.http_client._prepare_request_call
    
    def wrapped_prepare_request_call(*args, **kwargs):
        headers, _parsed_params, data = orig_prepare_request_call(*args, **kwargs)
        headers.update(custom_header)
        return headers, _parsed_params, data
    
    client.http_client._prepare_request_call = wrapped_prepare_request_call
    
  3. self-assigned this
    on Feb 4, 2026
  4. added this to the 3.0 milestone on Feb 4, 2026
  5. added a commit that references this issue on Feb 26, 2026
    5ae33a0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request.t-toolingIssues with this label are in the ownership of the tooling team.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions