From b3b6b8cb28ba2fb9783dd887031ecea0040280fd Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Fri, 17 Aug 2018 16:17:52 +0800 Subject: [PATCH] Fix Request.connectionCloseFast bugs See https://github.com/valyala/fasthttp/pull/265 and https://github.com/valyala/fasthttp/issues/220 and https://github.com/valyala/fasthttp/issues/264 --- header.go | 6 ------ header_test.go | 3 --- server.go | 6 ++---- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/header.go b/header.go index 387c198..e00743e 100644 --- a/header.go +++ b/header.go @@ -157,12 +157,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. diff --git a/header_test.go b/header_test.go index 70a59b4..7cc684d 100644 --- a/header_test.go +++ b/header_test.go @@ -431,9 +431,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") } diff --git a/server.go b/server.go index f0ca700..ef40b6c 100644 --- a/server.go +++ b/server.go @@ -1746,7 +1746,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 { @@ -1785,9 +1785,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 {