build(deps): bump github.com/go-chi/chi/v5 from 5.2.1 to 5.2.2
Bumps [github.com/go-chi/chi/v5](https://github.com/go-chi/chi) from 5.2.1 to 5.2.2. - [Release notes](https://github.com/go-chi/chi/releases) - [Changelog](https://github.com/go-chi/chi/blob/master/CHANGELOG.md) - [Commits](https://github.com/go-chi/chi/compare/v5.2.1...v5.2.2) --- updated-dependencies: - dependency-name: github.com/go-chi/chi/v5 dependency-version: 5.2.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
+4
-2
@@ -20,7 +20,9 @@ and [docgen](https://github.com/go-chi/docgen). We hope you enjoy it too!
|
||||
|
||||
## Install
|
||||
|
||||
`go get -u github.com/go-chi/chi/v5`
|
||||
```sh
|
||||
go get -u github.com/go-chi/chi/v5
|
||||
```
|
||||
|
||||
|
||||
## Features
|
||||
@@ -194,7 +196,7 @@ type Router interface {
|
||||
// path, with a fresh middleware stack for the inline-Router.
|
||||
Group(fn func(r Router)) Router
|
||||
|
||||
// Route mounts a sub-Router along a `pattern`` string.
|
||||
// Route mounts a sub-Router along a `pattern` string.
|
||||
Route(pattern string, fn func(r Router)) Router
|
||||
|
||||
// Mount attaches another http.Handler along ./pattern/*
|
||||
|
||||
+1
-2
@@ -37,8 +37,7 @@
|
||||
//
|
||||
// A placeholder with a name followed by a colon allows a regular
|
||||
// expression match, for example {number:\\d+}. The regular expression
|
||||
// syntax is Go's normal regexp RE2 syntax, except that regular expressions
|
||||
// including { or } are not supported, and / will never be
|
||||
// syntax is Go's normal regexp RE2 syntax, except that / will never be
|
||||
// matched. An anonymous regexp pattern is allowed, using an empty string
|
||||
// before the colon in the placeholder, such as {:\\d+}
|
||||
//
|
||||
|
||||
+9
-15
@@ -7,7 +7,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -160,16 +159,14 @@ func (c *Compressor) SetEncoder(encoding string, fn EncoderFunc) {
|
||||
delete(c.encoders, encoding)
|
||||
|
||||
// If the encoder supports Resetting (IoReseterWriter), then it can be pooled.
|
||||
encoder := fn(ioutil.Discard, c.level)
|
||||
if encoder != nil {
|
||||
if _, ok := encoder.(ioResetterWriter); ok {
|
||||
pool := &sync.Pool{
|
||||
New: func() interface{} {
|
||||
return fn(ioutil.Discard, c.level)
|
||||
},
|
||||
}
|
||||
c.pooledEncoders[encoding] = pool
|
||||
encoder := fn(io.Discard, c.level)
|
||||
if _, ok := encoder.(ioResetterWriter); ok {
|
||||
pool := &sync.Pool{
|
||||
New: func() interface{} {
|
||||
return fn(io.Discard, c.level)
|
||||
},
|
||||
}
|
||||
c.pooledEncoders[encoding] = pool
|
||||
}
|
||||
// If the encoder is not in the pooledEncoders, add it to the normal encoders.
|
||||
if _, ok := c.pooledEncoders[encoding]; !ok {
|
||||
@@ -277,16 +274,13 @@ type compressResponseWriter struct {
|
||||
func (cw *compressResponseWriter) isCompressible() bool {
|
||||
// Parse the first part of the Content-Type response header.
|
||||
contentType := cw.Header().Get("Content-Type")
|
||||
if idx := strings.Index(contentType, ";"); idx >= 0 {
|
||||
contentType = contentType[0:idx]
|
||||
}
|
||||
contentType, _, _ = strings.Cut(contentType, ";")
|
||||
|
||||
// Is the content type compressible?
|
||||
if _, ok := cw.contentTypes[contentType]; ok {
|
||||
return true
|
||||
}
|
||||
if idx := strings.Index(contentType, "/"); idx > 0 {
|
||||
contentType = contentType[0:idx]
|
||||
if contentType, _, hadSlash := strings.Cut(contentType, "/"); hadSlash {
|
||||
_, ok := cw.contentWildcards[contentType]
|
||||
return ok
|
||||
}
|
||||
|
||||
+4
-5
@@ -40,11 +40,10 @@ func contentEncoding(ce string, charsets ...string) bool {
|
||||
|
||||
// Split a string in two parts, cleaning any whitespace.
|
||||
func split(str, sep string) (string, string) {
|
||||
var a, b string
|
||||
var parts = strings.SplitN(str, sep, 2)
|
||||
a = strings.TrimSpace(parts[0])
|
||||
if len(parts) == 2 {
|
||||
b = strings.TrimSpace(parts[1])
|
||||
a, b, found := strings.Cut(str, sep)
|
||||
a = strings.TrimSpace(a)
|
||||
if found {
|
||||
b = strings.TrimSpace(b)
|
||||
}
|
||||
|
||||
return a, b
|
||||
|
||||
+2
-2
@@ -31,7 +31,8 @@ func AllowContentType(contentTypes ...string) func(http.Handler) http.Handler {
|
||||
return
|
||||
}
|
||||
|
||||
s := strings.ToLower(strings.TrimSpace(strings.Split(r.Header.Get("Content-Type"), ";")[0]))
|
||||
s, _, _ := strings.Cut(r.Header.Get("Content-Type"), ";")
|
||||
s = strings.ToLower(strings.TrimSpace(s))
|
||||
|
||||
if _, ok := allowedContentTypes[s]; ok {
|
||||
next.ServeHTTP(w, r)
|
||||
@@ -42,4 +43,3 @@ func AllowContentType(contentTypes ...string) func(http.Handler) http.Handler {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -1,3 +1,6 @@
|
||||
//go:build !tinygo
|
||||
// +build !tinygo
|
||||
|
||||
package middleware
|
||||
|
||||
import (
|
||||
|
||||
+1
-5
@@ -47,11 +47,7 @@ func realIP(r *http.Request) string {
|
||||
} else if xrip := r.Header.Get(xRealIP); xrip != "" {
|
||||
ip = xrip
|
||||
} else if xff := r.Header.Get(xForwardedFor); xff != "" {
|
||||
i := strings.Index(xff, ",")
|
||||
if i == -1 {
|
||||
i = len(xff)
|
||||
}
|
||||
ip = xff[:i]
|
||||
ip, _, _ = strings.Cut(xff, ",")
|
||||
}
|
||||
if ip == "" || net.ParseIP(ip) == nil {
|
||||
return ""
|
||||
|
||||
+1
-7
@@ -133,13 +133,7 @@ type Pattern struct {
|
||||
|
||||
func NewPattern(value string) Pattern {
|
||||
p := Pattern{}
|
||||
if i := strings.IndexByte(value, '*'); i >= 0 {
|
||||
p.wildcard = true
|
||||
p.prefix = value[0:i]
|
||||
p.suffix = value[i+1:]
|
||||
} else {
|
||||
p.prefix = value
|
||||
}
|
||||
p.prefix, p.suffix, p.wildcard = strings.Cut(value, "*")
|
||||
return p
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -3,6 +3,7 @@ package middleware
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
@@ -47,13 +48,12 @@ func RedirectSlashes(next http.Handler) http.Handler {
|
||||
path = r.URL.Path
|
||||
}
|
||||
if len(path) > 1 && path[len(path)-1] == '/' {
|
||||
// Trim all leading and trailing slashes (e.g., "//evil.com", "/some/path//")
|
||||
path = "/" + strings.Trim(path, "/")
|
||||
if r.URL.RawQuery != "" {
|
||||
path = fmt.Sprintf("%s?%s", path[:len(path)-1], r.URL.RawQuery)
|
||||
} else {
|
||||
path = path[:len(path)-1]
|
||||
path = fmt.Sprintf("%s?%s", path, r.URL.RawQuery)
|
||||
}
|
||||
redirectURL := fmt.Sprintf("//%s%s", r.Host, path)
|
||||
http.Redirect(w, r, redirectURL, 301)
|
||||
http.Redirect(w, r, path, 301)
|
||||
return
|
||||
}
|
||||
next.ServeHTTP(w, r)
|
||||
|
||||
+1
-1
@@ -126,9 +126,9 @@ type token struct{}
|
||||
type throttler struct {
|
||||
tokens chan token
|
||||
backlogTokens chan token
|
||||
retryAfterFn func(ctxDone bool) time.Duration
|
||||
backlogTimeout time.Duration
|
||||
statusCode int
|
||||
retryAfterFn func(ctxDone bool) time.Duration
|
||||
}
|
||||
|
||||
// setRetryAfterHeaderIfNeeded sets Retry-After HTTP header if corresponding retryAfterFn option of throttler is initialized.
|
||||
|
||||
+3
-4
@@ -6,7 +6,6 @@ package middleware
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
@@ -73,10 +72,10 @@ type WrapResponseWriter interface {
|
||||
// http.ResponseWriter interface.
|
||||
type basicWriter struct {
|
||||
http.ResponseWriter
|
||||
wroteHeader bool
|
||||
tee io.Writer
|
||||
code int
|
||||
bytes int
|
||||
tee io.Writer
|
||||
wroteHeader bool
|
||||
discard bool
|
||||
}
|
||||
|
||||
@@ -108,7 +107,7 @@ func (b *basicWriter) Write(buf []byte) (n int, err error) {
|
||||
} else if b.tee != nil {
|
||||
n, err = b.tee.Write(buf)
|
||||
} else {
|
||||
n, err = ioutil.Discard.Write(buf)
|
||||
n, err = io.Discard.Write(buf)
|
||||
}
|
||||
b.bytes += n
|
||||
return n, err
|
||||
|
||||
+4
-6
@@ -107,9 +107,8 @@ func (mx *Mux) Use(middlewares ...func(http.Handler) http.Handler) {
|
||||
// Handle adds the route `pattern` that matches any http method to
|
||||
// execute the `handler` http.Handler.
|
||||
func (mx *Mux) Handle(pattern string, handler http.Handler) {
|
||||
parts := strings.SplitN(pattern, " ", 2)
|
||||
if len(parts) == 2 {
|
||||
mx.Method(parts[0], parts[1], handler)
|
||||
if method, rest, found := strings.Cut(pattern, " "); found {
|
||||
mx.Method(method, rest, handler)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -119,9 +118,8 @@ func (mx *Mux) Handle(pattern string, handler http.Handler) {
|
||||
// HandleFunc adds the route `pattern` that matches any http method to
|
||||
// execute the `handlerFn` http.HandlerFunc.
|
||||
func (mx *Mux) HandleFunc(pattern string, handlerFn http.HandlerFunc) {
|
||||
parts := strings.SplitN(pattern, " ", 2)
|
||||
if len(parts) == 2 {
|
||||
mx.Method(parts[0], parts[1], handlerFn)
|
||||
if method, rest, found := strings.Cut(pattern, " "); found {
|
||||
mx.Method(method, rest, handlerFn)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
//go:build go1.22
|
||||
// +build go1.22
|
||||
//go:build go1.22 && !tinygo
|
||||
// +build go1.22,!tinygo
|
||||
|
||||
|
||||
package chi
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
//go:build !go1.22
|
||||
// +build !go1.22
|
||||
//go:build !go1.22 || tinygo
|
||||
// +build !go1.22 tinygo
|
||||
|
||||
package chi
|
||||
|
||||
|
||||
+2
-4
@@ -730,11 +730,9 @@ func patNextSegment(pattern string) (nodeTyp, string, string, byte, int, int) {
|
||||
tail = pattern[pe]
|
||||
}
|
||||
|
||||
var rexpat string
|
||||
if idx := strings.Index(key, ":"); idx >= 0 {
|
||||
key, rexpat, isRegexp := strings.Cut(key, ":")
|
||||
if isRegexp {
|
||||
nt = ntRegexp
|
||||
rexpat = key[idx+1:]
|
||||
key = key[:idx]
|
||||
}
|
||||
|
||||
if len(rexpat) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user