-
Notifications
You must be signed in to change notification settings - Fork 150
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
Handle the 'relative url' case when follow_redirect is enabled #141
Handle the 'relative url' case when follow_redirect is enabled #141
Conversation
Hi @yannrouillard! Thanks for this PR. I looked at http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html section 14.30 Location, and RFC says that supports only absolute URI. Content-Location header supports relative URI and HTTPI don't look for it. I don't know what to do in this case. Before we merge, it would be great to have this case on tests. Would you mind to code something like this https://github.com/savonrb/httpi/blob/master/spec/httpi/httpi_spec.rb#L233. |
Hi, RFC2616 has been superseded by RFC7321 and this one mentions the relative url case: You're right for the test case, I will update the pull request to include such a test. I also noticed that httpi doesn't properly honor the "303 See Other" response code. It should in that case always issues a GET request even if the original request was a POST. Another problem I had is that cookies are not automatically handled. I had to disable follow_redirect and do it manually so the cookie are taken into account. Do you think this should be done automatically by HTTPI ? |
Hi, thanks for the link! HTTPI's follow redirect option was discussed at this issue #67 and implemented because this wasabi's issue savonrb/wasabi#18. I don't think we have to be so "by the book" and change 30x actual behaviour. Maybe @tjarratt can help me here. About the cookies, i think that HTTPI could have a |
I'm completely okay with changing the behavior of things to match specifications. HTTP is a very complicated spec, and historically Savon, HTTPI (and other related gems) have only implemented as much as they needed to, leaving the rest for the community. It seems like handling cookies would be a nice feature for HTTPI, if that's something you need @yannrouillard. A separate pull request for that would be good. My only other suggestion would be a small test for this behavior. There's a lot of edge cases in following redirects, and having some tests that assert the correct behavior would benefit anyone that wants to refactor or modify this code later. |
I updated the pull request to include the relevant test cases and I also fixed the patch to that is work for path relative to the current url (and not only paths relative to the root of the current host). I created a second branch https://github.com/yannrouillard/httpi/tree/fix-redirection-status-code-behavior for the problem about 303 redirection. I didn't implement a modification for 301 and 302 code status as it is a bit different than 303:
So httpi does respect the standard for 301 and 302 and, as it is was used first for Savon, I wonder if this implement the could break some current cases where POST API call are redirected (don't know if that cases exists that much). |
Thanks for the pull request @yannrouillard! It is much appreciated. Glad to have some more improvements to HTTPI 😄 I haven't had a chance to look at your second branch -- when you get some time, do you want to submit a second PR for that? |
…rt_in_follow_redirect Handle the 'relative url' case when follow_redirect is enabled
Here is a proposition of fix is to solve bug #140