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

check minsize when writing first byte #91

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

drewbailey
Copy link

Fix bug where writing and flushing a zero byte write would cause startGzip() to run but not write, and then on subsequent writes call startPlain, resulting in invalid header errors

gzip_test.go Outdated
@@ -208,6 +208,51 @@ func TestGzipHandlerNoBody(t *testing.T) {
}
}

func TestGzipHnalderStream(t *testing.T) {

Choose a reason for hiding this comment

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

did you mean write TestGzipHandlerStream instead of TestGzipHnalderStream

Copy link
Author

Choose a reason for hiding this comment

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

Woops yep! Also I’m not confident in the fix but the test case reproduces the issue at hand.

Startgzip gets called but not init then subsequently startPlain gets called and then errors

gzip.go Outdated
@@ -166,7 +166,7 @@ func (w *GzipResponseWriter) startGzip() error {
// Initialize and flush the buffer into the gzip response if there are any bytes.
// If there aren't any, we shouldn't initialize it yet because on Close it will
// write the gzip header even if nothing was ever written.
if len(w.buf) > 0 {
if len(w.buf) >= w.minSize {

Choose a reason for hiding this comment

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

This seems to introduce another issue found in the failing test case due to the reason previously mentioned. This is preventing w.init() from being called. Also, the following conditional check len(w.buf) >= w.minSize is already made in the write function.

@drewbailey
Copy link
Author

I removed the invalid fix, but left the test case up there showing the issue we are running into

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.

2 participants