Skip to content
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

Fix Flush breaks response if called while buffering #60

Merged
merged 2 commits into from
Nov 20, 2017

Conversation

tmthrgd
Copy link
Contributor

@tmthrgd tmthrgd commented Nov 10, 2017

This fixes the bug I noted in #58 (comment). In doing so, it reverts 0f67f3f, which was #58, and commits a different fix for that issue.

Where #58 juggled calling WriteHeader within Flush, this pull request simply makes Flush a no-op while the response is buffering, i.e. until it reaches the minimum size.

In reverting 0f67f3f, it has the side-effect of reducing the size of the per-request GzipResponseWriter struct from 104 bytes to 96 bytes.

This fixes nytimes#58 and prevents the underlying Flusher
from writing the wrong status code or writing
headers before Content-Encoding has been set.

This is cb0f3d94c6 with the test
case taken from 574da8f22d.
@@ -306,21 +306,22 @@ func TestStatusCodes(t *testing.T) {
}
}

func TestStatusCodesFlushed(t *testing.T) {
func TestFlushBeforeWrite(t *testing.T) {
b := []byte(testBody)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to use the smallTestBody ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juliens Why's that? In this test case I'm testing the interaction between Flush and Write and I want the response to be gzipped.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I misread, I believed the write was before the flush 😉

It's good for me even though I do not really like the 'Flush` after a small body writing does not do anything.

@tmthrgd
Copy link
Contributor Author

tmthrgd commented Nov 20, 2017

Ping @jprobinson, any chance this could be reviewed/merged soon? (Sorry for the noise).

@jprobinson jprobinson merged commit d6f4660 into nytimes:master Nov 20, 2017
@jprobinson
Copy link
Contributor

🍕 thanks!

...and sorry for the wait!

@tmthrgd tmthrgd deleted the upstream_flush_fix branch November 20, 2017 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants