Skip to content

Commit

Permalink
Requests with incomplete bodies no longer cause log noise (#682)
Browse files Browse the repository at this point in the history
* #660 Incorrect content length

* fix

* unexpected EOF is expected

* Prevent test from panicing should err ever be nil
  • Loading branch information
kevburnsjr authored and erikdubbelboer committed Oct 27, 2019
1 parent 9bc6da1 commit f82a646
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3147,6 +3147,24 @@ func TestMaxWriteTimeoutPerRequest(t *testing.T) {
}
}

func TestIncompleteBodyReturnsUnexpectedEOF(t *testing.T) {
rw := &readWriter{}
rw.r.WriteString("POST /foo HTTP/1.1\r\nHost: google.com\r\nContent-Length: 5\r\n\r\n123")
s := &Server{
Handler: func(ctx *RequestCtx) {},
}
ch := make(chan error)
go func() {
ch <- s.ServeConn(rw)
}()
select {
case err := <-ch:
if err == nil || err.Error() != "unexpected EOF" {
t.Fatal(err)
}
}
}

func verifyResponse(t *testing.T, r *bufio.Reader, expectedStatusCode int, expectedContentType, expectedBody string) {
var resp Response
if err := resp.Read(r); err != nil {
Expand Down
1 change: 1 addition & 0 deletions workerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ func (wp *workerPool) workerFunc(ch *workerChan) {
if wp.LogAllErrors || !(strings.Contains(errStr, "broken pipe") ||
strings.Contains(errStr, "reset by peer") ||
strings.Contains(errStr, "request headers: small read buffer") ||
strings.Contains(errStr, "unexpected EOF") ||
strings.Contains(errStr, "i/o timeout")) {
wp.Logger.Printf("error when serving connection %q<->%q: %s", c.LocalAddr(), c.RemoteAddr(), err)
}
Expand Down

0 comments on commit f82a646

Please sign in to comment.