-
Notifications
You must be signed in to change notification settings - Fork 376
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
added option for dialer to follow redirects #125
base: master
Are you sure you want to change the base?
Conversation
Hi @NivKeidan! Thank you for such a good feedback! At the first glance it looks like that following redirects can be done via Dialer might also want to count number of redirects done previously (as standard http.Client does and fails request after 10 consecutive redirects). Current implementation may introduce some However, all of the logic also can be implemented in separate function/method with use of func DialWithRedirects() {
d := ws.Dialer{
OnHeader: func(...) error {
// if header is location
return errRedirect
},
}
for n := 0; n < 10; n++ {
if err := d.Dial(...); err == errRedirect {
continue
}
}
return errTooManyRedirects
} But I'm not sure this should be done this way. Also, I think you did actually break the previous behaviour since before the Let's think/discuss this a bit and then make a decision? upd. Looks like it's false alarm by me because previously we fail |
So I think it's good to have this right on Dialer struct, but with ability to limit the number of redirects done. switch {
case resp.status == 101:
break // OK
case d.FollowRedirects && isRedirect(resp.status):
if urlstr, err = lookupLocationHeader(...); err != nil {
return
}
if err := d.checkRedirect(urlstr, n); err != nil {
return err
}
continue
default:
err = StatusError(...)
} |
Hey @gobwas thanks for the input! I will take a look at CheckRedirect and implement a default 10 retry limit. I hope i'll get to it over the weekend! |
Hey @NivKeidan, I'm friendly asking if you are going to continue work on this? ) It's okay if not, I will just close this and maybe implement it on my own on my free time :) |
Kindly ping. Looks like it can be closed now. |
Hey guys,
First of all, thank you for this package! Great job!
This PR introduces ability for a client to follow redirects.
Protocol wise, following redirects is acceptable.
Previous behaviour is unmodified
Usage:
Simply add
dialer.FollowRedirects = true
This is quite a naive implementation.
If you feel changes are required to make it more acceptable, I would happily put the time in.