Skip to content

Commit

Permalink
Added redirect policy which takes HSTS into account, so that even if …
Browse files Browse the repository at this point in the history
…the location would go from HTTPs to HTTP it would follow to HTTPs if an HTSTS header is present
  • Loading branch information
skraxberger committed Aug 31, 2023
1 parent 2ad958c commit c4810ff
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions common/httpx/httpx.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ func New(options *Options) (*HTTPX, error) {
redirectFunc = func(redirectedRequest *http.Request, previousRequests []*http.Request) error {
// add custom cookies if necessary
httpx.setCustomCookies(redirectedRequest)

location := redirectedRequest.Response.Header.Get("Location")
hsts := redirectedRequest.Response.Header.Get("Strict-Transport-Security")
url, err := redirectedRequest.URL.Parse(location)
if err != nil {
} else {
if url.Scheme == "http" && hsts != "" {
url.Scheme = "https"
}
}
redirectedRequest.URL = url
if len(previousRequests) >= options.MaxRedirects {
// https://github.com/golang/go/issues/10069
return http.ErrUseLastResponse
Expand Down

0 comments on commit c4810ff

Please sign in to comment.