Do not change response code after 204 #5
Merged
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.
There's a bug in the
writerwrapper
. If you callWriteHeader
with either 204 or 304,shouldCompress
would be set to false and then all subsequent calls toWrite
will result in directly calling theOriginWriter.Write
but since the status code is not written toOriginWriter
, it will set it to 200. Another side effect of this is thatWrite
will not only set the status code to 200 but it will also write the content ofdata
toBody
which would not normally happen if the gzip middleware is not used. Instead, if you set the status code to 204 or 304, any calls toWrite
will fail with an error. The correct unit test for this would be:The problem is that
recorder
actually behaves differently fromserver.response
and won't check for 204, 304 (the actual call thatserver.response
makes isbodyAllowedForStatus(w.status)
) sorecorder
will both manage to record the 204 status code and the body (which won't happen in reality). Yet, I didn't find a way to instantiate the actualserver.response
and test against it. So, in the unit tests, the body will be written but in actual use cases, an error will be thrown as expected.