Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: honour KeepHeader on https connections #460

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion https.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ func (proxy *ProxyHttpServer) handleHttps(w http.ResponseWriter, r *http.Request
ctx.Warnf("Illegal URL %s", "https://"+r.Host+req.URL.Path)
return
}
removeProxyHeaders(ctx, req)
if !proxy.KeepHeader {
RemoveProxyHeaders(ctx, req)
}
resp, err = ctx.RoundTrip(req)
if err != nil {
ctx.Warnf("Cannot read TLS response from mitm'd server %v", err)
Expand Down
5 changes: 3 additions & 2 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func (proxy *ProxyHttpServer) filterResponse(respOrig *http.Response, ctx *Proxy
return
}

func removeProxyHeaders(ctx *ProxyCtx, r *http.Request) {
// RemoveProxyHeaders removes all proxy headers which should not propagate to the next hop
func RemoveProxyHeaders(ctx *ProxyCtx, r *http.Request) {
r.RequestURI = "" // this must be reset when serving a request with the client
ctx.Logf("Sending request %v %v", r.Method, r.URL.String())
// If no Accept-Encoding header exists, Transport will add the headers it can accept
Expand Down Expand Up @@ -130,7 +131,7 @@ func (proxy *ProxyHttpServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
}

if !proxy.KeepHeader {
removeProxyHeaders(ctx, r)
RemoveProxyHeaders(ctx, r)
}
resp, err = ctx.RoundTrip(r)
if err != nil {
Expand Down