Skip to content

Commit

Permalink
cmd/forwarder/run: add ProxyHeaders
Browse files Browse the repository at this point in the history
It allows to specify additional headers to be added to CONNECT request to upstream proxy.
Note it has no effect when ConnectPassthrough is enabled.

Fixes #268
  • Loading branch information
Choraden authored and mmatczuk committed Sep 8, 2023
1 parent 571c52f commit d491e9b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmd/forwarder/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type command struct {
httpTransportConfig *forwarder.HTTPTransportConfig
pac *url.URL
credentials []*forwarder.HostPortUser
proxyHeaders []header.Header
requestHeaders []header.Header
responseHeaders []header.Header
httpProxyConfig *forwarder.HTTPProxyConfig
Expand Down Expand Up @@ -105,6 +106,18 @@ func (c *command) runE(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("credentials: %w", err)
}

if len(c.proxyHeaders) > 0 {
c.httpProxyConfig.ConnectRequestModifier = func(req *http.Request) error {
if req.Header == nil {
req.Header = http.Header{}
}
for _, h := range c.proxyHeaders {
h.Apply(req.Header)
}
return nil
}
}

if len(c.requestHeaders) > 0 {
c.httpProxyConfig.RequestModifiers = append(c.httpProxyConfig.RequestModifiers, header.Headers(c.requestHeaders))
}
Expand Down

0 comments on commit d491e9b

Please sign in to comment.