Skip to content

Commit

Permalink
Fix Request.connectionCloseFast bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdubbelboer committed Mar 11, 2018
1 parent 34f277f commit 477f212
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 13 deletions.
6 changes: 0 additions & 6 deletions header.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,6 @@ func (h *RequestHeader) ConnectionClose() bool {
return h.connectionClose
}

func (h *RequestHeader) connectionCloseFast() bool {
// h.parseRawHeaders() isn't called for performance reasons.
// Use ConnectionClose for triggering raw headers parsing.
return h.connectionClose
}

// SetConnectionClose sets 'Connection: close' header.
func (h *RequestHeader) SetConnectionClose() {
// h.parseRawHeaders() isn't called for performance reasons.
Expand Down
3 changes: 0 additions & 3 deletions header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,6 @@ func TestRequestHeaderHTTP10ConnectionClose(t *testing.T) {
t.Fatalf("unexpected error: %s", err)
}

if !h.connectionCloseFast() {
t.Fatalf("expecting 'Connection: close' request header")
}
if !h.ConnectionClose() {
t.Fatalf("expecting 'Connection: close' request header")
}
Expand Down
6 changes: 2 additions & 4 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,7 @@ func (s *Server) serveConn(c net.Conn) error {
}
}

connectionClose = s.DisableKeepalive || ctx.Request.Header.connectionCloseFast()
connectionClose = s.DisableKeepalive || ctx.Request.Header.ConnectionClose()
isHTTP11 = ctx.Request.Header.IsHTTP11()

if serverName != nil {
Expand Down Expand Up @@ -1661,9 +1661,7 @@ func (s *Server) serveConn(c net.Conn) error {
lastWriteDeadlineTime = s.updateWriteDeadline(c, ctx, lastWriteDeadlineTime)
}

// Verify Request.Header.connectionCloseFast() again,
// since request handler might trigger full headers' parsing.
connectionClose = connectionClose || ctx.Request.Header.connectionCloseFast() || ctx.Response.ConnectionClose()
connectionClose = connectionClose || ctx.Response.ConnectionClose()
if connectionClose {
ctx.Response.Header.SetCanonical(strConnection, strClose)
} else if !isHTTP11 {
Expand Down

0 comments on commit 477f212

Please sign in to comment.