From 060a6b5161f4a9ef26f0a31f3e8f2d7bbcc513ab Mon Sep 17 00:00:00 2001 From: kinggo Date: Wed, 21 Dec 2022 22:32:26 +0800 Subject: [PATCH] optimize: allow http head when use getonly --- http.go | 4 ++-- server.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/http.go b/http.go index 25defadd70..3d1429c730 100644 --- a/http.go +++ b/http.go @@ -1129,7 +1129,7 @@ func (req *Request) readLimitBody(r *bufio.Reader, maxBodySize int, getOnly bool // Do not reset the request here - the caller must reset it before // calling this method. - if getOnly && !req.Header.IsGet() { + if getOnly && !req.Header.IsGet() && !req.Header.IsHead() { return ErrGetOnly } @@ -1147,7 +1147,7 @@ func (req *Request) readBodyStream(r *bufio.Reader, maxBodySize int, getOnly boo // Do not reset the request here - the caller must reset it before // calling this method. - if getOnly && !req.Header.IsGet() { + if getOnly && !req.Header.IsGet() && !req.Header.IsHead() { return ErrGetOnly } diff --git a/server.go b/server.go index c32990767a..ab1d681742 100644 --- a/server.go +++ b/server.go @@ -292,7 +292,7 @@ type Server struct { // Rejects all non-GET requests if set to true. // // This option is useful as anti-DoS protection for servers - // accepting only GET requests. The request size is limited + // accepting only GET requests and HEAD requests. The request size is limited // by ReadBufferSize if GetOnly is set. // // Server accepts all the requests by default.