-
Notifications
You must be signed in to change notification settings - Fork 39
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
Use http.Transport instead of http.Client. #15
Conversation
http.Client follows redirects by default and has support for cookies. http.Transport only performs one round-trip. Using http.Client is vulnerable to bad behaviour if there's a redirect loop somewhere in your app. Since we don't need (or want) redirects, and don't use cookies, http.Transport seems like the most logical choice.
Thanks. I'm not sure that disabling cookies and redirects is best solution, because Gor aims to replicate exact same requests. If you have redirect loop in your production environment i guess its a bug and should be fixed, right? But it make sense try to limit number for redirects, not sure if standard Go lib support it. |
The default behaviour (which gor does not override) of Yep, redirect loops are a bug, but not necessarily a bug that should bring our entire stack to its knees. :P |
Are you sure that it not send cookies? Because request object should contains info about cookies. I suggest just to add CustomRedirect function like this: func customCheckRedirect(req *Request, via []*Request) error {
if len(via) >= 2 {
return errors.New("stopped after 2 redirects")
}
return nil
}
...
client := &http.Client{
CheckRedirect: customCheckRedirect,
} |
I'm not an expert (I have only ever written a few lines of go), but if I read the documentation I find this:
And right now we don't supply a |
@derekkraan I limit redirects by 2, also added integration tests to ensure that cookies is transferred https://github.com/buger/gor/blob/master/integration_test.go |
I believe the correct behaviour is to follow 0 redirects. If the user's browser receives a redirect, it'll follow that redirect and gor will pick that up, still perfectly duplicating the load on the production stack on the staging stack. But by following redirects up to two times:
|
@derekkraan i finally got you idea, you right. I disabled redirects. |
http.Client follows redirects by default and has support for cookies.
http.Transport only performs one round-trip. Using http.Client is
vulnerable to bad behaviour if there's a redirect loop somewhere in your
app. Since we don't need (or want) redirects, and don't use cookies,
http.Transport seems like the most logical choice.
(Before this patch, we ended up DOSing our own site whenever someone discovered a redirect loop)