forked from quic-go/quic-go
http3: avoid re-parsing of the Content-Length header for responses (#4648)
* http3: avoid re-parsing of the Content-Length header for responses * http3: set http.Response.ContentLength to 0 for certain types of responses
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/quic-go/quic-go"
|
||||
"github.com/quic-go/quic-go/internal/protocol"
|
||||
@@ -244,15 +243,9 @@ func (s *requestStream) ReadResponse() (*http.Response, error) {
|
||||
isInformational := res.StatusCode >= 100 && res.StatusCode < 200
|
||||
isNoContent := res.StatusCode == http.StatusNoContent
|
||||
isSuccessfulConnect := s.isConnect && res.StatusCode >= 200 && res.StatusCode < 300
|
||||
if !isInformational && !isNoContent && !isSuccessfulConnect {
|
||||
res.ContentLength = -1
|
||||
if clens, ok := res.Header["Content-Length"]; ok && len(clens) == 1 {
|
||||
if clen64, err := strconv.ParseInt(clens[0], 10, 64); err == nil {
|
||||
res.ContentLength = clen64
|
||||
}
|
||||
}
|
||||
if (isInformational || isNoContent || isSuccessfulConnect) && res.ContentLength == -1 {
|
||||
res.ContentLength = 0
|
||||
}
|
||||
|
||||
if s.requestedGzip && res.Header.Get("Content-Encoding") == "gzip" {
|
||||
res.Header.Del("Content-Encoding")
|
||||
res.Header.Del("Content-Length")
|
||||
|
||||
Reference in New Issue
Block a user