From d4470c5a6c6c0d62eea803232167e24cc6af59e1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Sep 2023 17:01:26 +0000 Subject: [PATCH] Bump github.com/valyala/fasthttp from 1.49.0 to 1.50.0 in /src Bumps [github.com/valyala/fasthttp](https://github.com/valyala/fasthttp) from 1.49.0 to 1.50.0. - [Release notes](https://github.com/valyala/fasthttp/releases) - [Commits](https://github.com/valyala/fasthttp/compare/v1.49.0...v1.50.0) --- updated-dependencies: - dependency-name: github.com/valyala/fasthttp dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- src/go.mod | 2 +- src/go.sum | 4 +- .../github.com/valyala/fasthttp/args.go | 16 ++++--- .../github.com/valyala/fasthttp/client.go | 47 ++++++++++++++----- .../github.com/valyala/fasthttp/header.go | 39 ++++++++------- .../github.com/valyala/fasthttp/http.go | 30 +++++++----- .../github.com/valyala/fasthttp/server.go | 16 ++++--- src/vendor/github.com/valyala/fasthttp/uri.go | 3 +- .../github.com/valyala/fasthttp/userdata.go | 3 +- src/vendor/modules.txt | 2 +- 10 files changed, 101 insertions(+), 61 deletions(-) diff --git a/src/go.mod b/src/go.mod index e027fa330..19b64d5e5 100644 --- a/src/go.mod +++ b/src/go.mod @@ -13,7 +13,7 @@ require ( github.com/onsi/gomega v1.27.10 github.com/prometheus/client_model v0.4.0 github.com/prometheus/common v0.44.0 - github.com/valyala/fasthttp v1.49.0 + github.com/valyala/fasthttp v1.50.0 golang.org/x/net v0.15.0 google.golang.org/grpc v1.58.0 gopkg.in/yaml.v2 v2.4.0 diff --git a/src/go.sum b/src/go.sum index 3fc503dab..2486c9d4c 100644 --- a/src/go.sum +++ b/src/go.sum @@ -176,8 +176,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1 github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.49.0 h1:9FdvCpmxB74LH4dPb7IJ1cOSsluR07XG3I1txXWwJpE= -github.com/valyala/fasthttp v1.49.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA= +github.com/valyala/fasthttp v1.50.0 h1:H7fweIlBm0rXLs2q0XbalvJ6r0CUPFWK3/bB4N13e9M= +github.com/valyala/fasthttp v1.50.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/src/vendor/github.com/valyala/fasthttp/args.go b/src/vendor/github.com/valyala/fasthttp/args.go index c6e75848c..9cc11067f 100644 --- a/src/vendor/github.com/valyala/fasthttp/args.go +++ b/src/vendor/github.com/valyala/fasthttp/args.go @@ -552,13 +552,14 @@ func decodeArgAppend(dst, src []byte) []byte { } idx := 0 - if idxPercent == -1 { + switch { + case idxPercent == -1: idx = idxPlus - } else if idxPlus == -1 { + case idxPlus == -1: idx = idxPercent - } else if idxPercent > idxPlus { + case idxPercent > idxPlus: idx = idxPlus - } else { + default: idx = idxPercent } @@ -567,7 +568,8 @@ func decodeArgAppend(dst, src []byte) []byte { // slow path for i := idx; i < len(src); i++ { c := src[i] - if c == '%' { + switch c { + case '%': if i+2 >= len(src) { return append(dst, src[i:]...) } @@ -579,9 +581,9 @@ func decodeArgAppend(dst, src []byte) []byte { dst = append(dst, x1<<4|x2) i += 2 } - } else if c == '+' { + case '+': dst = append(dst, ' ') - } else { + default: dst = append(dst, c) } } diff --git a/src/vendor/github.com/valyala/fasthttp/client.go b/src/vendor/github.com/valyala/fasthttp/client.go index ae005d72c..d1c8549a5 100644 --- a/src/vendor/github.com/valyala/fasthttp/client.go +++ b/src/vendor/github.com/valyala/fasthttp/client.go @@ -380,7 +380,7 @@ func (c *Client) Post(dst []byte, url string, postArgs *Args) (statusCode int, b // and AcquireResponse in performance-critical code. func (c *Client) DoTimeout(req *Request, resp *Response, timeout time.Duration) error { req.timeout = timeout - if req.timeout < 0 { + if req.timeout <= 0 { return ErrTimeout } return c.Do(req, resp) @@ -412,7 +412,7 @@ func (c *Client) DoTimeout(req *Request, resp *Response, timeout time.Duration) // and AcquireResponse in performance-critical code. func (c *Client) DoDeadline(req *Request, resp *Response, deadline time.Time) error { req.timeout = time.Until(deadline) - if req.timeout < 0 { + if req.timeout <= 0 { return ErrTimeout } return c.Do(req, resp) @@ -1158,7 +1158,7 @@ func ReleaseResponse(resp *Response) { // and AcquireResponse in performance-critical code. func (c *HostClient) DoTimeout(req *Request, resp *Response, timeout time.Duration) error { req.timeout = timeout - if req.timeout < 0 { + if req.timeout <= 0 { return ErrTimeout } return c.Do(req, resp) @@ -1185,7 +1185,7 @@ func (c *HostClient) DoTimeout(req *Request, resp *Response, timeout time.Durati // and AcquireResponse in performance-critical code. func (c *HostClient) DoDeadline(req *Request, resp *Response, deadline time.Time) error { req.timeout = time.Until(deadline) - if req.timeout < 0 { + if req.timeout <= 0 { return ErrTimeout } return c.Do(req, resp) @@ -1243,8 +1243,27 @@ func (c *HostClient) Do(req *Request, resp *Response) error { attempts := 0 hasBodyStream := req.IsBodyStream() + // If a request has a timeout we store the timeout + // and calculate a deadline so we can keep updating the + // timeout on each retry. + deadline := time.Time{} + timeout := req.timeout + if timeout > 0 { + deadline = time.Now().Add(timeout) + } + atomic.AddInt32(&c.pendingRequests, 1) for { + // If the original timeout was set, we need to update + // the one set on the request to reflect the remaining time. + if timeout > 0 { + req.timeout = time.Until(deadline) + if req.timeout <= 0 { + err = ErrTimeout + break + } + } + retry, err = c.do(req, resp) if err == nil || !retry { break @@ -1272,6 +1291,9 @@ func (c *HostClient) Do(req *Request, resp *Response) error { } atomic.AddInt32(&c.pendingRequests, -1) + // Restore the original timeout. + req.timeout = timeout + if err == io.EOF { err = ErrConnectionClosed } @@ -1343,7 +1365,7 @@ func (c *HostClient) doNonNilReqResp(req *Request, resp *Response) (bool, error) userAgent = defaultUserAgent } if userAgent != "" { - req.Header.userAgent = append(req.Header.userAgent[:], userAgent...) + req.Header.userAgent = append(req.Header.userAgent[:0], userAgent...) } } @@ -2013,7 +2035,7 @@ func (w *wantConn) cancel(c *HostClient, err error) { // // inspired by net/http/transport.go type wantConnQueue struct { - // This is a queue, not a deque. + // This is a queue, not a dequeue. // It is split into two stages - head[headPos:] and tail. // popFront is trivial (headPos++) on the first stage, and // pushBack is trivial (append) on the second stage. @@ -2288,7 +2310,7 @@ func (c *pipelineConnClient) DoDeadline(req *Request, resp *Response, deadline t c.init() timeout := time.Until(deadline) - if timeout < 0 { + if timeout <= 0 { return ErrTimeout } @@ -2303,7 +2325,7 @@ func (c *pipelineConnClient) DoDeadline(req *Request, resp *Response, deadline t userAgent = defaultUserAgent } if userAgent != "" { - req.Header.userAgent = append(req.Header.userAgent[:], userAgent...) + req.Header.userAgent = append(req.Header.userAgent[:0], userAgent...) } } @@ -2410,7 +2432,7 @@ func (c *pipelineConnClient) Do(req *Request, resp *Response) error { userAgent = defaultUserAgent } if userAgent != "" { - req.Header.userAgent = append(req.Header.userAgent[:], userAgent...) + req.Header.userAgent = append(req.Header.userAgent[:0], userAgent...) } } @@ -2894,8 +2916,8 @@ func (t *transport) RoundTrip(hc *HostClient, req *Request, resp *Response) (ret br := hc.acquireReader(conn) err = resp.ReadLimitBody(br, hc.MaxResponseBodySize) - hc.releaseReader(br) if err != nil { + hc.releaseReader(br) hc.closeConn(cc) // Don't retry in case of ErrBodyTooLarge since we will just get the same again. needRetry := err != ErrBodyTooLarge @@ -2906,10 +2928,11 @@ func (t *transport) RoundTrip(hc *HostClient, req *Request, resp *Response) (ret if customStreamBody && resp.bodyStream != nil { rbs := resp.bodyStream resp.bodyStream = newCloseReader(rbs, func() error { + hc.releaseReader(br) if r, ok := rbs.(*requestStream); ok { releaseRequestStream(r) } - if closeConn { + if closeConn || resp.ConnectionClose() { hc.closeConn(cc) } else { hc.releaseConn(cc) @@ -2917,6 +2940,8 @@ func (t *transport) RoundTrip(hc *HostClient, req *Request, resp *Response) (ret return nil }) return false, nil + } else { + hc.releaseReader(br) } if closeConn { diff --git a/src/vendor/github.com/valyala/fasthttp/header.go b/src/vendor/github.com/valyala/fasthttp/header.go index ca9062f6c..f6a0fb152 100644 --- a/src/vendor/github.com/valyala/fasthttp/header.go +++ b/src/vendor/github.com/valyala/fasthttp/header.go @@ -1298,19 +1298,20 @@ func (h *ResponseHeader) setSpecialHeader(key, value []byte) bool { switch key[0] | 0x20 { case 'c': - if caseInsensitiveCompare(strContentType, key) { + switch { + case caseInsensitiveCompare(strContentType, key): h.SetContentTypeBytes(value) return true - } else if caseInsensitiveCompare(strContentLength, key) { + case caseInsensitiveCompare(strContentLength, key): if contentLength, err := parseContentLength(value); err == nil { h.contentLength = contentLength h.contentLengthBytes = append(h.contentLengthBytes[:0], value...) } return true - } else if caseInsensitiveCompare(strContentEncoding, key) { + case caseInsensitiveCompare(strContentEncoding, key): h.SetContentEncodingBytes(value) return true - } else if caseInsensitiveCompare(strConnection, key) { + case caseInsensitiveCompare(strConnection, key): if bytes.Equal(strClose, value) { h.SetConnectionClose() } else { @@ -1361,16 +1362,17 @@ func (h *RequestHeader) setSpecialHeader(key, value []byte) bool { switch key[0] | 0x20 { case 'c': - if caseInsensitiveCompare(strContentType, key) { + switch { + case caseInsensitiveCompare(strContentType, key): h.SetContentTypeBytes(value) return true - } else if caseInsensitiveCompare(strContentLength, key) { + case caseInsensitiveCompare(strContentLength, key): if contentLength, err := parseContentLength(value); err == nil { h.contentLength = contentLength h.contentLengthBytes = append(h.contentLengthBytes[:0], value...) } return true - } else if caseInsensitiveCompare(strConnection, key) { + case caseInsensitiveCompare(strConnection, key): if bytes.Equal(strClose, value) { h.SetConnectionClose() } else { @@ -1378,7 +1380,7 @@ func (h *RequestHeader) setSpecialHeader(key, value []byte) bool { h.setNonSpecial(key, value) } return true - } else if caseInsensitiveCompare(strCookie, key) { + case caseInsensitiveCompare(strCookie, key): h.collectCookies() h.cookies = parseRequestCookies(h.cookies, value) return true @@ -2791,16 +2793,17 @@ func (h *RequestHeader) parseFirstLine(buf []byte) (int, error) { protoStr := strHTTP11 // parse requestURI n = bytes.LastIndexByte(b, ' ') - if n < 0 { + switch { + case n < 0: h.noHTTP11 = true n = len(b) protoStr = strHTTP10 - } else if n == 0 { + case n == 0: if h.secureErrorLogMessage { return 0, fmt.Errorf("requestURI cannot be empty") } return 0, fmt.Errorf("requestURI cannot be empty in %q", buf) - } else if !bytes.Equal(b[n+1:], strHTTP11) { + case !bytes.Equal(b[n+1:], strHTTP11): h.noHTTP11 = true protoStr = b[n+1:] } @@ -3268,15 +3271,16 @@ func normalizeHeaderValue(ov, ob []byte, headerLength int) (nv, nb []byte, nhl i lineStart := false for read := 0; read < length; read++ { c := ov[read] - if c == rChar || c == nChar { + switch { + case c == rChar || c == nChar: shrunk++ if c == nChar { lineStart = true } continue - } else if lineStart && c == '\t' { + case lineStart && c == '\t': c = ' ' - } else { + default: lineStart = false } nv[write] = c @@ -3335,15 +3339,16 @@ func removeNewLines(raw []byte) []byte { foundN := bytes.IndexByte(raw, nChar) start := 0 - if foundN != -1 { + switch { + case foundN != -1: if foundR > foundN { start = foundN } else if foundR != -1 { start = foundR } - } else if foundR != -1 { + case foundR != -1: start = foundR - } else { + default: return raw } diff --git a/src/vendor/github.com/valyala/fasthttp/http.go b/src/vendor/github.com/valyala/fasthttp/http.go index 988288815..0a5b446e8 100644 --- a/src/vendor/github.com/valyala/fasthttp/http.go +++ b/src/vendor/github.com/valyala/fasthttp/http.go @@ -814,14 +814,15 @@ func (req *Request) ResetBody() { // CopyTo copies req contents to dst except of body stream. func (req *Request) CopyTo(dst *Request) { req.copyToSkipBody(dst) - if req.bodyRaw != nil { + switch { + case req.bodyRaw != nil: dst.bodyRaw = append(dst.bodyRaw[:0], req.bodyRaw...) if dst.body != nil { dst.body.Reset() } - } else if req.body != nil { + case req.body != nil: dst.bodyBuffer().Set(req.body.B) - } else if dst.body != nil { + case dst.body != nil: dst.body.Reset() } } @@ -846,14 +847,15 @@ func (req *Request) copyToSkipBody(dst *Request) { // CopyTo copies resp contents to dst except of body stream. func (resp *Response) CopyTo(dst *Response) { resp.copyToSkipBody(dst) - if resp.bodyRaw != nil { + switch { + case resp.bodyRaw != nil: dst.bodyRaw = append(dst.bodyRaw, resp.bodyRaw...) if dst.body != nil { dst.body.Reset() } - } else if resp.body != nil { + case resp.body != nil: dst.bodyBuffer().Set(resp.body.B) - } else if dst.body != nil { + case dst.body != nil: dst.body.Reset() } } @@ -1106,8 +1108,8 @@ func (resp *Response) Reset() { if responseBodyPoolSizeLimit >= 0 && resp.body != nil { resp.ReleaseBody(responseBodyPoolSizeLimit) } - resp.Header.Reset() resp.resetSkipHeader() + resp.Header.Reset() resp.SkipBody = false resp.raddr = nil resp.laddr = nil @@ -1284,14 +1286,15 @@ func (req *Request) ReadBody(r *bufio.Reader, contentLength int, maxBodySize int bodyBuf := req.bodyBuffer() bodyBuf.Reset() - if contentLength >= 0 { + switch { + case contentLength >= 0: bodyBuf.B, err = readBody(r, contentLength, maxBodySize, bodyBuf.B) - } else if contentLength == -1 { + case contentLength == -1: bodyBuf.B, err = readBodyChunked(r, maxBodySize, bodyBuf.B) if err == nil && len(bodyBuf.B) == 0 { req.Header.SetContentLength(0) } - } else { + default: bodyBuf.B, err = readBodyIdentity(r, maxBodySize, bodyBuf.B) req.Header.SetContentLength(len(bodyBuf.B)) } @@ -1427,19 +1430,20 @@ func (resp *Response) ReadBody(r *bufio.Reader, maxBodySize int) (err error) { bodyBuf.Reset() contentLength := resp.Header.ContentLength() - if contentLength >= 0 { + switch { + case contentLength >= 0: bodyBuf.B, err = readBody(r, contentLength, maxBodySize, bodyBuf.B) if err == ErrBodyTooLarge && resp.StreamBody { resp.bodyStream = acquireRequestStream(bodyBuf, r, &resp.Header) err = nil } - } else if contentLength == -1 { + case contentLength == -1: if resp.StreamBody { resp.bodyStream = acquireRequestStream(bodyBuf, r, &resp.Header) } else { bodyBuf.B, err = readBodyChunked(r, maxBodySize, bodyBuf.B) } - } else { + default: bodyBuf.B, err = readBodyIdentity(r, maxBodySize, bodyBuf.B) resp.Header.SetContentLength(len(bodyBuf.B)) } diff --git a/src/vendor/github.com/valyala/fasthttp/server.go b/src/vendor/github.com/valyala/fasthttp/server.go index 73683bf8a..51dc2184c 100644 --- a/src/vendor/github.com/valyala/fasthttp/server.go +++ b/src/vendor/github.com/valyala/fasthttp/server.go @@ -403,7 +403,7 @@ type Server struct { // instead. TLSConfig *tls.Config - // FormValueFunc, which is used by RequestCtx.FormValue and support for customising + // FormValueFunc, which is used by RequestCtx.FormValue and support for customizing // the behaviour of the RequestCtx.FormValue function. // // NetHttpFormValueFunc gives a FormValueFunc func implementation that is consistent with net/http. @@ -549,11 +549,12 @@ func CompressHandlerLevel(h RequestHandler, level int) RequestHandler { func CompressHandlerBrotliLevel(h RequestHandler, brotliLevel, otherLevel int) RequestHandler { return func(ctx *RequestCtx) { h(ctx) - if ctx.Request.Header.HasAcceptEncodingBytes(strBr) { + switch { + case ctx.Request.Header.HasAcceptEncodingBytes(strBr): ctx.Response.brotliBody(brotliLevel) //nolint:errcheck - } else if ctx.Request.Header.HasAcceptEncodingBytes(strGzip) { + case ctx.Request.Header.HasAcceptEncodingBytes(strGzip): ctx.Response.gzipBody(otherLevel) //nolint:errcheck - } else if ctx.Request.Header.HasAcceptEncodingBytes(strDeflate) { + case ctx.Request.Header.HasAcceptEncodingBytes(strDeflate): ctx.Response.deflateBody(otherLevel) //nolint:errcheck } } @@ -2238,11 +2239,12 @@ func (s *Server) serveConn(c net.Conn) (err error) { panic(fmt.Sprintf("BUG: error in SetReadDeadline(%v): %v", deadline, err)) } } - if reqConf.MaxRequestBodySize > 0 { + switch { + case reqConf.MaxRequestBodySize > 0: maxRequestBodySize = reqConf.MaxRequestBodySize - } else if s.MaxRequestBodySize > 0 { + case s.MaxRequestBodySize > 0: maxRequestBodySize = s.MaxRequestBodySize - } else { + default: maxRequestBodySize = DefaultMaxRequestBodySize } if reqConf.WriteTimeout > 0 { diff --git a/src/vendor/github.com/valyala/fasthttp/uri.go b/src/vendor/github.com/valyala/fasthttp/uri.go index 4b578ebb8..f1ca6d97c 100644 --- a/src/vendor/github.com/valyala/fasthttp/uri.go +++ b/src/vendor/github.com/valyala/fasthttp/uri.go @@ -688,7 +688,8 @@ func normalizePath(dst, src []byte) []byte { func (u *URI) RequestURI() []byte { var dst []byte if u.DisablePathNormalizing { - dst = append(u.requestURI[:0], u.PathOriginal()...) + dst = u.requestURI[:0] + dst = append(dst, u.PathOriginal()...) } else { dst = appendQuotedPath(u.requestURI[:0], u.Path()) } diff --git a/src/vendor/github.com/valyala/fasthttp/userdata.go b/src/vendor/github.com/valyala/fasthttp/userdata.go index 40690f69b..5561cda81 100644 --- a/src/vendor/github.com/valyala/fasthttp/userdata.go +++ b/src/vendor/github.com/valyala/fasthttp/userdata.go @@ -42,7 +42,8 @@ func (d *userData) Set(key interface{}, value interface{}) { kv := userDataKV{} kv.key = key kv.value = value - *d = append(args, kv) + args = append(args, kv) + *d = args } func (d *userData) SetBytes(key []byte, value interface{}) { diff --git a/src/vendor/modules.txt b/src/vendor/modules.txt index 3b7a1644a..62528bbf4 100644 --- a/src/vendor/modules.txt +++ b/src/vendor/modules.txt @@ -161,7 +161,7 @@ github.com/square/certstrap/pkix # github.com/valyala/bytebufferpool v1.0.0 ## explicit github.com/valyala/bytebufferpool -# github.com/valyala/fasthttp v1.49.0 +# github.com/valyala/fasthttp v1.50.0 ## explicit; go 1.20 github.com/valyala/fasthttp github.com/valyala/fasthttp/fasthttputil