-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: http.Client's auto-redirect causes errors in Rack on Ruby by RFC 2046 #52519
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
Comments
rack should use 307 if they want to maintain proper compatibility with user agents, see RFC 7231 Section 6.4.3. |
@seankhliao Rack is a middleware for applications and does not force any redirect behaviour, it's up to applications to choose what status code to use. Go is violating RFC 2046 section 5.1, which states "The body must then contain one or more body parts" (i.e. empty bodies are not allowed), assuming it is submitting an empty body with a So, in any case, it's not Rack that is wrong here, it's following the RFC in terms of the error being generated. Either the app is wrong (should use 307?) or Go is wrong (should not send empty request with content type multipart/form-data). |
@seankhliao quoting the section you reference:
It seems like either you should:
Not sure what is best, but 307 doesn't seem like the right option, or at least from reading the RFC it looks like a 307 forces option 3 above? Interested to hear your interpretation. |
It's useful to consider an HTTP request as 2 layers: the transport protocol and the application protocol it carries. Here, Go follows the redirect according to the transport protocol, which Rack later marks as invalid at the application level. Based on your description of what Rack is, I think neither are wrong here. The server has generated a response, that when followed will create an invalid request. |
I think the problem here is that the client is doing something invalid. Yes, the server might be sending the wrong status code, but if that's going to cause the client to do something incorrect, maybe it should be a warning/exception on the client side? As someone who has been on both sides of this, I guess it's best to follow the RFCs - i.e. the server shouldn't send invalid/impractical response codes and the client shouldn't redirect incorrectly. |
Just FYI: "which Rack later marks as invalid at the application level" - rack is at the protocol level too in this case, it's totally up to the application to do the right thing here. |
According to RFC 2046, the Body of a multipart request must not be empty. However, http.Client's auto-redirect uses the same Content-Type, which violates this rule.
Of course we can avoid the error by using
http.ErrUseLastResponse
. But this default behavior results in an error with Rack, which is very widely used in Ruby. Rack does not provide a workaround.What is the correct solution?
refs: rack/rack#1787
The text was updated successfully, but these errors were encountered: