Skip to content

How to add headers for proxy? #1804

Description

@FoliageOwO

Is there any possible way to add authorization headers in HTTP proxy through CONNECT tunnel?

With curl, I can do:

$ curl -x http://127.0.0.1:8888 https://example.com --proxy-header "X-Proxy-Authorization: TOKEN"

which adds an authorization header for the HTTP proxy http://127.0.0.1:8888.

Seemingly there does not exist a hook or any configuration to allow me to do this.

Activity

  1. TekExplorer commented on Feb 13, 2026

    @TekExplorer

    I'm not sure you need a special config for that beyond the normal headers?

  2. FoliageOwO commented on May 24, 2026

    @FoliageOwO
    Author

    I'm not sure you need a special config for that beyond the normal headers?

    Thanks for the response. I am referring to headers on the proxy CONNECT request, not headers on the actual request to the origin server.

    For an HTTPS URL through an HTTP proxy, there are two different requests involved:

    CONNECT example.com:443 HTTP/1.1
    Host: example.com:443
    X-Proxy-Authorization: TOKEN

    After the tunnel is established, the actual HTTPS request is sent through TLS:

    GET / HTTP/1.1
    Host: example.com
    Referer: ...

    Headers added through package:http are applied to the second request. They cannot be used for the first CONNECT request, since that request is generated internally when establishing the proxy tunnel.

    I am aware that dart:io exposes addProxyCredentials / authenticateProxy for standard proxy authentication. My use case requires adding a custom proxy header such as X-Proxy-Authorization, equivalent to:

    curl -x http://127.0.0.1:8888 https://example.com \
      --proxy-header "X-Proxy-Authorization: TOKEN"

    I could not find any API or hook in HttpClient / IOClient that allows customizing the headers of the generated CONNECT request.

    Is there an existing way to do this, or would support for arbitrary proxy CONNECT headers require a new API?

  3. TekExplorer commented on May 24, 2026

    @TekExplorer

    I don't see any. It looks hard-coded. There's even an enum!

    I believe we would need a new API

    You could probably make a CONNECT request yourself, but I doubt that would do anything useful.

    This would be better a question for the core io library rather than the http package, which is built over-top of it (and not very responsive to issues by comparison, as far as I can tell)

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions