-
Notifications
You must be signed in to change notification settings - Fork 18k
http: Server sends no error for malformed requests. #2160
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
Labels
Comments
Owner changed to @bradfitz. Status changed to Accepted. |
Your patch is much longer than I'd expect, and makes me think I don't understand the issue. Why not just a one-liner in, func (c *conn) serve() { ... w, err := c.readRequest() if err != nil { if err == errTooLarge { fmt.Fprintf(c.rwc, "HTTP/1.1 400 Request Too Large\r\n\r\n") } else { fmt.Fprintf(c.rwc, "HTTP/1.1 400 Bad Request\r\n\r\n") // <<<<<<<<<<<< } ... Would that work? |
That looks ok to me as fix. However, that still results in a no-content page for bad requests. One of the reasons my patch was ugly and long was that I assumed we'd want to write the 400 with a Body indicating what went wrong, along with maybe Date, Content-Type, Content-Length, and probably "Connection: close" headers. We have code for that, but it requires a *response and a Request, and trying to fulfill that needs even when ReadRequest failed lead me down a bumpy, awkward road. Granted, you could just add a "Bad Request" to the end of the Fprintf string, but I have no idea what the spec or accepted browser/cache behavior says about that. Also, the one-liner you propose sends a 400 for ErrHijacked, ErrNotSupported, ErrUnexpectedEOF, and others. In my change I tried to avoid sending for any other than the few cases in ReadRequest I was sure about, and that added some complexity. However, sending a 400 is likely better than dropping the request silently for most errors, and is certainly entirely correct for at least some of them. Anyway, my fix was thrown together relatively quickly, and was certainly more complicated than necessary as a result of my assumptions and assumed requirements. You know better than I what assumptions are safe and what requirements are reasonable, so if you think it can be done simpler, it almost certainly can be. |
This issue was closed by revision bb4cf3f. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by consalus:
Attachments:
The text was updated successfully, but these errors were encountered: