-
Notifications
You must be signed in to change notification settings - Fork 129
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,6 +208,51 @@ func TestGzipHandlerNoBody(t *testing.T) { | |
} | ||
} | ||
|
||
func TestGzipHnalderStream(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you mean write There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
ln, err := net.Listen("tcp", "127.0.0.1:") | ||
if err != nil { | ||
t.Fatalf("failed creating listen socket: %v", err) | ||
} | ||
defer ln.Close() | ||
srv := &http.Server{ | ||
Handler: nil, | ||
} | ||
go srv.Serve(ln) | ||
|
||
handler, ok := GzipHandlerWithOpts(MinSize(0)) | ||
assert.Nil(t, ok) | ||
srv.Handler = handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
flusher, ok := w.(http.Flusher) | ||
assert.Equal(t, true, ok) | ||
|
||
w.WriteHeader(200) | ||
w.Write([]byte("")) | ||
flusher.Flush() | ||
w.Write([]byte("subsequent write with data")) | ||
flusher.Flush() | ||
})) | ||
|
||
req := &http.Request{ | ||
Method: "GET", | ||
URL: &url.URL{Path: "/", Scheme: "http", Host: ln.Addr().String()}, | ||
Header: make(http.Header), | ||
Close: false, | ||
} | ||
|
||
res, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
t.Fatalf("Unexpected error making http request %v", err) | ||
} | ||
defer res.Body.Close() | ||
|
||
body, err := ioutil.ReadAll(res.Body) | ||
if err != nil { | ||
t.Fatalf("Unexpected error reading response body %v", err) | ||
} | ||
|
||
assert.Equal(t, "subsequent write with data", string(body)) | ||
|
||
} | ||
func TestGzipHandlerContentLength(t *testing.T) { | ||
testBodyBytes := []byte(testBody) | ||
tests := []struct { | ||
|
There was a problem hiding this comment.
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 checklen(w.buf) >= w.minSize
is already made in thewrite
function.