Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goals
While our go integration tests showed our unterminated chunk code to indicate a premature close was working, curl and wire-shark showed a different story.
The old code was simply taking the conn and writing a "0\r\n" to it. However, it wasn't closing the conn, and because we hadn't told golang's HTTP code that we were taking over the conn, after our handler completed, go would still write the termination code: "0\r\n\r\n". So what we'd end up with is a response that ended "0\r\n0\r\n\r\n".
after "0\r\n" is written, everything before \r\n is a trailer header. Go's HTTP client attempts to parse trailer headers, so when it read the second "0\r\n" it would error cause it's an incorrectly formatted header (the source of our weird "malformed MIME header" error message we've been seeing in tests).
however, node, curl, and browser clients ignore this portion and just make sure the response terminates, so they would see the /r/n and consider it valid.
Implementation
We need to actually close the connection, which also means "Hijack"ing it so go's http server doesn't try to keep using it.
This PR does that and fixes the problem of early terminating chunked streams correctly.