-
Notifications
You must be signed in to change notification settings - Fork 414
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
User agent not setting on redirects #91
Comments
I think that has nothing to do with gorequest directly, cuz it's using the net/http package underneath. General speaking all headers get lost at a redirect, see golang/go#4800 There is also mentioned, that this behaviour can be controlled by CheckRedirect-function. edit see example below request := gorequest.New()
_, body, _ := request.Get(url).
RedirectPolicy(func(req gorequest.Request, via []gorequest.Request) error {
for attr, val := range via[0].Header {
if _, ok := req.Header[attr]; !ok {
req.Header[attr] = val
}
}
return nil
}).
Set("User-Agent", useragent).
End()
log.Println(body) |
Thanks! That works. It should be in the doc, I think. |
Sorry for discussing unrelated stuff here. But I don't know how to reach you, @fraenky8. |
I tried to reproduce the issue but this seems to no longer be an issue as of today, with Go 1.9. |
How to get just 301 status code instead of error? |
I am creating a new agent like so:
gorequest. New(). Get(url). Set("User-Agent", useragent). EndBytes()
When url returns 301 and the http client re-requests for the new location, the user agent is not being set.
The text was updated successfully, but these errors were encountered: