Skip to content

Commit

Permalink
Removes the Authorization header if it exists and host has changed af…
Browse files Browse the repository at this point in the history
…ter a redirect
  • Loading branch information
gummiboll committed Oct 13, 2017
1 parent 4cefa8a commit bcf9e50
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion colly.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func (c *Collector) scrape(u, method string, depth int, requestData io.Reader, c
return err
}
req.Header.Set("User-Agent", c.UserAgent)

if ctx == nil {
ctx = NewContext()
}
Expand Down Expand Up @@ -369,8 +370,16 @@ func (c *Collector) checkRedirectFunc() func(req *http.Request, via []*http.Requ
return http.ErrUseLastResponse
}

lastRequest := via[len(via)-1]

// Copy the headers from last request
req.Header = via[len(via)-1].Header
req.Header = lastRequest.Header

// If domain has changed, remove the Authorization-header if it exists
if req.URL.Host != lastRequest.URL.Host {
req.Header.Del("Authorization")
}

return nil
}
}
Expand Down

0 comments on commit bcf9e50

Please sign in to comment.