Repository navigation
How to add headers for proxy? #1804
Description
Activity
- addedtype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug
on Aug 6, 2025 I'm not sure you need a special config for that beyond the normal headers?
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
CONNECTrequest, 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:httpare applied to the second request. They cannot be used for the firstCONNECTrequest, since that request is generated internally when establishing the proxy tunnel.I am aware that
dart:ioexposesaddProxyCredentials/authenticateProxyfor standard proxy authentication. My use case requires adding a custom proxy header such asX-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/IOClientthat allows customizing the headers of the generatedCONNECTrequest.Is there an existing way to do this, or would support for arbitrary proxy
CONNECTheaders require a new API?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)
Is there any possible way to add authorization headers in HTTP proxy through
CONNECTtunnel?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.