Skip to content

Commit

Permalink
Always use link filtering to avoid http-https mixing
Browse files Browse the repository at this point in the history
  • Loading branch information
razzie committed Nov 26, 2020
1 parent b3860eb commit eb303bd
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions handlerfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,19 @@ func (hf *HandlerFactory) newProxyHandler(hostname, path string, target url.URL)
req.Header.Set("User-Agent", "")
}
}
var modifyResponse func(*http.Response) error
if len(path) > 0 || len(target.Path) > 1 {
modifyResponse = func(resp *http.Response) error {
if ctype := resp.Header.Get("Content-Type"); strings.HasPrefix(ctype, "text/html") {
resp.Header.Del("Content-Length")
resp.ContentLength = -1
resp.Body = NewPathPrefixHTMLStreamer(hostname, target.Path, path, resp.Body)
}
if location := resp.Header.Get("Location"); len(location) > 0 {
if u, _ := url.Parse(location); u != nil && u.Host == hostname {
location = u.RequestURI()
}
resp.Header.Set("Location", path+strings.TrimPrefix(location, target.Path))
modifyResponse := func(resp *http.Response) error {
if ctype := resp.Header.Get("Content-Type"); strings.HasPrefix(ctype, "text/html") {
resp.Header.Del("Content-Length")
resp.ContentLength = -1
resp.Body = NewPathPrefixHTMLStreamer(hostname, target.Path, path, resp.Body)
}
if location := resp.Header.Get("Location"); len(location) > 0 {
if u, _ := url.Parse(location); u != nil && u.Host == hostname {
location = u.RequestURI()
}
return nil
resp.Header.Set("Location", path+strings.TrimPrefix(location, target.Path))
}
return nil
}
return &httputil.ReverseProxy{
Director: director,
Expand Down

0 comments on commit eb303bd

Please sign in to comment.