From c637221c5f34859271e3af47da6ab9a910b29511 Mon Sep 17 00:00:00 2001 From: kinggo Date: Sun, 25 Dec 2022 16:38:13 +0800 Subject: [PATCH] optimize: allow http head when use getonly (#1456) --- 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 83cf1a1bf2..bb029ecef0 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.