Showing 1000 of 1115 detailed findings. The summary includes all 1115 findings.
context.go1
141:36add-constant
context.go:141:36
for strings.Contains(p, "/*/") { p = strings.ReplaceAll(p, "/*/", "/") }mux_test.go1
1886:5boolean-literal-comparison
mux_test.go:1886:5
tctx.Reset() if r.Match(tctx, "GET", "/users/1") == false { t.Fatal("expecting to find match for route:", "GET", "/users/1")middleware/client_ip.go1
217:6cognitive-complexity
middleware/client_ip.go:217:6
// which value security logic sees by sending a duplicate header.func walkXFF(headers []string, visit func(entry string) bool) { for hi := len(headers) - 1; hi >= 0; hi-- {chain.go1
36:6confusing-naming
chain.go:36:6
// handler in the order they are passed.func chain(middlewares []func(http.Handler) http.Handler, endpoint http.Handler) http.Handler { // Return ahead of time if there aren't any middlewares for the chainmiddleware/content_charset.go1
37:38confusing-results
middleware/content_charset.go:37:38
// Split a string in two parts, cleaning any whitespace.func split(str, sep string) (string, string) { a, b, found := strings.Cut(str, sep)mux_test.go1
1708:20context-cancel-in-loop
mux_test.go:1708:20
ctx, cancel := context.WithCancel(r.Context()) r = r.WithContext(ctx)context.go1
51:2context-stored-in-struct
context.go:51:2
// 1 allocation. parentCtx context.Contextmiddleware/get_head_test.go1
11:6cyclomatic-complexity
middleware/get_head_test.go:11:6
func TestGetHead(t *testing.T) { r := chi.NewRouter()middleware/client_ip_example_test.go1
77:2discarded-error-result
middleware/client_ip_example_test.go:77:2
r.ServeHTTP(w, req) fmt.Print(w.Body.String()) // Output: 198.51.100.42chi.go1
1:1doc-comment-period
chi.go:1:1
// Package chi is a small, idiomatic and composable router for building HTTP services.//tree.go1
447:6early-return
tree.go:447:6
if p < 0 { if xn.tail == '/' { p = len(xsearch)middleware/client_ip_test.go1
325:12error-strings
middleware/client_ip_test.go:325:12
if got := GetClientIP(req.Context()); got != "" { t.Errorf("GetClientIP on empty ctx: want %q, got %q", "", got) }middleware/middleware_test.go1
18:2excessive-blank-identifiers
middleware/middleware_test.go:18:2
func init() { _, filename, _, _ := runtime.Caller(0) testdataDir = path.Join(path.Dir(filename), "/../testdata")chain.go1
12:24exported-declaration-comment
chain.go:12:24
// with `h http.Handler` as the final handler.func (mws Middlewares) Handler(h http.Handler) http.Handler { return &ChainHandler{h, chain(mws, h), mws}middleware/nocache.go1
45:19external-call-in-loop
middleware/nocache.go:45:19
for _, v := range etagHeaders { if r.Header.Get(v) != "" { r.Header.Del(v)middleware/client_ip_test.go1
1:1file-length-limit
middleware/client_ip_test.go:1:1
package middlewaremiddleware/terminal.go1
55:22flag-parameter
middleware/terminal.go:55:22
// colorWritefunc cW(w io.Writer, useColor bool, color []byte, s string, args ...interface{}) { if IsTTY && useColor {chain.go1
1:1format
chain.go:1:1
package chi- Fix (safe): run `strider fmt chain.go`
middleware/client_ip_test.go1
95:6function-length
middleware/client_ip_test.go:95:6
func TestClientIPFromXFF_TrustedPrefixes(t *testing.T) { tt := []struct {tree.go1
695:6function-result-limit
tree.go:695:6
// node type, param key, regexp string, param tail byte, param starting index, param ending indexfunc patNextSegment(pattern string) (nodeTyp, string, string, byte, int, int) { ps := strings.Index(pattern, "{")mux.go1
155:16get-function-return-value
mux.go:155:16
// execute the `handlerFn` http.HandlerFunc.func (mx *Mux) Get(pattern string, handlerFn http.HandlerFunc) { mx.handle(mGET, pattern, handlerFn)middleware/logger.go1
70:16import-shadowing
middleware/logger.go:70:16
type LogEntry interface { Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) Panic(v interface{}, stack []byte)mux_test.go1
1395:18inefficient-sprintf
mux_test.go:1395:18
counter, _ := r.Context().Value(ctxKey{"counter"}).(int) w.Write([]byte(fmt.Sprintf("%v", counter))) }middleware/strip_test.go1
295:47insecure-url-scheme
middleware/strip_test.go:295:47
t.Run(tc.name, func(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "http://example.test"+tc.target, nil) rr := httptest.NewRecorder()chi.go1
66:13interface-method-limit
chi.go:66:13
// using only the standard net/http.type Router interface { http.Handlertree.go1
472:7max-control-nesting
tree.go:472:7
h := xn.endpoints[method] if h != nil && h.handler != nil { rctx.routeParams.Keys = append(rctx.routeParams.Keys, h.paramKeys...)context.go1
141:3modifies-parameter
context.go:141:3
for strings.Contains(p, "/*/") { p = strings.ReplaceAll(p, "/*/", "/") }middleware/route_headers.go1
52:3modifies-value-receiver
middleware/route_headers.go:52:3
if k == nil { hr[header] = []HeaderRoute{} }middleware/client_ip_test.go1
13:10nested-structs
middleware/client_ip_test.go:13:10
func TestClientIPFromHeader(t *testing.T) { tt := []struct { name stringmux_test.go1
721:6no-defer-in-loop
mux_test.go:721:6
ts := httptest.NewServer(r) defer ts.Close()middleware/logger.go1
172:6no-init
middleware/logger.go:172:6
func init() { color := truetree.go1
788:2no-naked-return
tree.go:788:2
} return}context.go1
39:2no-package-var
context.go:39:2
// RouteCtxKey is the context.Context key to store the request context. RouteCtxKey = &contextKey{"RouteContext"})middleware/route_headers.go1
145:9optimize-operands-order
middleware/route_headers.go:145:9
} return len(v) >= len(p.prefix+p.suffix) && strings.HasPrefix(v, p.prefix) && strings.HasSuffix(v, p.suffix)}chain.go1
1:9package-comments
chain.go:1:9
package chimiddleware/compress_test.go1
115:3redefines-builtin-id
middleware/compress_test.go:115:3
name string recover string types []stringtree.go1
81:8redundant-conversion
tree.go:81:8
} mt := methodTyp(2 << n) methodMap[method] = mtmiddleware/compress_test.go1
197:2single-case-switch
middleware/compress_test.go:197:2
var reader io.ReadCloser switch resp.Header.Get("Content-Encoding") { case "gzip":middleware/route_headers.go1
64:2slice-preallocation
middleware/route_headers.go:64:2
} patterns := []Pattern{} for _, m := range match {middleware/content_charset_test.go1
81:33standard-http-method-constant
middleware/content_charset_test.go:81:33
var req, _ = http.NewRequest("GET", "/", nil) req.Header.Set("Content-Type", tt.inputValue)middleware/compress.go1
99:2task-comment
middleware/compress.go:99:2
// // TODO: // lzma: Opera.context_test.go1
24:6test-parallelism
context_test.go:24:6
// "/v1/resources/*/{resource_id}" (wrong)func TestRoutePattern(t *testing.T) { routePatterns := []string{chain.go1
24:1top-level-declaration-order
chain.go:24:1
// execution.type ChainHandler struct { Endpoint http.Handlermiddleware/compress.go1
223:26unchecked-type-assertion
middleware/compress.go:223:26
if pool, ok := c.pooledEncoders[name]; ok { encoder := pool.Get().(ioResetterWriter) cleanup := func() {middleware/middleware_test.go1
73:15unclosed-http-response-body
middleware/middleware_test.go:73:15
resp, err := client.Get("https://localhost:7072") if err != nil {tree.go1
138:44unexported-return
tree.go:138:44
func (s endpoints) Value(method methodTyp) *endpoint { mh, ok := s[method]middleware/logger.go1
140:52unused-parameter
middleware/logger.go:140:52
func (l *defaultLogEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) { switch {middleware/logger_test.go1
17:7unused-receiver
middleware/logger_test.go:17:7
func (cw testLoggerWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { return nil, nil, nilmiddleware/compress.go1
167:16use-any
middleware/compress.go:167:16
pool := &sync.Pool{ New: func() interface{} { return fn(io.Discard, c.level)context_test.go1
53:3add-constant
context_test.go:53:3
x.RoutePatterns = []string{ "/v1/*", "/resources/*",mux_test.go1
1891:5boolean-literal-comparison
mux_test.go:1891:5
tctx.Reset() if r.Match(tctx, "HEAD", "/articles/10") == true { t.Fatal("not expecting to find match for route:", "HEAD", "/articles/10")middleware/compress.go1
65:6cognitive-complexity
middleware/compress.go:65:6
// The types are the content types that are allowed to be compressed.func NewCompressor(level int, types ...string) *Compressor { // If types are provided, set those as the allowed types. If none aremiddleware/realip.go1
39:6confusing-naming
middleware/realip.go:39:6
func realIP(r *http.Request) string { var ip stringtree.go1
695:55confusing-results
tree.go:695:55
// node type, param key, regexp string, param tail byte, param starting index, param ending indexfunc patNextSegment(pattern string) (nodeTyp, string, string, byte, int, int) { ps := strings.Index(pattern, "{")mux_test.go1
1349:3context-stored-in-struct
mux_test.go:1349:3
testcases := []struct { Ctx context.Context Method stringmiddleware/strip_test.go1
102:6cyclomatic-complexity
middleware/strip_test.go:102:6
func TestRedirectSlashes(t *testing.T) { r := chi.NewRouter()middleware/compress.go1
346:3discarded-error-result
middleware/compress.go:346:3
if f, ok := cw.writer().(compressFlusher); ok { f.Flush()context.go1
109:1doc-comment-period
context.go:109:1
// RoutePattern builds the routing pattern string for the particular// request, at the particular point during routing. This means, the valuemiddleware/client_ip_test.go1
328:12error-strings
middleware/client_ip_test.go:328:12
if got := GetClientIPAddr(req.Context()); got.IsValid() { t.Errorf("GetClientIPAddr on empty ctx: want zero, got %v", got) }tree.go1
767:3excessive-blank-identifiers
tree.go:767:3
for { ptyp, paramKey, _, _, _, e := patNextSegment(pat) if ptyp == ntStatic {chain.go1
18:24exported-declaration-comment
chain.go:18:24
// with `h http.Handler` as the final handler.func (mws Middlewares) HandlerFunc(h http.HandlerFunc) http.Handler { return &ChainHandler{h, chain(mws, h), mws}middleware/route_headers.go1
87:31external-call-in-loop
middleware/route_headers.go:87:31
for header, matchers := range hr { headerValue := r.Header.Get(header) if headerValue == "" {mux.go1
1:1file-length-limit
mux.go:1:1
package chichi.go1
1:1format
chi.go:1:1
// Package chi is a small, idiomatic and composable router for building HTTP services.//- Fix (safe): run `strider fmt chi.go`
middleware/compress_test.go1
16:6function-length
middleware/compress_test.go:16:6
func TestCompressor(t *testing.T) { r := chi.NewRouter()middleware/logger.go1
140:41import-shadowing
middleware/logger.go:140:41
func (l *defaultLogEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) { switch {tree.go1
477:7max-control-nesting
tree.go:477:7
for endpoints := range xn.endpoints { if endpoints == mALL || endpoints == mSTUB {middleware/compress.go1
150:2modifies-parameter
middleware/compress.go:150:2
func (c *Compressor) SetEncoder(encoding string, fn EncoderFunc) { encoding = strings.ToLower(encoding) if encoding == "" {middleware/route_headers.go1
54:2modifies-value-receiver
middleware/route_headers.go:54:2
} hr[header] = append(hr[header], HeaderRoute{MatchOne: NewPattern(match), Middleware: middlewareHandler}) return hrmiddleware/client_ip_test.go1
56:10nested-structs
middleware/client_ip_test.go:56:10
func TestClientIPFromXFF_NoTrustedPrefixes(t *testing.T) { tt := []struct { name stringmiddleware/middleware_test.go1
17:6no-init
middleware/middleware_test.go:17:6
func init() { _, filename, _, _ := runtime.Caller(0)middleware/client_ip.go1
12:5no-package-var
middleware/client_ip.go:12:5
// clientIPCtxKey stores the client IP set by any of the ClientIPFrom* middlewares.var clientIPCtxKey = &contextKey{"clientIP"}middleware/route_headers.go1
145:9optimize-operands-order
middleware/route_headers.go:145:9
} return len(v) >= len(p.prefix+p.suffix) && strings.HasPrefix(v, p.prefix) && strings.HasSuffix(v, p.suffix)}context.go1
1:9package-comments
context.go:1:9
package chimiddleware/path_rewrite.go1
9:23redefines-builtin-id
middleware/path_rewrite.go:9:23
// PathRewrite is a simple middleware which allows you to rewrite the request URL path.func PathRewrite(old, new string) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler {middleware/logger.go1
141:2single-case-switch
middleware/logger.go:141:2
func (l *defaultLogEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) { switch { case status < 200:path_value_test.go1
50:5slice-preallocation
path_value_test.go:50:5
r.Handle(tc.method+" "+tc.pattern, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { pathValues := []string{} for _, pathKey := range tc.pathKeys {middleware/realip_test.go1
12:28standard-http-method-constant
middleware/realip_test.go:12:28
func TestXRealIP(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil) req.Header.Add("X-Real-IP", "100.100.100.100")middleware/compress.go1
122:2task-comment
middleware/compress.go:122:2
// TODO: Exception for old MSIE browsers that can't handle non-HTML? // https://zoompf.com/blog/2012/02/lose-the-wait-http-compressioncontext_test.go1
97:6test-parallelism
context_test.go:97:6
// collapsed into a single slash.func TestReplaceWildcardsConsecutive(t *testing.T) { if p := replaceWildcards("/foo/*/*/*/bar"); p != "/foo/bar" {chi.go1
66:1top-level-declaration-order
chi.go:66:1
// using only the standard net/http.type Router interface { http.Handlermiddleware/wrap_writer.go1
149:36unchecked-type-assertion
middleware/wrap_writer.go:149:36
f.wroteHeader = true fl := f.basicWriter.ResponseWriter.(http.Flusher) fl.Flush()middleware/middleware_test.go1
89:15unclosed-http-response-body
middleware/middleware_test.go:89:15
resp, err := http.DefaultClient.Do(req) if err != nil {tree.go1
147:84unexported-return
tree.go:147:84
func (n *node) InsertRoute(method methodTyp, pattern string, handler http.Handler) *node { var parent *nodemiddleware/logger.go1
140:95unused-parameter
middleware/logger.go:140:95
func (l *defaultLogEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) { switch {middleware/recoverer.go1
132:7unused-receiver
middleware/recoverer.go:132:7
func (s prettyStack) decorateFuncCallLine(line string, useColor bool, num int) (string, error) { idx := strings.LastIndex(line, "(")middleware/logger.go1
70:76use-any
middleware/logger.go:70:76
type LogEntry interface { Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) Panic(v interface{}, stack []byte)context_test.go1
54:3add-constant
context_test.go:54:3
"/v1/*", "/resources/*", // Even with many wildcardsmux_test.go1
1906:5boolean-literal-comparison
mux_test.go:1906:5
tctx.Reset() if r.Match(tctx, "GET", "/") != true { t.Fatal("expecting to find match for route:", "GET", "/")middleware/compress.go1
213:22cognitive-complexity
middleware/compress.go:213:22
// selectEncoder returns the encoder, the name of the encoder, and a closer function.func (c *Compressor) selectEncoder(h http.Header, w io.Writer) (io.Writer, string, func()) { header := h.Get("Accept-Encoding")middleware/recoverer.go1
61:6confusing-naming
middleware/recoverer.go:61:6
// do not support them (e.g. on Windows) or when output is being captured.func printPrettyStack(rvr interface{}, useColor bool) { debugStack := debug.Stack()tree.go1
695:74confusing-results
tree.go:695:74
// node type, param key, regexp string, param tail byte, param starting index, param ending indexfunc patNextSegment(pattern string) (nodeTyp, string, string, byte, int, int) { ps := strings.Index(pattern, "{")middleware/throttle.go1
44:6cyclomatic-complexity
middleware/throttle.go:44:6
// ThrottleWithOpts is a middleware that limits number of currently processed requests using passed ThrottleOpts.func ThrottleWithOpts(opts ThrottleOpts) func(http.Handler) http.Handler { if opts.Limit < 1 {middleware/compress_test.go1
36:3discarded-error-result
middleware/compress_test.go:36:3
w.Header().Set("Content-Type", "text/html") w.Write([]byte("textstring")) })context.go1
151:1doc-comment-period
context.go:151:1
// Add will append a URL parameter to the end of the route paramfunc (s *RouteParams) Add(key, value string) {middleware/client_ip_test.go1
347:12error-strings
middleware/client_ip_test.go:347:12
if gotStr != "203.0.113.42" { t.Errorf("GetClientIP: want 203.0.113.42, got %q", gotStr) }chain.go1
24:6exported-declaration-comment
chain.go:24:6
// execution.type ChainHandler struct { Endpoint http.Handlermiddleware/throttle_test.go1
252:41external-call-in-loop
middleware/throttle_test.go:252:41
count429++ assertEqual(t, "3600", res.header.Get("Retry-After")) continuemux_test.go1
1:1file-length-limit
mux_test.go:1:1
package chicontext.go1
1:1format
context.go:1:1
package chi- Fix (safe): run `strider fmt context.go`
middleware/content_charset_test.go1
11:6function-length
middleware/content_charset_test.go:11:6
func TestContentCharset(t *testing.T) { t.Parallel()middleware/middleware_test.go1
82:61import-shadowing
middleware/middleware_test.go:82:61
func testRequest(t *testing.T, ts *httptest.Server, method, path string, body io.Reader) (*http.Response, string) { req, err := http.NewRequest(method, ts.URL+path, body)tree.go1
478:8max-control-nesting
tree.go:478:8
for endpoints := range xn.endpoints { if endpoints == mALL || endpoints == mSTUB { continuemiddleware/content_charset.go1
13:3modifies-parameter
middleware/content_charset.go:13:3
for i, c := range charsets { charsets[i] = strings.ToLower(c) }middleware/route_headers.go1
62:3modifies-value-receiver
middleware/route_headers.go:62:3
if k == nil { hr[header] = []HeaderRoute{} }middleware/client_ip_test.go1
96:10nested-structs
middleware/client_ip_test.go:96:10
func TestClientIPFromXFF_TrustedPrefixes(t *testing.T) { tt := []struct { name stringmiddleware/request_id.go1
46:6no-init
middleware/request_id.go:46:6
func init() { hostname, err := os.Hostname()middleware/compress.go1
16:5no-package-var
middleware/compress.go:16:5
var defaultCompressibleContentTypes = []string{ "text/html",middleware/wrap_writer.go1
28:6optimize-operands-order
middleware/wrap_writer.go:28:6
_, rf := w.(io.ReaderFrom) if fl && hj && rf { return &httpFancyWriter{bw}middleware/basic_auth.go1
1:9package-comments
middleware/basic_auth.go:1:9
package middlewaremiddleware/throttle_test.go1
246:3single-case-switch
middleware/throttle_test.go:246:3
for res := range resultsCh { switch res.status { case http.StatusOK:middleware/realip_test.go1
46:29standard-http-method-constant
middleware/realip_test.go:46:29
for _, v := range xForwardedForIPs { req, _ := http.NewRequest("GET", "/", nil) req.Header.Add("X-Forwarded-For", v)mux_test.go1
1313:1task-comment
mux_test.go:1313:1
// TODO: a Router wrapper test..//middleware/client_ip_test.go1
12:6test-parallelism
middleware/client_ip_test.go:12:6
func TestClientIPFromHeader(t *testing.T) { tt := []struct {context.go1
37:1top-level-declaration-order
context.go:37:1
var ( // RouteCtxKey is the context.Context key to store the request context.middleware/wrap_writer.go1
161:36unchecked-type-assertion
middleware/wrap_writer.go:161:36
func (f *hijackWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { hj := f.basicWriter.ResponseWriter.(http.Hijacker) return hj.Hijack()middleware/middleware_test.go1
119:15unclosed-http-response-body
middleware/middleware_test.go:119:15
resp, err := httpClient.Do(req) if err != nil {tree.go1
382:73unexported-return
tree.go:382:73
func (n *node) FindRoute(rctx *Context, method methodTyp, path string) (*node, endpoints, http.Handler) { // Reset the context routing pattern and paramsmiddleware/logger.go1
168:48unused-parameter
middleware/logger.go:168:48
func (l *defaultLogEntry) Panic(v interface{}, stack []byte) { printPrettyStack(v, l.useColor)middleware/recoverer.go1
172:7unused-receiver
middleware/recoverer.go:172:7
func (s prettyStack) decorateSourceLine(line string, useColor bool, num int) (string, error) { idx := strings.LastIndex(line, ".go:")middleware/logger.go1
71:10use-any
middleware/logger.go:71:10
Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) Panic(v interface{}, stack []byte)}context_test.go1
57:3add-constant
context_test.go:57:3
"/*", "/*", "/*",mux_test.go1
1917:5boolean-literal-comparison
mux_test.go:1917:5
tctx.Reset() if r.Match(tctx, "GET", "/") != false { t.Fatal("not expecting to find match for route:", "GET", "/")middleware/compress_test.go1
112:6cognitive-complexity
middleware/compress_test.go:112:6
func TestCompressorWildcards(t *testing.T) { tests := []struct {mux.go1
422:16confusing-naming
mux.go:422:16
// and routing pattern.func (mx *Mux) handle(method methodTyp, pattern string, handler http.Handler) *node { if len(pattern) == 0 || pattern[0] != '/' {middleware/wrap_writer.go1
15:6cyclomatic-complexity
middleware/wrap_writer.go:15:6
// hook into various parts of the response process.func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter { _, fl := w.(http.Flusher)middleware/compress_test.go1
41:3discarded-error-result
middleware/compress_test.go:41:3
w.Header().Set("Content-Type", "text/html") w.Write([]byte("textstring")) })context_test.go1
5:1doc-comment-period
context_test.go:5:1
// TestRoutePattern tests correct in-the-middle wildcard removals.// If user organizes a router like this:middleware/client_ip_test.go1
350:12error-strings
middleware/client_ip_test.go:350:12
if !gotAddr.IsValid() || gotAddr.String() != "203.0.113.42" { t.Errorf("GetClientIPAddr: want 203.0.113.42, got %v", gotAddr) }chi.go1
66:6exported-declaration-comment
chi.go:66:6
// using only the standard net/http.type Router interface { http.Handlertree.go1
1:1file-length-limit
tree.go:1:1
package chicontext_test.go1
1:1format
context_test.go:1:1
package chi- Fix (safe): run `strider fmt context_test.go`
middleware/route_headers_test.go1
10:6function-length
middleware/route_headers_test.go:10:6
func TestRouteHeaders(t *testing.T) { t.Run("empty router should call next handler exactly once", func(t *testing.T) {middleware/middleware_test.go1
105:71import-shadowing
middleware/middleware_test.go:105:71
func testRequestNoRedirect(t *testing.T, ts *httptest.Server, method, path string, body io.Reader) (*http.Response, string) { req, err := http.NewRequest(method, ts.URL+path, body)middleware/content_charset.go1
30:5modifies-parameter
middleware/content_charset.go:30:5
func contentEncoding(ce string, charsets ...string) bool { _, ce = split(strings.ToLower(ce), ";") _, ce = split(ce, "charset=")middleware/route_headers.go1
68:2modifies-value-receiver
middleware/route_headers.go:68:2
} hr[header] = append(hr[header], HeaderRoute{MatchAny: patterns, Middleware: middlewareHandler}) return hrmiddleware/client_ip_test.go1
185:10nested-structs
middleware/client_ip_test.go:185:10
func TestClientIPFromXFFTrustedProxies(t *testing.T) { tt := []struct { name stringmiddleware/terminal.go1
37:6no-init
middleware/terminal.go:37:6
func init() { // This is sort of cheating: if stdout is a character device, we assumemiddleware/logger.go1
15:2no-package-var
middleware/logger.go:15:2
// LogEntryCtxKey is the context.Context key to store the request log entry. LogEntryCtxKey = &contextKey{"LogEntry"}middleware/wrap_writer.go1
83:5optimize-operands-order
middleware/wrap_writer.go:83:5
func (b *basicWriter) WriteHeader(code int) { if code >= 100 && code <= 199 && code != http.StatusSwitchingProtocols { if !b.discard {middleware/clean_path.go1
1:9package-comments
middleware/clean_path.go:1:9
package middlewaretree.go1
254:2single-case-switch
tree.go:254:2
// Add child depending on next up segment switch segTyp {middleware/realip_test.go1
69:28standard-http-method-constant
middleware/realip_test.go:69:28
func TestXForwardForXRealIPPrecedence(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil) req.Header.Add("X-Forwarded-For", "0.0.0.0")mux_test.go1
1324:1task-comment
mux_test.go:1324:1
//// // TODO: this should be supported...// func TestWoot(t *testing.T) {middleware/client_ip_test.go1
42:18test-parallelism
middleware/client_ip_test.go:42:18
for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { got := run(t, ClientIPFromHeader("X-Real-IP"), func(r *http.Request) {middleware/client_ip.go1
16:1top-level-declaration-order
middleware/client_ip.go:16:1
// name, used by the XFF-based middlewares.const xForwardedForHeader = "X-Forwarded-For"middleware/wrap_writer.go1
174:36unchecked-type-assertion
middleware/wrap_writer.go:174:36
f.wroteHeader = true fl := f.basicWriter.ResponseWriter.(http.Flusher) fl.Flush()middleware/throttle_test.go1
45:16unclosed-http-response-body
middleware/throttle_test.go:45:16
res, err := client.Get(server.URL) assertNoError(t, err)tree.go1
382:80unexported-return
tree.go:382:80
func (n *node) FindRoute(rctx *Context, method methodTyp, path string) (*node, endpoints, http.Handler) { // Reset the context routing pattern and paramsmiddleware/recoverer_test.go1
17:30unused-parameter
middleware/recoverer_test.go:17:30
func (testPrintLogger) Print(v ...interface{}) {}mux.go1
493:7unused-receiver
mux.go:493:7
func (mx *Mux) nextRoutePath(rctx *Context) string { routePath := "/"middleware/logger.go1
88:13use-any
middleware/logger.go:88:13
type LoggerInterface interface { Print(v ...interface{})}context_test.go1
64:11add-constant
context_test.go:64:11
if p := x.RoutePattern(); p != "/v1/resources/{resource_id}/*" { t.Fatal("unexpected route pattern: " + p) }tree_test.go1
427:5boolean-literal-comparison
tree_test.go:427:5
if tr.findPattern("/pages") != false { t.Errorf("find /pages failed")middleware/get_head.go1
10:6cognitive-complexity
middleware/get_head.go:10:6
// GetHead automatically route undefined HEAD requests to GET handlers.func GetHead(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {tree.go1
409:16confusing-naming
tree.go:409:16
// It's like searching through a multi-dimensional radix trie.func (n *node) findRoute(rctx *Context, method methodTyp, path string) *node { nn := nmux.go1
295:16cyclomatic-complexity
mux.go:295:16
// if you define two Mount() routes on the exact same pattern the mount will panic.func (mx *Mux) Mount(pattern string, handler http.Handler) { if handler == nil {middleware/compress_test.go1
46:3discarded-error-result
middleware/compress_test.go:46:3
w.Header().Set("Content-Type", "text/html") w.Write([]byte("textstring")) })middleware/clean_path.go1
10:1doc-comment-period
middleware/clean_path.go:10:1
// CleanPath middleware will clean out double slash mistakes from a user's request path.// For example, if a user requests /users//1 or //users////1 will both be treated as: /users/1middleware/client_ip_test.go1
353:12error-strings
middleware/client_ip_test.go:353:12
if gotAddr.Is6() { t.Errorf("GetClientIPAddr: want IPv4, got IPv6") }chi.go1
119:6exported-declaration-comment
chi.go:119:6
// used by the `docgen` subpackage to generation documentation for Routers.type Routes interface { // Routes returns the routing tree in an easily traversable structure.tree_test.go1
1:1file-length-limit
tree_test.go:1:1
package chimiddleware/basic_auth.go1
1:1format
middleware/basic_auth.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/basic_auth.go`
middleware/strip_test.go1
102:6function-length
middleware/strip_test.go:102:6
func TestRedirectSlashes(t *testing.T) { r := chi.NewRouter()middleware/content_charset.go1
31:5modifies-parameter
middleware/content_charset.go:31:5
_, ce = split(strings.ToLower(ce), ";") _, ce = split(ce, "charset=") ce, _ = split(ce, ";")middleware/route_headers.go1
73:2modifies-value-receiver
middleware/route_headers.go:73:2
func (hr HeaderRouter) RouteDefault(handler func(next http.Handler) http.Handler) HeaderRouter { hr["*"] = []HeaderRoute{{Middleware: handler}} return hrmiddleware/client_ip_test.go1
247:10nested-structs
middleware/client_ip_test.go:247:10
func TestClientIPFromRemoteAddr(t *testing.T) { tt := []struct { name stringmiddleware/logger.go1
20:2no-package-var
middleware/logger.go:20:2
// logging configurations. DefaultLogger func(next http.Handler) http.Handler)middleware/wrap_writer.go1
210:5optimize-operands-order
middleware/wrap_writer.go:210:5
func (f *httpFancyWriter) ReadFrom(r io.Reader) (int64, error) { if f.basicWriter.tee != nil || f.basicWriter.discard { // Route through basicWriter.Write so that the tee and discard semanticsmiddleware/client_ip.go1
1:9package-comments
middleware/client_ip.go:1:9
package middlewaretree.go1
427:3single-case-switch
tree.go:427:3
switch ntyp { case ntStatic:middleware/realip_test.go1
94:28standard-http-method-constant
middleware/realip_test.go:94:28
func TestInvalidIP(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil) req.Header.Add("X-Real-IP", "100.100.100.1000")tree_test.go1
173:2task-comment
tree_test.go:173:2
// TODO: panic if we see {id}{x} because we're missing a delimiter, its not possible. // also {:id}* is not possible.middleware/client_ip_test.go1
55:6test-parallelism
middleware/client_ip_test.go:55:6
func TestClientIPFromXFF_NoTrustedPrefixes(t *testing.T) { tt := []struct {middleware/compress.go1
48:1top-level-declaration-order
middleware/compress.go:48:1
// Compressor represents a set of encoding configurations.type Compressor struct { // The mapping of encoder names to encoder functions.middleware/wrap_writer.go1
179:36unchecked-type-assertion
middleware/wrap_writer.go:179:36
func (f *flushHijackWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { hj := f.basicWriter.ResponseWriter.(http.Hijacker) return hj.Hijack()middleware/throttle_test.go1
116:16unclosed-http-response-body
middleware/throttle_test.go:116:16
res, err := client.Get(server.URL) assertNoError(t, err)mux_test.go1
2057:18unused-parameter
mux_test.go:2057:18
func testHandler(t *testing.T, h http.Handler, method, path string, body io.Reader) (*http.Response, string) { r, _ := http.NewRequest(method, path, body)middleware/logger.go1
140:101use-any
middleware/logger.go:140:101
func (l *defaultLogEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) { switch {context_test.go1
73:3add-constant
context_test.go:73:3
"/with_asterisks*/*", "/{resource_id}", }tree_test.go1
430:5boolean-literal-comparison
tree_test.go:430:5
} if tr.findPattern("/pages*") != false { t.Errorf("find /pages* failed - should be nil")middleware/get_head_test.go1
11:6cognitive-complexity
middleware/get_head_test.go:11:6
func TestGetHead(t *testing.T) { r := chi.NewRouter()tree.go1
846:6confusing-naming
tree.go:846:6
func walk(r Routes, walkFn WalkFunc, parentRoute string, parentMw ...func(http.Handler) http.Handler) error { for _, route := range r.Routes() {mux_test.go1
16:6cyclomatic-complexity
mux_test.go:16:6
func TestMuxBasic(t *testing.T) { var count uint64middleware/compress_test.go1
214:2discarded-error-result
middleware/compress_test.go:214:2
} reader.Close()middleware/client_ip_example_test.go1
12:1doc-comment-period
middleware/client_ip_example_test.go:12:1
// Example_clientIP shows how to choose a ClientIPFrom* middleware. There is// no safe default ā pick exactly ONE based on your network setup:middleware/client_ip_test.go1
427:12error-strings
middleware/client_ip_test.go:427:12
if capturedClientIP == "192.0.2.2" { t.Errorf("VULNERABLE: returned attacker-supplied leftmost IP") }chi.go1
138:6exported-declaration-comment
chi.go:138:6
// to compose middleware chains and http.Handler's.type Middlewares []func(http.Handler) http.Handlermiddleware/clean_path.go1
1:1format
middleware/clean_path.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/clean_path.go`
middleware/throttle.go1
44:6function-length
middleware/throttle.go:44:6
// ThrottleWithOpts is a middleware that limits number of currently processed requests using passed ThrottleOpts.func ThrottleWithOpts(opts ThrottleOpts) func(http.Handler) http.Handler { if opts.Limit < 1 {middleware/content_charset.go1
32:2modifies-parameter
middleware/content_charset.go:32:2
_, ce = split(ce, "charset=") ce, _ = split(ce, ";") return slices.Contains(charsets, ce)tree.go1
142:3modifies-value-receiver
tree.go:142:3
mh = &endpoint{} s[method] = mh }middleware/client_ip_test.go1
504:10nested-structs
middleware/client_ip_test.go:504:10
func TestClientIPFromHeader_MultiValueLastWins(t *testing.T) { tt := []struct { name stringmiddleware/middleware_test.go1
15:5no-package-var
middleware/middleware_test.go:15:5
var testdataDir stringmux.go1
308:5optimize-operands-order
mux.go:308:5
subr, ok := handler.(*Mux) if ok && subr.notFoundHandler == nil && mx.notFoundHandler != nil { subr.NotFound(mx.notFoundHandler)middleware/compress.go1
1:9package-comments
middleware/compress.go:1:9
package middlewaretree.go1
601:3single-case-switch
tree.go:601:3
switch n.typ { case ntStatic:middleware/recoverer_test.go1
95:30standard-http-method-constant
middleware/recoverer_test.go:95:30
req, err := http.NewRequest("GET", "/", nil) if err != nil {tree_test.go1
194:2task-comment
tree_test.go:194:2
// TODO: make a separate test case for this one.. // tr.InsertRoute(mGET, "/articles/{id}/{id}", hStub1) // panic expected, we're duplicating param keysmiddleware/client_ip_test.go1
82:18test-parallelism
middleware/client_ip_test.go:82:18
for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { got := run(t, ClientIPFromXFF(), func(r *http.Request) {middleware/logger.go1
63:1top-level-declaration-order
middleware/logger.go:63:1
// See DefaultLogFormatter for an example implementation.type LogFormatter interface { NewLogEntry(r *http.Request) LogEntrymiddleware/wrap_writer.go1
196:36unchecked-type-assertion
middleware/wrap_writer.go:196:36
f.wroteHeader = true fl := f.basicWriter.ResponseWriter.(http.Flusher) fl.Flush()middleware/throttle_test.go1
131:16unclosed-http-response-body
middleware/throttle_test.go:131:16
res, err := client.Get(server.URL) assertNoError(t, err)middleware/logger.go1
168:35use-any
middleware/logger.go:168:35
func (l *defaultLogEntry) Panic(v interface{}, stack []byte) { printPrettyStack(v, l.useColor)middleware/client_ip_test.go1
21:79add-constant
middleware/client_ip_test.go:21:79
{"ipv6_canonical", "2345:425:2ca1::567:5673:23b5", "2345:425:2ca1::567:5673:23b5"}, {"ipv6_uncompressed_normalized", "2345:0425:2CA1:0000:0000:0567:5673:23B5", "2345:425:2ca1::567:5673:23b5"},tree_test.go1
433:5boolean-literal-comparison
tree_test.go:433:5
} if tr.findPattern("/pages/*") == false { t.Errorf("find /pages/* failed")middleware/recoverer.go1
76:22cognitive-complexity
middleware/recoverer.go:76:22
func (s prettyStack) parse(debugStack []byte, rvr interface{}, useColor bool) ([]byte, error) { var err errormux_test.go1
497:6cyclomatic-complexity
mux_test.go:497:6
func TestMuxComplicatedNotFound(t *testing.T) { decorateRouter := func(r *Mux) {middleware/content_charset_test.go1
81:17discarded-error-result
middleware/content_charset_test.go:81:17
var req, _ = http.NewRequest("GET", "/", nil) req.Header.Set("Content-Type", tt.inputValue)middleware/compress.go1
31:1doc-comment-period
middleware/compress.go:31:1
// Compress is a middleware that compresses response// body of a given content types to a data format basedmiddleware/client_ip_test.go1
537:14error-strings
middleware/client_ip_test.go:537:14
if got != tc.out { t.Errorf("VULNERABLE or wrong: want %q, got %q", tc.out, got) }context.go1
27:6exported-declaration-comment
context.go:27:6
// http.Request Context.func RouteContext(ctx context.Context) *Context { val, _ := ctx.Value(RouteCtxKey).(*Context)middleware/client_ip.go1
1:1format
middleware/client_ip.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/client_ip.go`
mux_test.go1
16:6function-length
mux_test.go:16:6
func TestMuxBasic(t *testing.T) { var count uint64middleware/logger.go1
82:2modifies-parameter
middleware/logger.go:82:2
func WithLogEntry(r *http.Request, entry LogEntry) *http.Request { r = r.WithContext(context.WithValue(r.Context(), LogEntryCtxKey, entry)) return rtree.go1
796:39modifies-value-receiver
tree.go:796:39
func (ns nodes) Len() int { return len(ns) }func (ns nodes) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] }func (ns nodes) Less(i, j int) bool { return ns[i].label < ns[j].label }middleware/client_ip_test.go1
558:10nested-structs
middleware/client_ip_test.go:558:10
func TestXFF_V4MappedIPv6BypassesTrustedV4Prefix(t *testing.T) { tt := []struct { name stringmiddleware/nocache.go1
12:5no-package-var
middleware/nocache.go:12:5
// Unix epoch timevar epoch = time.Unix(0, 0).UTC().Format(http.TimeFormat)mux.go1
311:5optimize-operands-order
mux.go:311:5
} if ok && subr.methodNotAllowedHandler == nil && mx.methodNotAllowedHandler != nil { subr.MethodNotAllowed(mx.methodNotAllowedHandler)middleware/content_charset.go1
1:9package-comments
middleware/content_charset.go:1:9
package middlewaremiddleware/request_id_test.go1
29:31standard-http-method-constant
middleware/request_id_test.go:29:31
func() *http.Request { req, _ := http.NewRequest("GET", "/", nil) req.Header.Add("X-Request-Id", "req-123456")middleware/client_ip_test.go1
95:6test-parallelism
middleware/client_ip_test.go:95:6
func TestClientIPFromXFF_TrustedPrefixes(t *testing.T) { tt := []struct {middleware/middleware.go1
17:1top-level-declaration-order
middleware/middleware.go:17:1
// for defining context keys was copied from Go 1.7's new use of context in net/http.type contextKey struct { name stringmiddleware/wrap_writer.go1
201:36unchecked-type-assertion
middleware/wrap_writer.go:201:36
func (f *httpFancyWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { hj := f.basicWriter.ResponseWriter.(http.Hijacker) return hj.Hijack()middleware/throttle_test.go1
169:16unclosed-http-response-body
middleware/throttle_test.go:169:16
res, err := client.Get(server.URL) assertNoError(t, err)middleware/middleware_test.go1
149:37use-any
middleware/middleware_test.go:149:37
func assertEqual(t *testing.T, a, b interface{}) { t.Helper()middleware/client_ip_test.go1
63:23add-constant
middleware/client_ip_test.go:63:23
{"empty", []string{""}, ""}, {"single", []string{"100.100.100.100"}, "100.100.100.100"}, {"comma_space", []string{"1.1.1.1, 2.2.2.2"}, "2.2.2.2"},tree_test.go1
436:5boolean-literal-comparison
tree_test.go:436:5
} if tr.findPattern("/articles/{id}/*") == false { t.Errorf("find /articles/{id}/* failed")middleware/route_headers.go1
77:24cognitive-complexity
middleware/route_headers.go:77:24
func (hr HeaderRouter) Handler(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {mux_test.go1
885:6cyclomatic-complexity
mux_test.go:885:6
func TestMuxBig(t *testing.T) { r := bigMux()middleware/get_head_test.go1
16:3discarded-error-result
middleware/get_head_test.go:16:3
w.Header().Set("X-Test", "yes") w.Write([]byte("bye")) })middleware/compress.go1
134:1doc-comment-period
middleware/compress.go:134:1
// SetEncoder can be used to set the implementation of a compression algorithm.//middleware/client_ip_test.go1
583:14error-strings
middleware/client_ip_test.go:583:14
if got != tc.out { t.Errorf("VULNERABLE: v4-mapped IPv6 escaped v4 trusted prefix ā want %q, got %q", tc.out, got) }context.go1
45:6exported-declaration-comment
context.go:45:6
// an optional routing path.type Context struct { Routes Routesmiddleware/client_ip_bench_test.go1
1:1format
middleware/client_ip_bench_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/client_ip_bench_test.go`
mux_test.go1
316:6function-length
mux_test.go:316:6
func TestMuxNestedNotFound(t *testing.T) { r := NewRouter()middleware/recoverer.go1
119:2modifies-parameter
middleware/recoverer.go:119:2
func (s prettyStack) decorateLine(line string, useColor bool, num int) (string, error) { line = strings.TrimSpace(line) if strings.HasPrefix(line, "\t") || strings.Contains(line, ".go:") {tree.go1
796:46modifies-value-receiver
tree.go:796:46
func (ns nodes) Len() int { return len(ns) }func (ns nodes) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] }func (ns nodes) Less(i, j int) bool { return ns[i].label < ns[j].label }middleware/client_ip_test.go1
616:10nested-structs
middleware/client_ip_test.go:616:10
func TestClientIPFromRemoteAddr_V4MappedIsUnmapped(t *testing.T) { tt := []struct { name stringmiddleware/nocache.go1
15:5no-package-var
middleware/nocache.go:15:5
// Taken from https://github.com/mytrile/nocachevar noCacheHeaders = map[string]string{ "Expires": epoch,mux.go1
423:5optimize-operands-order
mux.go:423:5
func (mx *Mux) handle(method methodTyp, pattern string, handler http.Handler) *node { if len(pattern) == 0 || pattern[0] != '/' { panic(fmt.Sprintf("chi: routing pattern must begin with '/' in '%s'", pattern))middleware/content_encoding.go1
1:9package-comments
middleware/content_encoding.go:1:9
package middlewaremiddleware/request_id_test.go1
39:31standard-http-method-constant
middleware/request_id_test.go:39:31
func() *http.Request { req, _ := http.NewRequest("GET", "/", nil) req.Header.Add("X-Trace-Id", "trace:abc123")middleware/client_ip_test.go1
162:18test-parallelism
middleware/client_ip_test.go:162:18
for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { got := run(t, ClientIPFromXFF(tc.prefixes...), func(r *http.Request) {middleware/recoverer.go1
52:1top-level-declaration-order
middleware/recoverer.go:52:1
// for ability to test the PrintPrettyStack functionvar recovererErrorWriter io.Writer = os.Stderrmiddleware/wrap_writer.go1
206:37unchecked-type-assertion
middleware/wrap_writer.go:206:37
func (f *http2FancyWriter) Push(target string, opts *http.PushOptions) error { return f.basicWriter.ResponseWriter.(http.Pusher).Push(target, opts)}middleware/throttle_test.go1
189:16unclosed-http-response-body
middleware/throttle_test.go:189:16
res, err := client.Get(server.URL) assertNoError(t, err)middleware/recoverer.go1
54:27use-any
middleware/recoverer.go:54:27
func PrintPrettyStack(rvr interface{}) { printPrettyStack(rvr, true)middleware/client_ip_test.go1
66:47add-constant
middleware/client_ip_test.go:66:47
{"comma_no_space", []string{"1.1.1.1,2.2.2.2"}, "2.2.2.2"}, {"multi_header_merged", []string{"1.1.1.1", "2.2.2.2"}, "2.2.2.2"}, {"multi_header_with_commas", []string{"5.5.5.5, 6.6.6.6", "7.7.7.7, 4.4.4.4"}, "4.4.4.4"},tree_test.go1
439:5boolean-literal-comparison
tree_test.go:439:5
} if tr.findPattern("/articles/{something}/*") == false { t.Errorf("find /articles/{something}/* failed")middleware/route_headers.go1
116:22cognitive-complexity
middleware/route_headers.go:116:22
func (r HeaderRoute) IsMatch(value string) bool { if len(r.MatchAny) > 0 {mux_test.go1
1177:6cyclomatic-complexity
mux_test.go:1177:6
func TestMuxSubroutes(t *testing.T) { hHubView1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {middleware/get_head_test.go1
22:4discarded-error-result
middleware/get_head_test.go:22:4
w.Header().Set("X-Article", id) w.Write([]byte("article:" + id)) })middleware/content_type.go1
8:1doc-comment-period
middleware/content_type.go:8:1
// SetHeader is a convenience handler to set a response header key/valuefunc SetHeader(key, value string) func(http.Handler) http.Handler {middleware/client_ip_test.go1
604:12error-strings
middleware/client_ip_test.go:604:12
if got != "" { t.Errorf("VULNERABLE: zoned IPv6 escaped v6 trusted prefix ā want %q, got %q", "", got) }context.go1
100:19exported-declaration-comment
context.go:100:19
// routing context.func (x *Context) URLParam(key string) string { for k := len(x.URLParams.Keys) - 1; k >= 0; k-- {middleware/client_ip_test.go1
1:1format
middleware/client_ip_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/client_ip_test.go`
mux_test.go1
497:6function-length
mux_test.go:497:6
func TestMuxComplicatedNotFound(t *testing.T) { decorateRouter := func(r *Mux) {middleware/route_headers.go1
49:2modifies-parameter
middleware/route_headers.go:49:2
func (hr HeaderRouter) Route(header, match string, middlewareHandler func(next http.Handler) http.Handler) HeaderRouter { header = strings.ToLower(header) k := hr[header]middleware/client_ip_test.go1
647:10nested-structs
middleware/client_ip_test.go:647:10
func TestXFF_FailClosedOnUnparseable(t *testing.T) { tt := []struct { name stringmiddleware/nocache.go1
22:5no-package-var
middleware/nocache.go:22:5
var etagHeaders = []string{ "ETag",mux_test.go1
701:24optimize-operands-order
mux_test.go:701:24
defer func() { if r := recover(); r != nil && !tc.shouldPanic { t.Errorf("Unexpected panic for pattern %s:\n%v", tc.pattern, r)middleware/content_type.go1
1:9package-comments
middleware/content_type.go:1:9
package middlewaremiddleware/sunset_test.go1
15:29standard-http-method-constant
middleware/sunset_test.go:15:29
t.Run("Sunset without link", func(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil) w := httptest.NewRecorder()middleware/client_ip_test.go1
175:6test-parallelism
middleware/client_ip_test.go:175:6
func TestClientIPFromXFF_PanicsOnBadPrefix(t *testing.T) { defer func() {middleware/recoverer_test.go1
15:1top-level-declaration-order
middleware/recoverer_test.go:15:1
type testPrintLogger struct{}middleware/wrap_writer.go1
219:36unchecked-type-assertion
middleware/wrap_writer.go:219:36
} rf := f.basicWriter.ResponseWriter.(io.ReaderFrom) f.basicWriter.maybeWriteHeader()middleware/throttle_test.go1
235:14unclosed-http-response-body
middleware/throttle_test.go:235:14
defer wg.Done() res, _ := client.Get(server.URL) resultsCh <- result{status: res.StatusCode, header: res.Header}middleware/recoverer.go1
61:27use-any
middleware/recoverer.go:61:27
// do not support them (e.g. on Windows) or when output is being captured.func printPrettyStack(rvr interface{}, useColor bool) { debugStack := debug.Stack()middleware/client_ip_test.go1
68:37add-constant
middleware/client_ip_test.go:68:37
{"multi_header_with_commas", []string{"5.5.5.5, 6.6.6.6", "7.7.7.7, 4.4.4.4"}, "4.4.4.4"}, {"ipv6", []string{"2001:db8::1"}, "2001:db8::1"}, {"mixed_v4_v6_rightmost_wins", []string{"203.0.113.1, 2001:db8::1"}, "2001:db8::1"},tree_test.go1
442:5boolean-literal-comparison
tree_test.go:442:5
} if tr.findPattern("/articles/{slug}/{uid}/*") == false { t.Errorf("find /articles/{slug}/{uid}/* failed")middleware/strip_test.go1
102:6cognitive-complexity
middleware/strip_test.go:102:6
func TestRedirectSlashes(t *testing.T) { r := chi.NewRouter()mux_test.go1
1807:6cyclomatic-complexity
mux_test.go:1807:6
func TestQueryHTTPMethod(t *testing.T) { r := NewRouter()middleware/get_head_test.go1
28:4discarded-error-result
middleware/get_head_test.go:28:4
w.Header().Set("X-User", "-") w.Write([]byte("user")) })middleware/logger.go1
23:1doc-comment-period
middleware/logger.go:23:1
// Logger is a middleware that logs the start and end of each request, along// with some useful data about what was requested, what the response status was,middleware/compress_test.go1
158:15error-strings
middleware/compress_test.go:158:15
if r := recover(); tt.recover != fmt.Sprintf("%v", r) { t.Errorf("Unexpected value recovered: %v", r) }context.go1
123:19exported-declaration-comment
context.go:123:19
// }func (x *Context) RoutePattern() string { if x == nil {middleware/compress.go1
1:1format
middleware/compress.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/compress.go`
mux_test.go1
642:6function-length
mux_test.go:642:6
func TestMuxHandlePatternValidation(t *testing.T) { testCases := []struct {middleware/route_headers.go1
59:2modifies-parameter
middleware/route_headers.go:59:2
func (hr HeaderRouter) RouteAny(header string, match []string, middlewareHandler func(next http.Handler) http.Handler) HeaderRouter { header = strings.ToLower(header) k := hr[header]middleware/compress.go1
54:30nested-structs
middleware/compress.go:54:30
// The set of content types allowed to be compressed. allowedTypes map[string]struct{} allowedWildcards map[string]struct{}middleware/realip.go1
12:5no-package-var
middleware/realip.go:12:5
var trueClientIP = http.CanonicalHeaderKey("True-Client-IP")var xForwardedFor = http.CanonicalHeaderKey("X-Forwarded-For")tree.go1
632:6optimize-operands-order
tree.go:632:6
n.walk(func(eps endpoints, subroutes Routes) bool { if eps[mSTUB] != nil && eps[mSTUB].handler != nil && subroutes == nil { return falsemiddleware/get_head.go1
1:9package-comments
middleware/get_head.go:1:9
package middlewaremiddleware/sunset_test.go1
46:29standard-http-method-constant
middleware/sunset_test.go:46:29
t.Run("Sunset with link", func(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil) w := httptest.NewRecorder()middleware/client_ip_test.go1
184:6test-parallelism
middleware/client_ip_test.go:184:6
func TestClientIPFromXFFTrustedProxies(t *testing.T) { tt := []struct {middleware/request_id.go1
21:1top-level-declaration-order
middleware/request_id.go:21:1
// RequestIDKey is the key that holds the unique request ID in a request context.const RequestIDKey ctxKeyRequestID = 0middleware/wrap_writer.go1
241:36unchecked-type-assertion
middleware/wrap_writer.go:241:36
f.wroteHeader = true fl := f.basicWriter.ResponseWriter.(http.Flusher) fl.Flush()middleware/throttle_test.go1
288:17unclosed-http-response-body
middleware/throttle_test.go:288:17
go func() { resp, err := client.Get(server.URL) if err != nil {middleware/recoverer.go1
76:51use-any
middleware/recoverer.go:76:51
func (s prettyStack) parse(debugStack []byte, rvr interface{}, useColor bool) ([]byte, error) { var err errormiddleware/client_ip_test.go1
79:82add-constant
middleware/client_ip_test.go:79:82
// See https://adam-p.ca/blog/2022/03/x-forwarded-for/ for more details. {"weird_with_empties_then_valid_rightmost", []string{"oh, hi,,127.0.0.1,,,,"}, "127.0.0.1"}, }middleware/strip_test.go1
276:6cognitive-complexity
middleware/strip_test.go:276:6
func TestRedirectSlashes_PreventBackslashRelativeOpenRedirect(t *testing.T) { h := RedirectSlashes(http.NotFoundHandler())tree.go1
409:16cyclomatic-complexity
tree.go:409:16
// It's like searching through a multi-dimensional radix trie.func (n *node) findRoute(rctx *Context, method methodTyp, path string) *node { nn := nmiddleware/get_head_test.go1
33:4discarded-error-result
middleware/get_head_test.go:33:4
w.Header().Set("X-User", id) w.Write([]byte("user:" + id)) })middleware/nocache.go1
31:1doc-comment-period
middleware/nocache.go:31:1
// NoCache is a simple piece of middleware that sets a number of HTTP headers to prevent// a router (or subrouter) from being cached by an upstream proxy and/or client.middleware/content_charset_test.go1
100:12error-strings
middleware/content_charset_test.go:100:12
if s1 != "type1" || s2 != "type2" { t.Errorf("Want type1, type2 got %s, %s", s1, s2) }middleware/clean_path.go1
12:6exported-declaration-comment
middleware/clean_path.go:12:6
// For example, if a user requests /users//1 or //users////1 will both be treated as: /users/1func CleanPath(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {middleware/compress_test.go1
1:1format
middleware/compress_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/compress_test.go`
mux_test.go1
956:6function-length
mux_test.go:956:6
func bigMux() Router { var r *Muxmux.go1
87:2modifies-parameter
mux.go:87:2
// NOTE: r.WithContext() causes 2 allocations and context.WithValue() causes 1 allocation r = r.WithContext(context.WithValue(r.Context(), RouteCtxKey, rctx))middleware/compress.go1
55:30nested-structs
middleware/compress.go:55:30
allowedTypes map[string]struct{} allowedWildcards map[string]struct{} // The list of encoders in order of decreasing precedence.middleware/realip.go1
13:5no-package-var
middleware/realip.go:13:5
var trueClientIP = http.CanonicalHeaderKey("True-Client-IP")var xForwardedFor = http.CanonicalHeaderKey("X-Forwarded-For")var xRealIP = http.CanonicalHeaderKey("X-Real-IP")tree.go1
704:5optimize-operands-order
tree.go:704:5
// Sanity check if ps >= 0 && ws >= 0 && ws < ps { panic("chi: wildcard '*' must be the last pattern in a route, otherwise use a '{param}'")middleware/heartbeat.go1
1:9package-comments
middleware/heartbeat.go:1:9
package middlewaremux_test.go1
1259:28standard-http-method-constant
mux_test.go:1259:28
router := r req, _ := http.NewRequest("GET", "/accounts/44/hi", nil)middleware/client_ip_test.go1
224:18test-parallelism
middleware/client_ip_test.go:224:18
for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { got := run(t, ClientIPFromXFFTrustedProxies(tc.n), func(r *http.Request) {middleware/route_headers.go1
46:1top-level-declaration-order
middleware/route_headers.go:46:1
type HeaderRouter map[string][]HeaderRoutemux.go1
81:22unchecked-type-assertion
mux.go:81:22
// into the pool for reuse from another request. rctx = mx.pool.Get().(*Context) rctx.Reset()mux_test.go1
166:15unclosed-http-response-body
mux_test.go:166:15
// HEAD /ping resp, err := http.Head(ts.URL + "/ping") if err != nil {middleware/recoverer_test.go1
17:35use-any
middleware/recoverer_test.go:17:35
func (testPrintLogger) Print(v ...interface{}) {}middleware/client_ip_test.go1
116:23add-constant
middleware/client_ip_test.go:116:23
name: "all_trusted_returns_empty", prefixes: []string{"203.0.113.0/24"}, xff: []string{"203.0.113.10, 203.0.113.20"},middleware/throttle.go1
44:6cognitive-complexity
middleware/throttle.go:44:6
// ThrottleWithOpts is a middleware that limits number of currently processed requests using passed ThrottleOpts.func ThrottleWithOpts(opts ThrottleOpts) func(http.Handler) http.Handler { if opts.Limit < 1 {tree.go1
628:16cyclomatic-complexity
tree.go:628:16
func (n *node) routes() []Route { rts := []Route{}middleware/heartbeat.go1
18:5discarded-error-result
middleware/heartbeat.go:18:5
w.WriteHeader(http.StatusOK) w.Write([]byte(".")) returnmiddleware/profiler.go1
13:1doc-comment-period
middleware/profiler.go:13:1
// Profiler is a convenient subrouter used for mounting net/http/pprof. ie.//middleware/content_charset_test.go1
106:12error-strings
middleware/content_charset_test.go:106:12
if s1 != "type1" { t.Errorf("Want \"type1\" got \"%s\"", s1) }middleware/client_ip.go1
41:6exported-declaration-comment
middleware/client_ip.go:41:6
// stripped before storage.func ClientIPFromHeader(trustedHeader string) func(http.Handler) http.Handler { header := http.CanonicalHeaderKey(trustedHeader)middleware/content_charset.go1
1:1format
middleware/content_charset.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/content_charset.go`
mux_test.go1
1096:6function-length
mux_test.go:1096:6
func TestMuxSubroutesBasic(t *testing.T) { hIndex := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {mux.go1
333:3modifies-parameter
mux.go:333:3
mx.handle(mALL|mSTUB, pattern+"/", mountHandler) pattern += "/" }middleware/compress.go1
68:34nested-structs
middleware/compress.go:68:34
// provided, use the default list. allowedTypes := make(map[string]struct{}) allowedWildcards := make(map[string]struct{})middleware/realip.go1
14:5no-package-var
middleware/realip.go:14:5
var xForwardedFor = http.CanonicalHeaderKey("X-Forwarded-For")var xRealIP = http.CanonicalHeaderKey("X-Real-IP")middleware/logger.go1
1:9package-comments
middleware/logger.go:1:9
package middlewaremux_test.go1
1298:26standard-http-method-constant
mux_test.go:1298:26
r, _ := http.NewRequest("GET", "/", nil) rctx := NewRouteContext()middleware/client_ip_test.go1
237:6test-parallelism
middleware/client_ip_test.go:237:6
func TestClientIPFromXFFTrustedProxies_PanicsOnZero(t *testing.T) { defer func() {middleware/throttle.go1
134:1top-level-declaration-order
middleware/throttle.go:134:1
// token represents a request that is being processed.type token struct{}mux.go1
449:40unchecked-type-assertion
mux.go:449:40
// Grab the route context object rctx := r.Context().Value(RouteCtxKey).(*Context)mux_test.go1
2041:15unclosed-http-response-body
mux_test.go:2041:15
resp, err := http.DefaultClient.Do(req) if err != nil {middleware/terminal.go1
55:69use-any
middleware/terminal.go:55:69
// colorWritefunc cW(w io.Writer, useColor bool, color []byte, s string, args ...interface{}) { if IsTTY && useColor {middleware/client_ip_test.go1
169:14add-constant
middleware/client_ip_test.go:169:14
if got != tc.out { t.Errorf("want %q, got %q", tc.out, got) }middleware/wrap_writer.go1
15:6cognitive-complexity
middleware/wrap_writer.go:15:6
// hook into various parts of the response process.func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter { _, fl := w.(http.Flusher)tree.go1
695:6cyclomatic-complexity
tree.go:695:6
// node type, param key, regexp string, param tail byte, param starting index, param ending indexfunc patNextSegment(pattern string) (nodeTyp, string, string, byte, int, int) { ps := strings.Index(pattern, "{")middleware/middleware_test.go1
44:3discarded-error-result
middleware/middleware_test.go:44:3
w.Write([]byte("OK")) })middleware/request_id.go1
23:1doc-comment-period
middleware/request_id.go:23:1
// RequestIDHeader is the name of the HTTP Header which contains the request id.// Exported so that it can be changed by developersmiddleware/content_charset_test.go1
109:12error-strings
middleware/content_charset_test.go:109:12
if s2 != "" { t.Errorf("Want empty string got \"%s\"", s2) }middleware/client_ip.go1
85:6exported-declaration-comment
middleware/client_ip.go:85:6
// Panics at startup if any prefix is invalid.func ClientIPFromXFF(trustedIPPrefixes ...string) func(http.Handler) http.Handler { prefixes := make([]netip.Prefix, len(trustedIPPrefixes))middleware/content_charset_test.go1
1:1format
middleware/content_charset_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/content_charset_test.go`
mux_test.go1
1177:6function-length
mux_test.go:1177:6
func TestMuxSubroutes(t *testing.T) { hHubView1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {mux.go1
389:3modifies-parameter
mux.go:389:3
rctx.RoutePath = mx.nextRoutePath(rctx) subPattern := node.subroutes.Find(rctx, method, rctx.RoutePath)middleware/compress.go1
69:38nested-structs
middleware/compress.go:69:38
allowedTypes := make(map[string]struct{}) allowedWildcards := make(map[string]struct{}) if len(types) > 0 {middleware/recoverer.go1
52:5no-package-var
middleware/recoverer.go:52:5
// for ability to test the PrintPrettyStack functionvar recovererErrorWriter io.Writer = os.Stderrmiddleware/maybe.go1
1:9package-comments
middleware/maybe.go:1:9
package middlewaremux_test.go1
1702:31standard-http-method-constant
mux_test.go:1702:31
w := httptest.NewRecorder() r, err := http.NewRequest("GET", "/ok", nil) if err != nil {middleware/client_ip_test.go1
246:6test-parallelism
middleware/client_ip_test.go:246:6
func TestClientIPFromRemoteAddr(t *testing.T) { tt := []struct {middleware/wrap_writer.go1
48:1top-level-declaration-order
middleware/wrap_writer.go:48:1
// into various parts of the response process.type WrapResponseWriter interface { http.ResponseWritermux_test.go1
53:36unchecked-type-assertion
mux_test.go:53:36
ctx := r.Context() user := ctx.Value(ctxKey{"user"}).(string) w.WriteHeader(200)middleware/value.go1
9:25use-any
middleware/value.go:9:25
// WithValue is a middleware that sets a given key/value in a context chain.func WithValue(key, val interface{}) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler {middleware/client_ip_test.go1
195:42add-constant
middleware/client_ip_test.go:195:42
{"n3_third_from_right", 3, []string{"1.1.1.1, 2.2.2.2, 3.3.3.3, 4.4.4.4"}, "2.2.2.2"}, {"n2_exactly_matches_len", 2, []string{"1.1.1.1, 2.2.2.2"}, "1.1.1.1"},middleware/wrap_writer.go1
82:23cognitive-complexity
middleware/wrap_writer.go:82:23
func (b *basicWriter) WriteHeader(code int) { if code >= 100 && code <= 199 && code != http.StatusSwitchingProtocols {tree.go1
846:6cyclomatic-complexity
tree.go:846:6
func walk(r Routes, walkFn WalkFunc, parentRoute string, parentMw ...func(http.Handler) http.Handler) error { for _, route := range r.Routes() {middleware/realip_test.go1
12:12discarded-error-result
middleware/realip_test.go:12:12
func TestXRealIP(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil) req.Header.Add("X-Real-IP", "100.100.100.100")middleware/route_headers.go1
8:1doc-comment-period
middleware/route_headers.go:8:1
// RouteHeaders is a neat little header-based router that allows you to direct// the flow of a request through a middleware stack based on a request header.middleware/logger_test.go1
25:13error-strings
middleware/logger_test.go:25:13
if !ok { t.Errorf("http.Hijacker is unavailable on the writer. add the interface methods.") }middleware/client_ip.go1
138:6exported-declaration-comment
middleware/client_ip.go:138:6
// Panics at startup if numTrustedProxies < 1.func ClientIPFromXFFTrustedProxies(numTrustedProxies int) func(http.Handler) http.Handler { if numTrustedProxies < 1 {middleware/content_encoding_test.go1
1:1format
middleware/content_encoding_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/content_encoding_test.go`
mux_test.go1
1922:6function-length
mux_test.go:1922:6
func TestMuxFind(t *testing.T) { r := NewRouter()mux.go1
481:3modifies-parameter
mux.go:481:3
} r.Pattern = rctx.RoutePattern()middleware/compress.go1
76:32nested-structs
middleware/compress.go:76:32
if before, ok := strings.CutSuffix(t, "/*"); ok { allowedWildcards[before] = struct{}{} } else {middleware/request_id.go1
25:5no-package-var
middleware/request_id.go:25:5
// Exported so that it can be changed by developersvar RequestIDHeader = "X-Request-Id"middleware/middleware.go1
1:9package-comments
middleware/middleware.go:1:9
package middlewaremux_test.go1
2112:28standard-http-method-constant
mux_test.go:2112:28
w := httptest.NewRecorder() r, _ := http.NewRequest("GET", path, nil)middleware/client_ip_test.go1
259:18test-parallelism
middleware/client_ip_test.go:259:18
for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { got := run(t, ClientIPFromRemoteAddr, func(r *http.Request) {mux_test.go2
2064:1top-level-declaration-order
mux_test.go:2064:1
type ctxKey struct { name string336:43unchecked-type-assertion
mux_test.go:336:43
}).NotFound(func(w http.ResponseWriter, r *http.Request) { chkMw := r.Context().Value(ctxKey{"mw"}).(string) chkWith := r.Context().Value(ctxKey{"with"}).(string)mux.go1
54:24use-any
mux.go:54:24
mux := &Mux{tree: &node{}, pool: &sync.Pool{}} mux.pool.New = func() interface{} { return NewRouteContext()middleware/client_ip_test.go1
195:63add-constant
middleware/client_ip_test.go:195:63
{"n3_third_from_right", 3, []string{"1.1.1.1, 2.2.2.2, 3.3.3.3, 4.4.4.4"}, "2.2.2.2"}, {"n2_exactly_matches_len", 2, []string{"1.1.1.1, 2.2.2.2"}, "1.1.1.1"},middleware/wrap_writer.go1
96:23cognitive-complexity
middleware/wrap_writer.go:96:23
func (b *basicWriter) Write(buf []byte) (n int, err error) { b.maybeWriteHeader()middleware/realip_test.go1
22:3discarded-error-result
middleware/realip_test.go:22:3
realIP = r.RemoteAddr w.Write([]byte("Hello World")) })middleware/strip.go1
36:1doc-comment-period
middleware/strip.go:36:1
// RedirectSlashes is a middleware that will match request paths with a trailing// slash and redirect to the same path, less the trailing slash.middleware/route_headers_test.go1
208:14error-strings
middleware/route_headers_test.go:208:14
if got := p.Match(tt.value); got != tt.expected { t.Errorf("Pattern(%q).Match(%q) = %v, want %v", tt.pattern, tt.value, got, tt.expected) }middleware/client_ip.go1
176:6exported-declaration-comment
middleware/client_ip.go:176:6
// IPv6 zones are preserved (link-local connections may legitimately have one).func ClientIPFromRemoteAddr(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {middleware/content_type.go1
1:1format
middleware/content_type.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/content_type.go`
tree.go2
147:16function-length
tree.go:147:16
func (n *node) InsertRoute(method methodTyp, pattern string, handler http.Handler) *node { var parent *node73:2modifies-parameter
tree.go:73:2
} method = strings.ToUpper(method) if _, ok := methodMap[method]; ok {middleware/compress.go1
78:23nested-structs
middleware/compress.go:78:23
} else { allowedTypes[t] = struct{}{} }middleware/request_id.go1
27:5no-package-var
middleware/request_id.go:27:5
var prefix stringvar reqid atomic.Uint64middleware/nocache.go1
1:9package-comments
middleware/nocache.go:1:9
package middlewaremiddleware/client_ip_test.go1
276:6test-parallelism
middleware/client_ip_test.go:276:6
// first-write-wins semantics.func TestClientIPLastWriteWins(t *testing.T) { t.Run("later_overrides_earlier", func(t *testing.T) {tree.go1
19:1top-level-declaration-order
tree.go:19:1
const ( mSTUB methodTyp = 1 << iotamux_test.go1
337:47unchecked-type-assertion
mux_test.go:337:47
chkMw := r.Context().Value(ctxKey{"mw"}).(string) chkWith := r.Context().Value(ctxKey{"with"}).(string) w.WriteHeader(404)middleware/client_ip_test.go1
220:48add-constant
middleware/client_ip_test.go:220:48
// Normalization at the chosen position: v4-mapped IPv6 folds to v4, zone stripped. {"v4_mapped_at_position_folded", 1, []string{"::ffff:1.2.3.4"}, "1.2.3.4"}, {"zone_stripped_at_position", 1, []string{"2001:db8::1%eth0"}, "2001:db8::1"},mux.go1
295:16cognitive-complexity
mux.go:295:16
// if you define two Mount() routes on the exact same pattern the mount will panic.func (mx *Mux) Mount(pattern string, handler http.Handler) { if handler == nil {middleware/realip_test.go1
46:13discarded-error-result
middleware/realip_test.go:46:13
for _, v := range xForwardedForIPs { req, _ := http.NewRequest("GET", "/", nil) req.Header.Add("X-Forwarded-For", v)middleware/strip_test.go1
201:1doc-comment-period
middleware/strip_test.go:201:1
// This tests a http.Handler that is not chi.Router// In these cases, the routeContext is nilmux_test.go1
702:15error-strings
mux_test.go:702:15
if r := recover(); r != nil && !tc.shouldPanic { t.Errorf("Unexpected panic for pattern %s:\n%v", tc.pattern, r) }middleware/client_ip.go1
192:6exported-declaration-comment
middleware/client_ip.go:192:6
// Convenient for logging, rate-limit keys, etc.func GetClientIP(ctx context.Context) string { ip := GetClientIPAddr(ctx)middleware/content_type_test.go1
1:1format
middleware/content_type_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/content_type_test.go`
tree.go2
243:16function-length
tree.go:243:16
// pattern segment is added to the url pattern tree as individual nodes, depending on type.func (n *node) addChild(child *node, prefix string) *node { search := prefix268:4modifies-parameter
tree.go:268:4
} child.prefix = segRexpat child.rex = rexmiddleware/compress.go1
83:22nested-structs
middleware/compress.go:83:22
for _, t := range defaultCompressibleContentTypes { allowedTypes[t] = struct{}{} }middleware/request_id.go1
28:5no-package-var
middleware/request_id.go:28:5
var prefix stringvar reqid atomic.Uint64middleware/page_route.go1
1:9package-comments
middleware/page_route.go:1:9
package middlewaremiddleware/client_ip_test.go1
277:35test-parallelism
middleware/client_ip_test.go:277:35
func TestClientIPLastWriteWins(t *testing.T) { t.Run("later_overrides_earlier", func(t *testing.T) { got := runChain(t,mux_test.go1
355:46unchecked-type-assertion
mux_test.go:355:46
sr1.NotFound(func(w http.ResponseWriter, r *http.Request) { chkMw2 := r.Context().Value(ctxKey{"mw2"}).(string) w.WriteHeader(404)middleware/client_ip_test.go1
220:67add-constant
middleware/client_ip_test.go:220:67
// Normalization at the chosen position: v4-mapped IPv6 folds to v4, zone stripped. {"v4_mapped_at_position_folded", 1, []string{"::ffff:1.2.3.4"}, "1.2.3.4"}, {"zone_stripped_at_position", 1, []string{"2001:db8::1%eth0"}, "2001:db8::1"},mux.go1
447:16cognitive-complexity
mux.go:447:16
// the matching handler for a particular http method.func (mx *Mux) routeHTTP(w http.ResponseWriter, r *http.Request) { // Grab the route context objectmiddleware/realip_test.go1
54:4discarded-error-result
middleware/realip_test.go:54:4
realIP = r.RemoteAddr w.Write([]byte("Hello World")) })middleware/sunset.go1
8:1doc-comment-period
middleware/sunset.go:8:1
// Sunset set Deprecation/Sunset header to response// This can be used to enable Sunset in a route or a route groupmux_test.go1
725:16error-strings
mux_test.go:725:16
if body != tc.expectedBody || resp.StatusCode != tc.expectedStatus { t.Errorf("Expected status %d and body %s; got status %d and body %s for pattern %s", tc.expectedStatus, tc.expectedBody, resp.StatusCode, body, tc.pattern)middleware/client_ip.go1
204:6exported-declaration-comment
middleware/client_ip.go:204:6
// prefix containment, Is4/Is6, etc. ā without re-parsing the string.func GetClientIPAddr(ctx context.Context) netip.Addr { ip, _ := ctx.Value(clientIPCtxKey).(netip.Addr)middleware/get_head.go1
1:1format
middleware/get_head.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/get_head.go`
tree.go2
409:16function-length
tree.go:409:16
// It's like searching through a multi-dimensional radix trie.func (n *node) findRoute(rctx *Context, method methodTyp, path string) *node { nn := n269:4modifies-parameter
tree.go:269:4
child.prefix = segRexpat child.rex = rex }middleware/compress.go1
269:30nested-structs
middleware/compress.go:269:30
w io.Writer contentTypes map[string]struct{} contentWildcards map[string]struct{}middleware/terminal.go1
14:2no-package-var
middleware/terminal.go:14:2
// Normal colors nBlack = []byte{'\033', '[', '3', '0', 'm'} nRed = []byte{'\033', '[', '3', '1', 'm'}middleware/path_rewrite.go1
1:9package-comments
middleware/path_rewrite.go:1:9
package middlewaremiddleware/client_ip_test.go1
292:53test-parallelism
middleware/client_ip_test.go:292:53
t.Run("earlier_persists_when_later_finds_nothing", func(t *testing.T) { got := runChain(t,mux_test.go1
614:45unchecked-type-assertion
mux_test.go:614:45
r.With(mw1).With(mw2).Get("/inline", func(w http.ResponseWriter, r *http.Request) { v1 := r.Context().Value(ctxKey{"inline1"}).(string) v2 := r.Context().Value(ctxKey{"inline2"}).(string)middleware/client_ip_test.go1
221:45add-constant
middleware/client_ip_test.go:221:45
{"v4_mapped_at_position_folded", 1, []string{"::ffff:1.2.3.4"}, "1.2.3.4"}, {"zone_stripped_at_position", 1, []string{"2001:db8::1%eth0"}, "2001:db8::1"}, }mux_test.go1
16:6cognitive-complexity
mux_test.go:16:6
func TestMuxBasic(t *testing.T) { var count uint64middleware/realip_test.go1
69:12discarded-error-result
middleware/realip_test.go:69:12
func TestXForwardForXRealIPPrecedence(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil) req.Header.Add("X-Forwarded-For", "0.0.0.0")middleware/timeout.go1
9:1doc-comment-period
middleware/timeout.go:9:1
// Timeout is a middleware that cancels ctx after a given timeout and return// a 504 Gateway Timeout error to the client.middleware/compress.go1
42:6exported-declaration-comment
middleware/compress.go:42:6
// Passing a compression level of 5 is sensible valuefunc Compress(level int, types ...string) func(next http.Handler) http.Handler { compressor := NewCompressor(level, types...)middleware/get_head_test.go1
1:1format
middleware/get_head_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/get_head_test.go`
tree_test.go1
10:6function-length
tree_test.go:10:6
func TestTree(t *testing.T) { hStub := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})tree.go1
274:4modifies-parameter
tree.go:274:4
// Route starts with a param child.typ = segTypmiddleware/compress.go1
270:30nested-structs
middleware/compress.go:270:30
contentTypes map[string]struct{} contentWildcards map[string]struct{} encoding stringmiddleware/terminal.go1
15:2no-package-var
middleware/terminal.go:15:2
nBlack = []byte{'\033', '[', '3', '0', 'm'} nRed = []byte{'\033', '[', '3', '1', 'm'} nGreen = []byte{'\033', '[', '3', '2', 'm'}middleware/profiler.go1
3:9package-comments
middleware/profiler.go:3:9
package middlewaremiddleware/client_ip_test.go1
306:55test-parallelism
middleware/client_ip_test.go:306:55
t.Run("earlier_persists_when_later_xff_all_trusted", func(t *testing.T) { got := runChain(t,mux_test.go1
615:45unchecked-type-assertion
mux_test.go:615:45
v1 := r.Context().Value(ctxKey{"inline1"}).(string) v2 := r.Context().Value(ctxKey{"inline2"}).(string) w.Write([]byte(fmt.Sprintf("inline %s %s", v1, v2)))middleware/client_ip_test.go1
227:19add-constant
middleware/client_ip_test.go:227:19
for _, v := range tc.xff { r.Header.Add("X-Forwarded-For", v) }mux_test.go1
431:6cognitive-complexity
mux_test.go:431:6
func TestMuxNestedMethodNotAllowed(t *testing.T) { r := NewRouter()middleware/realip_test.go1
80:3discarded-error-result
middleware/realip_test.go:80:3
realIP = r.RemoteAddr w.Write([]byte("Hello World")) })middleware/url_format.go1
17:1doc-comment-period
middleware/url_format.go:17:1
// URLFormat is a middleware that parses the url extension from a request path and stores it// on the context as a string under the key `middleware.URLFormatCtxKey`. The middleware willmiddleware/compress.go1
65:6exported-declaration-comment
middleware/compress.go:65:6
// The types are the content types that are allowed to be compressed.func NewCompressor(level int, types ...string) *Compressor { // If types are provided, set those as the allowed types. If none aremiddleware/logger.go1
1:1format
middleware/logger.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/logger.go`
tree_test.go1
154:6function-length
tree_test.go:154:6
func TestTreeMoar(t *testing.T) { hStub := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})tree.go1
284:4modifies-parameter
tree.go:284:4
} child.tail = segTail // for params, we set the tailmiddleware/compress_test.go1
52:13nested-structs
middleware/compress_test.go:52:13
tests := []struct { name stringmiddleware/terminal.go1
16:2no-package-var
middleware/terminal.go:16:2
nRed = []byte{'\033', '[', '3', '1', 'm'} nGreen = []byte{'\033', '[', '3', '2', 'm'} nYellow = []byte{'\033', '[', '3', '3', 'm'}middleware/realip.go1
1:9package-comments
middleware/realip.go:1:9
package middlewaremiddleware/client_ip_test.go1
322:6test-parallelism
middleware/client_ip_test.go:322:6
func TestGetClientIPAddr_Unset(t *testing.T) { req := httptest.NewRequest("GET", "/", nil)mux_test.go1
804:63unchecked-type-assertion
mux_test.go:804:63
ctx := r.Context() ctxmwHandlerCount := ctx.Value(ctxKey{"count.ctxmwHandler"}).(uint64) w.Write([]byte(fmt.Sprintf("inits:%d reqs:%d ctxValue:%d", ctxmwInit, handlerCount, ctxmwHandlerCount)))middleware/client_ip_test.go1
254:30add-constant
middleware/client_ip_test.go:254:30
{"ipv6_with_port", "[2001:db8::1]:1234", "2001:db8::1"}, {"bare_ipv4", "192.0.2.1", "192.0.2.1"}, {"empty", "", ""},mux_test.go1
497:6cognitive-complexity
mux_test.go:497:6
func TestMuxComplicatedNotFound(t *testing.T) { decorateRouter := func(r *Mux) {middleware/realip_test.go1
94:12discarded-error-result
middleware/realip_test.go:94:12
func TestInvalidIP(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil) req.Header.Add("X-Real-IP", "100.100.100.1000")tree.go1
67:1doc-comment-period
tree.go:67:1
// RegisterMethod adds support for custom HTTP method handlers, available// via Router#Method and Router#MethodFuncmiddleware/compress.go1
149:22exported-declaration-comment
middleware/compress.go:149:22
// })func (c *Compressor) SetEncoder(encoding string, fn EncoderFunc) { encoding = strings.ToLower(encoding)middleware/logger_test.go1
1:1format
middleware/logger_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/logger_test.go`
tree.go1
305:4modifies-parameter
tree.go:305:4
// starts with a static segment child.typ = ntStatic child.prefix = search[:segStartIdx]middleware/compress_test.go1
113:13nested-structs
middleware/compress_test.go:113:13
func TestCompressorWildcards(t *testing.T) { tests := []struct { name stringmiddleware/terminal.go1
17:2no-package-var
middleware/terminal.go:17:2
nGreen = []byte{'\033', '[', '3', '2', 'm'} nYellow = []byte{'\033', '[', '3', '3', 'm'} nBlue = []byte{'\033', '[', '3', '4', 'm'}middleware/recoverer.go1
1:9package-comments
middleware/recoverer.go:1:9
package middlewaremiddleware/client_ip_test.go1
332:6test-parallelism
middleware/client_ip_test.go:332:6
func TestGetClientIPAddr_RoundTrip(t *testing.T) { var gotStr stringmux_test.go1
1025:9unchecked-type-assertion
mux_test.go:1025:9
r.Route("/hubs", func(r Router) { _ = r.(*Mux) // sr1 r.Route("/{hubID}", func(r Router) {middleware/client_ip_test.go1
255:4add-constant
middleware/client_ip_test.go:255:4
{"bare_ipv4", "192.0.2.1", "192.0.2.1"}, {"empty", "", ""}, {"garbage", "not-an-ip", ""},mux_test.go1
642:6cognitive-complexity
mux_test.go:642:6
func TestMuxHandlePatternValidation(t *testing.T) { testCases := []struct {middleware/realip_test.go1
104:3discarded-error-result
middleware/realip_test.go:104:3
realIP = r.RemoteAddr w.Write([]byte("Hello World")) })tree.go1
793:1doc-comment-period
tree.go:793:1
// Sort the list of nodes by labelfunc (ns nodes) Sort() { sort.Sort(ns); ns.tailSort() }middleware/compress.go1
189:22exported-declaration-comment
middleware/compress.go:189:22
// current Compressor.func (c *Compressor) Handler(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {middleware/middleware.go1
1:1format
middleware/middleware.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/middleware.go`
tree.go1
306:4modifies-parameter
tree.go:306:4
child.typ = ntStatic child.prefix = search[:segStartIdx] child.rex = nilmiddleware/content_charset_test.go1
14:16nested-structs
middleware/content_charset_test.go:14:16
var tests = []struct { name stringmiddleware/terminal.go1
18:2no-package-var
middleware/terminal.go:18:2
nYellow = []byte{'\033', '[', '3', '3', 'm'} nBlue = []byte{'\033', '[', '3', '4', 'm'} nMagenta = []byte{'\033', '[', '3', '5', 'm'}middleware/request_id.go1
1:9package-comments
middleware/request_id.go:1:9
package middlewaremiddleware/client_ip_test.go1
362:6test-parallelism
middleware/client_ip_test.go:362:6
// shapes the application might choose.func TestAdvisory_GHSA_3fxj_6jh8_hvhx(t *testing.T) { // (a) Server directly on the internet: use ClientIPFromRemoteAddr.mux_test.go1
1027:10unchecked-type-assertion
mux_test.go:1027:10
r.Route("/{hubID}", func(r Router) { _ = r.(*Mux) // sr2 r.Get("/", func(w http.ResponseWriter, r *http.Request) {middleware/client_ip_test.go1
296:24add-constant
middleware/client_ip_test.go:296:24
ClientIPFromXFF(), ClientIPFromHeader("CF-Connecting-IP"), // missing ā no-op. },mux_test.go1
885:6cognitive-complexity
mux_test.go:885:6
func TestMuxBig(t *testing.T) { r := bigMux()middleware/recoverer.go1
66:3discarded-error-result
middleware/recoverer.go:66:3
if err == nil { recovererErrorWriter.Write(out) } else {tree.go1
830:1doc-comment-period
tree.go:830:1
// Route describes the details of a routing handler.// Handlers map key is an HTTP methodmiddleware/compress.go1
255:6exported-declaration-comment
middleware/compress.go:255:6
// In case of failure, the function should return nil.type EncoderFunc func(w io.Writer, level int) io.Writermiddleware/middleware_test.go1
1:1format
middleware/middleware_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/middleware_test.go`
tree.go1
307:4modifies-parameter
tree.go:307:4
child.prefix = search[:segStartIdx] child.rex = nilmiddleware/content_encoding.go1
11:38nested-structs
middleware/content_encoding.go:11:38
func AllowContentEncoding(contentEncoding ...string) func(next http.Handler) http.Handler { allowedEncodings := make(map[string]struct{}, len(contentEncoding)) for _, encoding := range contentEncoding {middleware/terminal.go1
19:2no-package-var
middleware/terminal.go:19:2
nBlue = []byte{'\033', '[', '3', '4', 'm'} nMagenta = []byte{'\033', '[', '3', '5', 'm'} nCyan = []byte{'\033', '[', '3', '6', 'm'}middleware/request_size.go1
1:9package-comments
middleware/request_size.go:1:9
package middlewaremiddleware/client_ip_test.go1
365:43test-parallelism
middleware/client_ip_test.go:365:43
// XFF is never consulted; the spoofed admin IP is ignored. t.Run("direct_internet_uses_remoteaddr", func(t *testing.T) { var clientIP stringmux_test.go1
1049:11unchecked-type-assertion
mux_test.go:1049:11
sr3.Route("/{webhookID}", func(r Router) { _ = r.(*Mux) // sr4 r.Get("/", func(w http.ResponseWriter, r *http.Request) {middleware/client_ip_test.go1
301:13add-constant
middleware/client_ip_test.go:301:13
}) if got != "8.8.8.8" { t.Errorf("want 8.8.8.8, got %q", got)mux_test.go1
1177:6cognitive-complexity
mux_test.go:1177:6
func TestMuxSubroutes(t *testing.T) { hHubView1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {middleware/recoverer.go1
69:3discarded-error-result
middleware/recoverer.go:69:3
// print stdlib output as a fallback os.Stderr.Write(debugStack) }middleware/compress.go1
292:35exported-declaration-comment
middleware/compress.go:292:35
func (cw *compressResponseWriter) WriteHeader(code int) { if cw.wroteHeader {middleware/page_route.go1
1:1format
middleware/page_route.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/page_route.go`
tree.go1
384:2modifies-parameter
tree.go:384:2
// Reset the context routing pattern and params rctx.routePattern = "" rctx.routeParams.Keys = rctx.routeParams.Keys[:0]middleware/content_encoding.go1
13:68nested-structs
middleware/content_encoding.go:13:68
for _, encoding := range contentEncoding { allowedEncodings[strings.TrimSpace(strings.ToLower(encoding))] = struct{}{} }middleware/terminal.go1
20:2no-package-var
middleware/terminal.go:20:2
nMagenta = []byte{'\033', '[', '3', '5', 'm'} nCyan = []byte{'\033', '[', '3', '6', 'm'} nWhite = []byte{'\033', '[', '3', '7', 'm'}middleware/route_headers.go1
1:9package-comments
middleware/route_headers.go:1:9
package middlewaremiddleware/client_ip_test.go1
390:33test-parallelism
middleware/client_ip_test.go:390:33
// entry is the genuine attacker IP, never the prepended spoof. t.Run("behind_proxy_uses_xff", func(t *testing.T) { got := run(t, ClientIPFromXFF("10.0.0.0/8"), func(r *http.Request) {mux_test.go1
1065:11unchecked-type-assertion
mux_test.go:1065:11
r.Route("/posts", func(r Router) { _ = r.(*Mux) // sr5 r.Get("/", func(w http.ResponseWriter, r *http.Request) {middleware/client_ip_test.go1
336:27add-constant
middleware/client_ip_test.go:336:27
r := chi.NewRouter() r.Use(ClientIPFromHeader("X-Real-IP")) r.Get("/", func(w http.ResponseWriter, r *http.Request) {mux_test.go1
1336:6cognitive-complexity
mux_test.go:1336:6
func TestServeHTTPExistingContext(t *testing.T) { r := NewRouter()middleware/request_id.go1
54:3discarded-error-result
middleware/request_id.go:54:3
for len(b64) < 10 { rand.Read(buf[:]) b64 = base64.StdEncoding.EncodeToString(buf[:])middleware/compress.go1
339:35exported-declaration-comment
middleware/compress.go:339:35
func (cw *compressResponseWriter) Flush() { if f, ok := cw.writer().(http.Flusher); ok {middleware/realip.go1
1:1format
middleware/realip.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/realip.go`
tree.go1
385:2modifies-parameter
tree.go:385:2
rctx.routePattern = "" rctx.routeParams.Keys = rctx.routeParams.Keys[:0] rctx.routeParams.Values = rctx.routeParams.Values[:0]middleware/content_encoding_test.go1
22:13nested-structs
middleware/content_encoding_test.go:22:13
tests := []struct { name stringmiddleware/terminal.go1
21:2no-package-var
middleware/terminal.go:21:2
nCyan = []byte{'\033', '[', '3', '6', 'm'} nWhite = []byte{'\033', '[', '3', '7', 'm'} // Bright colorsmiddleware/strip.go1
1:9package-comments
middleware/strip.go:1:9
package middlewaremiddleware/client_ip_test.go1
406:6test-parallelism
middleware/client_ip_test.go:406:6
// never mutate r.RemoteAddr.func TestAdvisory_GHSA_9g5q_2w5x_hmxf(t *testing.T) { originalRemoteAddr := "203.0.113.99:1234"mux_test.go1
1077:9unchecked-type-assertion
mux_test.go:1077:9
r.Route("/folders/", func(r Router) { _ = r.(*Mux) // sr6 r.Get("/", func(w http.ResponseWriter, r *http.Request) {middleware/client_ip_test.go1
342:36add-constant
middleware/client_ip_test.go:342:36
req := httptest.NewRequest("GET", "/", nil) req.Header.Set("X-Real-IP", "203.0.113.42")path_value_test.go1
10:6cognitive-complexity
path_value_test.go:10:6
func TestPathValue(t *testing.T) { testCases := []struct {middleware/request_id_test.go1
29:15discarded-error-result
middleware/request_id_test.go:29:15
func() *http.Request { req, _ := http.NewRequest("GET", "/", nil) req.Header.Add("X-Request-Id", "req-123456")middleware/compress.go1
355:35exported-declaration-comment
middleware/compress.go:355:35
func (cw *compressResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { if hj, ok := cw.writer().(http.Hijacker); ok {middleware/recoverer.go1
1:1format
middleware/recoverer.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/recoverer.go`
tree.go1
386:2modifies-parameter
tree.go:386:2
rctx.routeParams.Keys = rctx.routeParams.Keys[:0] rctx.routeParams.Values = rctx.routeParams.Values[:0]middleware/content_type.go1
21:41nested-structs
middleware/content_type.go:21:41
func AllowContentType(contentTypes ...string) func(http.Handler) http.Handler { allowedContentTypes := make(map[string]struct{}, len(contentTypes)) for _, ctype := range contentTypes {middleware/terminal.go1
23:2no-package-var
middleware/terminal.go:23:2
// Bright colors bBlack = []byte{'\033', '[', '3', '0', ';', '1', 'm'} bRed = []byte{'\033', '[', '3', '1', ';', '1', 'm'}middleware/sunset.go1
1:9package-comments
middleware/sunset.go:1:9
package middlewaremiddleware/client_ip_test.go1
440:6test-parallelism
middleware/client_ip_test.go:440:6
// rightmost-untrusted for XFF.func TestAdvisory_GHSA_rjr7_jggh_pgcp(t *testing.T) { // Attacker sends "X-Forwarded-For: 127.0.0.1" to spoof loopback. In a realmux_test.go1
1211:8unchecked-type-assertion
mux_test.go:1211:8
r.Route("/accounts/{accountID}", func(r Router) { _ = r.(*Mux) // sr2 // r.Get("/", hAccountView1)middleware/client_ip_test.go1
349:47add-constant
middleware/client_ip_test.go:349:47
} if !gotAddr.IsValid() || gotAddr.String() != "203.0.113.42" { t.Errorf("GetClientIPAddr: want 203.0.113.42, got %v", gotAddr)tree.go1
147:16cognitive-complexity
tree.go:147:16
func (n *node) InsertRoute(method methodTyp, pattern string, handler http.Handler) *node { var parent *nodemiddleware/request_id_test.go1
39:15discarded-error-result
middleware/request_id_test.go:39:15
func() *http.Request { req, _ := http.NewRequest("GET", "/", nil) req.Header.Add("X-Trace-Id", "trace:abc123")middleware/compress.go1
362:35exported-declaration-comment
middleware/compress.go:362:35
func (cw *compressResponseWriter) Push(target string, opts *http.PushOptions) error { if ps, ok := cw.writer().(http.Pusher); ok {middleware/recoverer_test.go1
1:1format
middleware/recoverer_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/recoverer_test.go`
tree.go1
395:2modifies-parameter
tree.go:395:2
// Record the routing params in the request lifecycle rctx.URLParams.Keys = append(rctx.URLParams.Keys, rctx.routeParams.Keys...) rctx.URLParams.Values = append(rctx.URLParams.Values, rctx.routeParams.Values...)middleware/content_type.go1
23:68nested-structs
middleware/content_type.go:23:68
for _, ctype := range contentTypes { allowedContentTypes[strings.TrimSpace(strings.ToLower(ctype))] = struct{}{} }middleware/terminal.go1
24:2no-package-var
middleware/terminal.go:24:2
bBlack = []byte{'\033', '[', '3', '0', ';', '1', 'm'} bRed = []byte{'\033', '[', '3', '1', ';', '1', 'm'} bGreen = []byte{'\033', '[', '3', '2', ';', '1', 'm'}middleware/supress_notfound.go1
1:9package-comments
middleware/supress_notfound.go:1:9
package middlewaremiddleware/client_ip_test.go1
444:39test-parallelism
middleware/client_ip_test.go:444:39
// rightmost-untrusted entry is never the loopback spoof. t.Run("xff_loopback_spoof_rejected", func(t *testing.T) { got := run(t, ClientIPFromXFF("10.0.0.0/8"), func(r *http.Request) {mux_test.go1
2009:47unchecked-type-assertion
mux_test.go:2009:47
r.Get("/", func(w http.ResponseWriter, r *http.Request) { baseYes := r.Context().Value(ctxKey{"base"}).(string) if _, ok := r.Context().Value(http.ServerContextKey).(*http.Server); !ok {middleware/client_ip_test.go1
373:30add-constant
middleware/client_ip_test.go:373:30
req := httptest.NewRequest("GET", "/admin", nil) req.RemoteAddr = "99.99.99.99:1234"tree.go1
243:16cognitive-complexity
tree.go:243:16
// pattern segment is added to the url pattern tree as individual nodes, depending on type.func (n *node) addChild(child *node, prefix string) *node { search := prefixmiddleware/request_id_test.go1
63:4discarded-error-result
middleware/request_id_test.go:63:4
w.Write([]byte(response)) })middleware/compress.go1
369:35exported-declaration-comment
middleware/compress.go:369:35
func (cw *compressResponseWriter) Close() error { if c, ok := cw.writer().(io.WriteCloser); ok {middleware/request_id.go1
1:1format
middleware/request_id.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/request_id.go`
tree.go1
396:2modifies-parameter
tree.go:396:2
rctx.URLParams.Keys = append(rctx.URLParams.Keys, rctx.routeParams.Keys...) rctx.URLParams.Values = append(rctx.URLParams.Values, rctx.routeParams.Values...)middleware/content_type_test.go1
15:16nested-structs
middleware/content_type_test.go:15:16
var tests = []struct { name stringmiddleware/terminal.go2
25:2no-package-var
middleware/terminal.go:25:2
bRed = []byte{'\033', '[', '3', '1', ';', '1', 'm'} bGreen = []byte{'\033', '[', '3', '2', ';', '1', 'm'} bYellow = []byte{'\033', '[', '3', '3', ';', '1', 'm'}1:9package-comments
middleware/terminal.go:1:9
package middlewaremiddleware/client_ip_test.go2
458:40test-parallelism
middleware/client_ip_test.go:458:40
// into. Attacker-supplied True-Client-IP / X-Forwarded-For are ignored. t.Run("only_opted_in_header_is_read", func(t *testing.T) { got := run(t, ClientIPFromHeader("X-Real-IP"), func(r *http.Request) {445:33add-constant
middleware/client_ip_test.go:445:33
t.Run("xff_loopback_spoof_rejected", func(t *testing.T) { got := run(t, ClientIPFromXFF("10.0.0.0/8"), func(r *http.Request) { r.Header.Set("X-Forwarded-For", "127.0.0.1, 99.99.99.99")tree.go1
409:16cognitive-complexity
tree.go:409:16
// It's like searching through a multi-dimensional radix trie.func (n *node) findRoute(rctx *Context, method methodTyp, path string) *node { nn := nmiddleware/strip_test.go1
22:3discarded-error-result
middleware/strip_test.go:22:3
w.WriteHeader(404) w.Write([]byte("nothing here")) })middleware/content_charset.go1
11:6exported-declaration-comment
middleware/content_charset.go:11:6
// An empty charset will allow requests with no Content-Type header or no specified charset.func ContentCharset(charsets ...string) func(next http.Handler) http.Handler { for i, c := range charsets {middleware/request_id_test.go1
1:1format
middleware/request_id_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/request_id_test.go`
tree.go1
400:3modifies-parameter
tree.go:400:3
if rn.endpoints[method].pattern != "" { rctx.routePattern = rn.endpoints[method].pattern rctx.RoutePatterns = append(rctx.RoutePatterns, rctx.routePattern)middleware/request_id_test.go1
21:22nested-structs
middleware/request_id_test.go:21:22
func TestRequestID(t *testing.T) { tests := map[string]struct { requestIDHeader stringmiddleware/terminal.go1
26:2no-package-var
middleware/terminal.go:26:2
bGreen = []byte{'\033', '[', '3', '2', ';', '1', 'm'} bYellow = []byte{'\033', '[', '3', '3', ';', '1', 'm'} bBlue = []byte{'\033', '[', '3', '4', ';', '1', 'm'}middleware/throttle.go1
1:9package-comments
middleware/throttle.go:1:9
package middlewaremiddleware/client_ip_test.go2
476:6test-parallelism
middleware/client_ip_test.go:476:6
// See https://adam-p.ca/blog/2022/03/x-forwarded-for/ "Multiple headers".func TestXFF_MultipleHeadersMerged(t *testing.T) { // Attacker sends two XFF headers; the trusted proxy appends to the second451:13add-constant
middleware/client_ip_test.go:451:13
} if got != "99.99.99.99" { t.Errorf("want 99.99.99.99 (rightmost-untrusted), got %q", got)tree.go1
554:16cognitive-complexity
tree.go:554:16
func (n *node) findEdge(ntyp nodeTyp, label byte) *node { nds := n.children[ntyp]middleware/strip_test.go1
26:3discarded-error-result
middleware/strip_test.go:26:3
r.Get("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("root")) })middleware/content_encoding.go1
10:6exported-declaration-comment
middleware/content_encoding.go:10:6
// with a 415 Unsupported Media Type status.func AllowContentEncoding(contentEncoding ...string) func(next http.Handler) http.Handler { allowedEncodings := make(map[string]struct{}, len(contentEncoding))middleware/request_size.go1
1:1format
middleware/request_size.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/request_size.go`
tree.go1
401:3modifies-parameter
tree.go:401:3
rctx.routePattern = rn.endpoints[method].pattern rctx.RoutePatterns = append(rctx.RoutePatterns, rctx.routePattern) }middleware/route_headers_test.go1
188:13nested-structs
middleware/route_headers_test.go:188:13
func TestPattern(t *testing.T) { tests := []struct { pattern stringmiddleware/terminal.go1
27:2no-package-var
middleware/terminal.go:27:2
bYellow = []byte{'\033', '[', '3', '3', ';', '1', 'm'} bBlue = []byte{'\033', '[', '3', '4', ';', '1', 'm'} bMagenta = []byte{'\033', '[', '3', '5', ';', '1', 'm'}middleware/timeout.go1
1:9package-comments
middleware/timeout.go:1:9
package middlewaremiddleware/client_ip_test.go2
503:6test-parallelism
middleware/client_ip_test.go:503:6
// came from hops further from us and are less trustworthy by definition.func TestClientIPFromHeader_MultiValueLastWins(t *testing.T) { tt := []struct {600:32add-constant
middleware/client_ip_test.go:600:32
func TestXFF_IPv6ZoneIDBypassesTrustedV6Prefix(t *testing.T) { got := run(t, ClientIPFromXFF("2606:4700::/32"), func(r *http.Request) { r.Header.Set("X-Forwarded-For", "2606:4700::1%attacker, 2606:4700::5")tree.go1
586:16cognitive-complexity
tree.go:586:16
func (n *node) findPattern(pattern string) bool { nn := nmiddleware/strip_test.go1
32:4discarded-error-result
middleware/strip_test.go:32:4
accountID := chi.URLParam(r, "accountID") w.Write([]byte(accountID)) })middleware/content_type.go1
20:6exported-declaration-comment
middleware/content_type.go:20:6
// with a 415 Unsupported Media Type status.func AllowContentType(contentTypes ...string) func(http.Handler) http.Handler { allowedContentTypes := make(map[string]struct{}, len(contentTypes))middleware/route_headers.go1
1:1format
middleware/route_headers.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/route_headers.go`
tree.go1
466:5modifies-parameter
tree.go:466:5
prevlen := len(rctx.routeParams.Values) rctx.routeParams.Values = append(rctx.routeParams.Values, xsearch[:p]) xsearch = xsearch[p:]middleware/strip_test.go1
279:13nested-structs
middleware/strip_test.go:279:13
tests := []struct { name stringmiddleware/terminal.go1
28:2no-package-var
middleware/terminal.go:28:2
bBlue = []byte{'\033', '[', '3', '4', ';', '1', 'm'} bMagenta = []byte{'\033', '[', '3', '5', ';', '1', 'm'} bCyan = []byte{'\033', '[', '3', '6', ';', '1', 'm'}middleware/url_format.go1
1:9package-comments
middleware/url_format.go:1:9
package middlewaremiddleware/client_ip_test.go2
530:18test-parallelism
middleware/client_ip_test.go:530:18
for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { got := run(t, ClientIPFromHeader("X-Real-IP"), func(r *http.Request) {684:23add-constant
middleware/client_ip_test.go:684:23
prefixes: []string{"10.0.0.0/8"}, xff: []string{"garbage", "203.0.113.7, 10.0.0.1"}, out: "203.0.113.7",tree.go1
628:16cognitive-complexity
tree.go:628:16
func (n *node) routes() []Route { rts := []Route{}middleware/strip_test.go1
61:3discarded-error-result
middleware/strip_test.go:61:3
w.WriteHeader(404) w.Write([]byte("nothing here")) })middleware/heartbeat.go1
12:6exported-declaration-comment
middleware/heartbeat.go:12:6
// to place this above ACL middlewares as well.func Heartbeat(endpoint string) func(http.Handler) http.Handler { f := func(h http.Handler) http.Handler {middleware/route_headers_test.go1
1:1format
middleware/route_headers_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/route_headers_test.go`
tree.go1
473:8modifies-parameter
tree.go:473:8
if h != nil && h.handler != nil { rctx.routeParams.Keys = append(rctx.routeParams.Keys, h.paramKeys...) return xnmiddleware/throttle_test.go1
267:20nested-structs
middleware/throttle_test.go:267:20
wait := make(chan struct{})middleware/terminal.go1
29:2no-package-var
middleware/terminal.go:29:2
bMagenta = []byte{'\033', '[', '3', '5', ';', '1', 'm'} bCyan = []byte{'\033', '[', '3', '6', ';', '1', 'm'} bWhite = []byte{'\033', '[', '3', '7', ';', '1', 'm'}middleware/value.go1
1:9package-comments
middleware/value.go:1:9
package middlewaremiddleware/client_ip_test.go2
557:6test-parallelism
middleware/client_ip_test.go:557:6
// GetClientIP.func TestXFF_V4MappedIPv6BypassesTrustedV4Prefix(t *testing.T) { tt := []struct {685:14add-constant
middleware/client_ip_test.go:685:14
xff: []string{"garbage", "203.0.113.7, 10.0.0.1"}, out: "203.0.113.7", },tree.go1
695:6cognitive-complexity
tree.go:695:6
// node type, param key, regexp string, param tail byte, param starting index, param ending indexfunc patNextSegment(pattern string) (nodeTyp, string, string, byte, int, int) { ps := strings.Index(pattern, "{")middleware/strip_test.go1
65:3discarded-error-result
middleware/strip_test.go:65:3
r.Get("/hi", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("hi")) })middleware/logger.go1
20:2exported-declaration-comment
middleware/logger.go:20:2
// logging configurations. DefaultLogger func(next http.Handler) http.Handler)middleware/strip_test.go1
1:1format
middleware/strip_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/strip_test.go`
tree.go1
481:8modifies-parameter
tree.go:481:8
} rctx.methodsAllowed = append(rctx.methodsAllowed, endpoints) }mux_test.go1
643:17nested-structs
mux_test.go:643:17
func TestMuxHandlePatternValidation(t *testing.T) { testCases := []struct { name stringmiddleware/terminal.go1
30:2no-package-var
middleware/terminal.go:30:2
bCyan = []byte{'\033', '[', '3', '6', ';', '1', 'm'} bWhite = []byte{'\033', '[', '3', '7', ';', '1', 'm'}middleware/wrap_writer.go1
1:9package-comments
middleware/wrap_writer.go:1:9
package middlewaremiddleware/client_ip_test.go1
578:18test-parallelism
middleware/client_ip_test.go:578:18
for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { got := run(t, ClientIPFromXFF(tc.prefixes...), func(r *http.Request) {middleware/compress_test.go1
40:34add-constant
middleware/compress_test.go:40:34
r.Get("/getcss", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") w.Write([]byte("textstring"))tree.go1
763:6cognitive-complexity
tree.go:763:6
func patParamKeys(pattern string) []string { pat := patternmiddleware/strip_test.go1
71:4discarded-error-result
middleware/strip_test.go:71:4
r.Get("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("accounts index")) })middleware/logger.go1
39:6exported-declaration-comment
middleware/logger.go:39:6
// r.Get("/", handler)func Logger(next http.Handler) http.Handler { return DefaultLogger(next)middleware/sunset.go1
1:1format
middleware/sunset.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/sunset.go`
tree.go1
486:7modifies-parameter
tree.go:486:7
// supported method rctx.methodNotAllowed = true }mux_test.go1
1348:17nested-structs
mux_test.go:1348:17
testcases := []struct { Ctx context.Contextmiddleware/terminal.go1
32:2no-package-var
middleware/terminal.go:32:2
reset = []byte{'\033', '[', '0', 'm'})mux.go1
1:9package-comments
mux.go:1:9
package chimiddleware/client_ip_test.go1
599:6test-parallelism
middleware/client_ip_test.go:599:6
// and skipped.func TestXFF_IPv6ZoneIDBypassesTrustedV6Prefix(t *testing.T) { got := run(t, ClientIPFromXFF("2606:4700::/32"), func(r *http.Request) {middleware/compress_test.go1
45:18add-constant
middleware/compress_test.go:45:18
r.Get("/getplain", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") w.Write([]byte("textstring"))tree.go1
846:6cognitive-complexity
tree.go:846:6
func walk(r Routes, walkFn WalkFunc, parentRoute string, parentMw ...func(http.Handler) http.Handler) error { for _, route := range r.Routes() {middleware/strip_test.go1
75:4discarded-error-result
middleware/strip_test.go:75:4
accountID := chi.URLParam(r, "accountID") w.Write([]byte(accountID)) })middleware/logger.go1
63:6exported-declaration-comment
middleware/logger.go:63:6
// See DefaultLogFormatter for an example implementation.type LogFormatter interface { NewLogEntry(r *http.Request) LogEntrymiddleware/sunset_test.go1
1:1format
middleware/sunset_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/sunset_test.go`
tree.go1
497:5modifies-parameter
tree.go:497:5
// not found on this branch, reset vars rctx.routeParams.Values = rctx.routeParams.Values[:prevlen] xsearch = searchpath_value_test.go1
11:17nested-structs
path_value_test.go:11:17
func TestPathValue(t *testing.T) { testCases := []struct { name stringmiddleware/terminal.go1
35:5no-package-var
middleware/terminal.go:35:5
var IsTTY booltree.go1
1:9package-comments
tree.go:1:9
package chimiddleware/client_ip_test.go1
615:6test-parallelism
middleware/client_ip_test.go:615:6
// calls Unmap() before storing.func TestClientIPFromRemoteAddr_V4MappedIsUnmapped(t *testing.T) { tt := []struct {middleware/compress_test.go1
46:18add-constant
middleware/compress_test.go:46:18
w.Header().Set("Content-Type", "text/html") w.Write([]byte("textstring")) })tree_test.go1
10:6cognitive-complexity
tree_test.go:10:6
func TestTree(t *testing.T) { hStub := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})middleware/strip_test.go1
111:3discarded-error-result
middleware/strip_test.go:111:3
w.WriteHeader(404) w.Write([]byte("nothing here")) })middleware/logger.go1
69:6exported-declaration-comment
middleware/logger.go:69:6
// See defaultLogEntry for an example implementation.type LogEntry interface { Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{})middleware/supress_notfound.go1
1:1format
middleware/supress_notfound.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/supress_notfound.go`
tree.go1
501:4modifies-parameter
tree.go:501:4
rctx.routeParams.Values = append(rctx.routeParams.Values, "")pattern_test.go1
10:17nested-structs
pattern_test.go:10:17
func TestPattern(t *testing.T) { testCases := []struct { name stringmiddleware/throttle.go1
16:2no-package-var
middleware/throttle.go:16:2
var ( defaultBacklogTimeout = time.Second * 60)middleware/client_ip_test.go1
625:18test-parallelism
middleware/client_ip_test.go:625:18
for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { got := run(t, ClientIPFromRemoteAddr, func(r *http.Request) {middleware/compress_test.go1
72:23add-constant
middleware/compress_test.go:72:23
name: "gzip is only encoding", path: "/gethtml", acceptedEncodings: []string{"gzip"},tree_test.go1
154:6cognitive-complexity
tree_test.go:154:6
func TestTreeMoar(t *testing.T) { hStub := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})middleware/strip_test.go1
115:3discarded-error-result
middleware/strip_test.go:115:3
r.Get("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("root")) })middleware/logger.go1
168:27exported-declaration-comment
middleware/logger.go:168:27
func (l *defaultLogEntry) Panic(v interface{}, stack []byte) { printPrettyStack(v, l.useColor)middleware/terminal.go1
1:1format
middleware/terminal.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/terminal.go`
tree.go1
505:4modifies-parameter
tree.go:505:4
// catch-all nodes rctx.routeParams.Values = append(rctx.routeParams.Values, search) xn = nds[0]tree_test.go1
80:13nested-structs
tree_test.go:80:13
tests := []struct { r string // input request pathmiddleware/throttle_test.go1
15:5no-package-var
middleware/throttle_test.go:15:5
var testContent = []byte("Hello world!")middleware/client_ip_test.go1
646:6test-parallelism
middleware/client_ip_test.go:646:6
// by trim before parsing, and do not trip fail-closed.func TestXFF_FailClosedOnUnparseable(t *testing.T) { tt := []struct {middleware/compress_test.go1
79:32add-constant
middleware/compress_test.go:79:32
path: "/getcss", acceptedEncodings: []string{"gzip", "deflate"}, expectedEncoding: "gzip",tree_test.go1
270:6cognitive-complexity
tree_test.go:270:6
func TestTreeRegexp(t *testing.T) { hStub1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})middleware/strip_test.go1
121:4discarded-error-result
middleware/strip_test.go:121:4
accountID := chi.URLParam(r, "accountID") w.Write([]byte(accountID)) })middleware/logger_test.go1
17:28exported-declaration-comment
middleware/logger_test.go:17:28
func (cw testLoggerWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { return nil, nil, nilmiddleware/throttle.go1
1:1format
middleware/throttle.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/throttle.go`
tree.go1
519:6modifies-parameter
tree.go:519:6
if h != nil && h.handler != nil { rctx.routeParams.Keys = append(rctx.routeParams.Keys, h.paramKeys...) return xntree_test.go1
204:13nested-structs
tree_test.go:204:13
tests := []struct { h http.Handlermiddleware/url_format.go1
14:2no-package-var
middleware/url_format.go:14:2
// for a request. URLFormatCtxKey = &contextKey{"URLFormat"})middleware/client_ip_test.go1
689:18test-parallelism
middleware/client_ip_test.go:689:18
for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { got := run(t, ClientIPFromXFF(tc.prefixes...), func(r *http.Request) {middleware/compress_test.go1
84:23add-constant
middleware/compress_test.go:84:23
name: "deflate is used", path: "/getcss", acceptedEncodings: []string{"deflate"},tree_test.go1
336:6cognitive-complexity
tree_test.go:336:6
func TestTreeRegexpRecursive(t *testing.T) { hStub1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})middleware/strip_test.go1
207:3discarded-error-result
middleware/strip_test.go:207:3
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("root")) })middleware/maybe.go1
8:6exported-declaration-comment
middleware/maybe.go:8:6
// a request does not satisfy the maybeFn logic.func Maybe(mw func(http.Handler) http.Handler, maybeFn func(r *http.Request) bool) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler {middleware/throttle_test.go1
1:1format
middleware/throttle_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/throttle_test.go`
tree.go1
527:6modifies-parameter
tree.go:527:6
} rctx.methodsAllowed = append(rctx.methodsAllowed, endpoints) }tree_test.go1
294:13nested-structs
tree_test.go:294:13
tests := []struct { r string // input request pathtree.go1
33:5no-package-var
tree.go:33:5
var mALL = mCONNECT | mDELETE | mGET | mHEAD | mOPTIONS | mPATCH | mPOST | mPUT | mQUERY | mTRACEmiddleware/compress_test.go2
16:6test-parallelism
middleware/compress_test.go:16:6
func TestCompressor(t *testing.T) { r := chi.NewRouter()86:23add-constant
middleware/compress_test.go:86:23
acceptedEncodings: []string{"deflate"}, expectedEncoding: "deflate", },tree_test.go1
447:6cognitive-complexity
tree_test.go:447:6
func debugPrintTree(parent int, i int, n *node, label byte) bool { numEdges := 0middleware/strip_test.go1
211:3discarded-error-result
middleware/strip_test.go:211:3
r.HandleFunc("/accounts", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("accounts")) })middleware/nocache.go1
40:6exported-declaration-comment
middleware/nocache.go:40:6
// Pragma: no-cache (for HTTP/1.0 proxies/clients)func NoCache(h http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) {middleware/url_format.go1
1:1format
middleware/url_format.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/url_format.go`
tree.go1
532:5modifies-parameter
tree.go:532:5
// supported method rctx.methodNotAllowed = true }tree_test.go1
350:13nested-structs
tree_test.go:350:13
tests := []struct { r string // input request pathtree.go1
41:5no-package-var
tree.go:41:5
var methodMap = map[string]methodTyp{ http.MethodConnect: mCONNECT,middleware/compress_test.go1
98:18test-parallelism
middleware/compress_test.go:98:18
for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { resp, respString := testRequestWithAcceptedEncodings(t, ts, "GET", tc.path, tc.acceptedEncodings...)middleware/content_charset_test.go1
124:69add-constant
middleware/content_charset_test.go:124:69
if !contentEncoding("text/xml; charset=UTF-8", []string{"latin-1", "utf-8"}...) { t.Error("Want true, got false")middleware/strip_test.go1
215:3discarded-error-result
middleware/strip_test.go:215:3
r.HandleFunc("/accounts/admin", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("admin")) })middleware/page_route.go1
10:6exported-declaration-comment
middleware/page_route.go:10:6
// at the middleware stack level.func PageRoute(path string, handler http.Handler) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler {middleware/url_format_test.go1
1:1format
middleware/url_format_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/url_format_test.go`
tree.go1
545:5modifies-parameter
tree.go:545:5
if len(rctx.routeParams.Values) > 0 { rctx.routeParams.Values = rctx.routeParams.Values[:len(rctx.routeParams.Values)-1] }tree_test.go1
396:13nested-structs
tree_test.go:396:13
tests := []struct { expectedHandler http.Handlertree.go1
54:5no-package-var
tree.go:54:5
var reverseMethodMap = map[methodTyp]string{ mCONNECT: http.MethodConnect,middleware/compress_test.go1
112:6test-parallelism
middleware/compress_test.go:112:6
func TestCompressorWildcards(t *testing.T) { tests := []struct {middleware/content_encoding_test.go1
44:29add-constant
middleware/content_encoding_test.go:44:29
name: "Support for gzip and deflate encoding", encodings: []string{"gzip", "deflate"}, expectedStatus: 200,middleware/strip_test.go1
247:3discarded-error-result
middleware/strip_test.go:247:3
r.Get("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("api root")) })middleware/profiler.go1
22:6exported-declaration-comment
middleware/profiler.go:22:6
// }func Profiler() http.Handler { r := chi.NewRouter()middleware/wrap_writer.go1
1:1format
middleware/wrap_writer.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/wrap_writer.go`
tree_test.go2
463:2modifies-parameter
tree_test.go:463:2
} parent = i for _, nds := range n.children {529:13nested-structs
tree_test.go:529:13
tests := []struct { name stringmiddleware/compress_test.go1
152:18test-parallelism
middleware/compress_test.go:152:18
for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { defer func() {middleware/content_encoding_test.go1
49:29add-constant
middleware/content_encoding_test.go:49:29
name: "Support for deflate and gzip encoding", encodings: []string{"deflate", "gzip"}, expectedStatus: 200,middleware/strip_test.go1
251:3discarded-error-result
middleware/strip_test.go:251:3
r.Get("/accounts", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("api accounts")) })middleware/realip.go1
28:6exported-declaration-comment
middleware/realip.go:28:6
// These never mutate r.RemoteAddr.func RealIP(h http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) {middleware/wrap_writer_test.go1
1:1format
middleware/wrap_writer_test.go:1:1
package middleware- Fix (safe): run `strider fmt middleware/wrap_writer_test.go`
tree_test.go1
466:4modifies-parameter
tree_test.go:466:4
for _, e := range nds { i++ if debugPrintTree(parent, i, e, e.label) {middleware/get_head_test.go2
11:6test-parallelism
middleware/get_head_test.go:11:6
func TestGetHead(t *testing.T) { r := chi.NewRouter()30:9add-constant
middleware/get_head_test.go:30:9
}) r.Get("/{id}", func(w http.ResponseWriter, r *http.Request) { id := chi.URLParam(r, "id")middleware/strip_test.go1
256:3discarded-error-result
middleware/strip_test.go:256:3
accountID := chi.URLParam(r, "accountID") w.Write([]byte(accountID)) })middleware/recoverer.go1
22:6exported-declaration-comment
middleware/recoverer.go:22:6
// Alternatively, look at https://github.com/go-chi/httplog middleware pkgs.func Recoverer(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) {mux.go1
1:1format
mux.go:1:1
package chi- Fix (safe): run `strider fmt mux.go`
middleware/logger_test.go1
21:6test-parallelism
middleware/logger_test.go:21:6
func TestRequestLogger(t *testing.T) { testHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {middleware/get_head_test.go1
43:45add-constant
middleware/get_head_test.go:43:45
} if req, body := testRequest(t, ts, "HEAD", "/hi", nil); body != "" || req.Header.Get("X-Test") != "yes" { t.Fatal(body)middleware/sunset_test.go1
15:13discarded-error-result
middleware/sunset_test.go:15:13
t.Run("Sunset without link", func(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil) w := httptest.NewRecorder()middleware/recoverer.go1
54:6exported-declaration-comment
middleware/recoverer.go:54:6
func PrintPrettyStack(rvr interface{}) { printPrettyStack(rvr, true)mux_test.go1
1:1format
mux_test.go:1:1
package chi- Fix (safe): run `strider fmt mux_test.go`
middleware/logger_test.go1
38:6test-parallelism
middleware/logger_test.go:38:6
func TestRequestLoggerReadFrom(t *testing.T) { data := []byte("file data")middleware/get_head_test.go1
53:35add-constant
middleware/get_head_test.go:53:35
if _, body := testRequest(t, ts, "GET", "/articles/5", nil); body != "article:5" { t.Fatal(body)middleware/sunset_test.go1
28:4discarded-error-result
middleware/sunset_test.go:28:4
deprecation = clonedHeader.Get("Deprecation") w.Write([]byte("I'll be unavailable soon")) })middleware/recoverer_test.go1
17:24exported-declaration-comment
middleware/recoverer_test.go:17:24
func (testPrintLogger) Print(v ...interface{}) {}path_value_test.go1
1:1format
path_value_test.go:1:1
package chi- Fix (safe): run `strider fmt path_value_test.go`
middleware/middleware_test.go1
22:6test-parallelism
middleware/middleware_test.go:22:6
func TestWrapWriterHTTP2(t *testing.T) { handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {middleware/get_head_test.go1
56:37add-constant
middleware/get_head_test.go:56:37
} if req, body := testRequest(t, ts, "HEAD", "/articles/5", nil); body != "" || req.Header.Get("X-Article") != "5" { t.Fatalf("expecting X-Article header '5' but got '%s'", req.Header.Get("X-Article"))middleware/sunset_test.go1
46:13discarded-error-result
middleware/sunset_test.go:46:13
t.Run("Sunset with link", func(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil) w := httptest.NewRecorder()middleware/request_id.go1
25:5exported-declaration-comment
middleware/request_id.go:25:5
// Exported so that it can be changed by developersvar RequestIDHeader = "X-Request-Id"pattern_test.go1
1:1format
pattern_test.go:1:1
package chi- Fix (safe): run `strider fmt pattern_test.go`
middleware/realip_test.go1
11:6test-parallelism
middleware/realip_test.go:11:6
func TestXRealIP(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil)middleware/get_head_test.go1
57:74add-constant
middleware/get_head_test.go:57:74
if req, body := testRequest(t, ts, "HEAD", "/articles/5", nil); body != "" || req.Header.Get("X-Article") != "5" { t.Fatalf("expecting X-Article header '5' but got '%s'", req.Header.Get("X-Article")) }middleware/sunset_test.go1
62:4discarded-error-result
middleware/sunset_test.go:62:4
w.Write([]byte("I'll be unavailable soon")) })middleware/request_id.go1
67:6exported-declaration-comment
middleware/request_id.go:67:6
// counter.func RequestID(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) {tree.go1
1:1format
tree.go:1:1
package chi- Fix (safe): run `strider fmt tree.go`
middleware/realip_test.go1
35:6test-parallelism
middleware/realip_test.go:35:6
func TestXForwardForIP(t *testing.T) { xForwardedForIPs := []string{middleware/get_head_test.go1
63:92add-constant
middleware/get_head_test.go:63:92
} if req, body := testRequest(t, ts, "HEAD", "/users/1", nil); body != "" || req.Header.Get("X-User") != "-" { t.Fatalf("expecting X-User header '-' but got '%s'", req.Header.Get("X-User"))middleware/terminal.go1
57:3discarded-error-result
middleware/terminal.go:57:3
if IsTTY && useColor { w.Write(color) }middleware/request_id.go1
83:6exported-declaration-comment
middleware/request_id.go:83:6
// Returns the empty string if a request ID cannot be found.func GetReqID(ctx context.Context) string { if ctx == nil {tree_test.go1
1:1format
tree_test.go:1:1
package chi- Fix (safe): run `strider fmt tree_test.go`
middleware/realip_test.go1
68:6test-parallelism
middleware/realip_test.go:68:6
func TestXForwardForXRealIPPrecedence(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil)middleware/logger.go1
147:32add-constant
middleware/logger.go:147:32
case status < 400: cW(l.buf, l.useColor, bCyan, "%03d", status) case status < 500:middleware/terminal.go1
61:3discarded-error-result
middleware/terminal.go:61:3
if IsTTY && useColor { w.Write(reset) }middleware/request_size.go1
9:6exported-declaration-comment
middleware/request_size.go:9:6
// number of bytes. It uses MaxBytesReader to do so.func RequestSize(bytes int64) func(http.Handler) http.Handler { f := func(h http.Handler) http.Handler {middleware/realip_test.go1
93:6test-parallelism
middleware/realip_test.go:93:6
func TestInvalidIP(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil)middleware/logger.go1
162:31add-constant
middleware/logger.go:162:31
} else { cW(l.buf, l.useColor, nRed, "%s", elapsed) }middleware/throttle_test.go1
25:3discarded-error-result
middleware/throttle_test.go:25:3
time.Sleep(time.Second * 1) // Expensive operation. w.Write(testContent) })middleware/route_headers.go1
42:6exported-declaration-comment
middleware/route_headers.go:42:6
// Handler)func RouteHeaders() HeaderRouter { return HeaderRouter{}middleware/recoverer_test.go1
78:6test-parallelism
middleware/recoverer_test.go:78:6
func TestRecovererAbortHandler(t *testing.T) { defer func() {middleware/realip_test.go1
37:3add-constant
middleware/realip_test.go:37:3
xForwardedForIPs := []string{ "100.100.100.100", "100.100.100.100, 200.200.200.200",middleware/throttle_test.go1
66:3discarded-error-result
middleware/throttle_test.go:66:3
time.Sleep(time.Second * 5) // Expensive operation. w.Write(testContent) })middleware/route_headers.go1
46:6exported-declaration-comment
middleware/route_headers.go:46:6
type HeaderRouter map[string][]HeaderRoutemiddleware/route_headers_test.go1
10:6test-parallelism
middleware/route_headers_test.go:10:6
func TestRouteHeaders(t *testing.T) { t.Run("empty router should call next handler exactly once", func(t *testing.T) {middleware/realip_test.go1
46:36add-constant
middleware/realip_test.go:46:36
for _, v := range xForwardedForIPs { req, _ := http.NewRequest("GET", "/", nil) req.Header.Add("X-Forwarded-For", v)middleware/throttle_test.go1
98:3discarded-error-result
middleware/throttle_test.go:98:3
time.Sleep(time.Second * 10) // Expensive operation. w.Write(testContent) })middleware/route_headers.go1
48:24exported-declaration-comment
middleware/route_headers.go:48:24
func (hr HeaderRouter) Route(header, match string, middlewareHandler func(next http.Handler) http.Handler) HeaderRouter { header = strings.ToLower(header)middleware/route_headers_test.go1
11:62test-parallelism
middleware/route_headers_test.go:11:62
func TestRouteHeaders(t *testing.T) { t.Run("empty router should call next handler exactly once", func(t *testing.T) { var callCount atomic.Int32middleware/realip_test.go1
69:28add-constant
middleware/realip_test.go:69:28
func TestXForwardForXRealIPPrecedence(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil) req.Header.Add("X-Forwarded-For", "0.0.0.0")middleware/throttle_test.go1
152:3discarded-error-result
middleware/throttle_test.go:152:3
time.Sleep(time.Second * 3) // Expensive operation. w.Write(testContent) })middleware/route_headers.go1
58:24exported-declaration-comment
middleware/route_headers.go:58:24
func (hr HeaderRouter) RouteAny(header string, match []string, middlewareHandler func(next http.Handler) http.Handler) HeaderRouter { header = strings.ToLower(header)middleware/route_headers_test.go1
31:62test-parallelism
middleware/route_headers_test.go:31:62
t.Run("matching header should route to correct middleware", func(t *testing.T) { var matchedRoute stringmiddleware/realip_test.go1
80:18add-constant
middleware/realip_test.go:80:18
realIP = r.RemoteAddr w.Write([]byte("Hello World")) })middleware/throttle_test.go1
215:3discarded-error-result
middleware/throttle_test.go:215:3
w.WriteHeader(http.StatusOK) w.Write([]byte("ok")) })middleware/route_headers.go1
72:24exported-declaration-comment
middleware/route_headers.go:72:24
func (hr HeaderRouter) RouteDefault(handler func(next http.Handler) http.Handler) HeaderRouter { hr["*"] = []HeaderRoute{{Middleware: handler}}middleware/route_headers_test.go1
64:41test-parallelism
middleware/route_headers_test.go:64:41
t.Run("wildcard pattern should match", func(t *testing.T) { var matched boolmiddleware/realip_test.go1
85:11add-constant
middleware/realip_test.go:85:11
if w.Code != 200 { t.Fatal("Response Code should be 200") }middleware/throttle_test.go1
235:14discarded-error-result
middleware/throttle_test.go:235:14
defer wg.Done() res, _ := client.Get(server.URL) resultsCh <- result{status: res.StatusCode, header: res.Header}middleware/route_headers.go1
77:24exported-declaration-comment
middleware/route_headers.go:77:24
func (hr HeaderRouter) Handler(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {middleware/route_headers_test.go1
90:54test-parallelism
middleware/route_headers_test.go:90:54
t.Run("default route should be used when no match", func(t *testing.T) { var usedDefault boolmiddleware/realip_test.go1
95:17add-constant
middleware/realip_test.go:95:17
req, _ := http.NewRequest("GET", "/", nil) req.Header.Add("X-Real-IP", "100.100.100.1000") w := httptest.NewRecorder()middleware/url_format_test.go1
18:3discarded-error-result
middleware/url_format_test.go:18:3
w.WriteHeader(404) w.Write([]byte("nothing here")) })middleware/route_headers.go1
110:6exported-declaration-comment
middleware/route_headers.go:110:6
type HeaderRoute struct { Middleware func(next http.Handler) http.Handlermiddleware/route_headers_test.go1
121:62test-parallelism
middleware/route_headers_test.go:121:62
t.Run("RouteAny should match any of the provided patterns", func(t *testing.T) { var matched boolmiddleware/recoverer.go1
127:32add-constant
middleware/recoverer.go:127:32
if strings.HasPrefix(line, "\t") { return strings.Replace(line, "\t", " ", 1), nil }middleware/url_format_test.go1
24:4discarded-error-result
middleware/url_format_test.go:24:4
articleID := chi.URLParam(r, "articleID") w.Write([]byte(articleID)) })middleware/route_headers.go1
116:22exported-declaration-comment
middleware/route_headers.go:116:22
func (r HeaderRoute) IsMatch(value string) bool { if len(r.MatchAny) > 0 {middleware/route_headers_test.go1
160:60test-parallelism
middleware/route_headers_test.go:160:60
t.Run("no match and no default should call next handler", func(t *testing.T) { var nextCalled boolmiddleware/recoverer.go1
200:28add-constant
middleware/recoverer.go:200:28
} cW(buf, useColor, bWhite, "%s", dir) cW(buf, useColor, fileColor, "%s", file)middleware/url_format_test.go1
31:4discarded-error-result
middleware/url_format_test.go:31:4
articleID := chi.URLParam(r, "articleID") w.Write([]byte(articleID)) })middleware/route_headers.go1
129:6exported-declaration-comment
middleware/route_headers.go:129:6
type Pattern struct { prefix stringmiddleware/route_headers_test.go1
187:6test-parallelism
middleware/route_headers_test.go:187:6
func TestPattern(t *testing.T) { tests := []struct {middleware/recoverer.go1
204:26add-constant
middleware/recoverer.go:204:26
if num == 1 { cW(buf, false, bWhite, "\n") }middleware/url_format_test.go1
59:4discarded-error-result
middleware/url_format_test.go:59:4
articleID := chi.URLParam(r, "articleID") w.Write([]byte(articleID)) })middleware/route_headers.go1
135:6exported-declaration-comment
middleware/route_headers.go:135:6
func NewPattern(value string) Pattern { p := Pattern{}middleware/route_headers_test.go1
205:34test-parallelism
middleware/route_headers_test.go:205:34
for _, tt := range tests { t.Run(tt.pattern+"_"+tt.value, func(t *testing.T) { p := NewPattern(tt.pattern)middleware/recoverer_test.go1
64:8add-constant
middleware/recoverer_test.go:64:8
r.Use(Recoverer) r.Get("/", panickingHandler)mux.go1
530:3discarded-error-result
mux.go:530:3
w.WriteHeader(405) w.Write(nil) }middleware/route_headers.go1
141:18exported-declaration-comment
middleware/route_headers.go:141:18
func (p Pattern) Match(v string) bool { if !p.wildcard {middleware/strip_test.go1
13:6test-parallelism
middleware/strip_test.go:13:6
func TestStripSlashes(t *testing.T) { r := chi.NewRouter()middleware/recoverer_test.go1
95:30add-constant
middleware/recoverer_test.go:95:30
req, err := http.NewRequest("GET", "/", nil) if err != nil {mux_test.go1
55:3discarded-error-result
mux_test.go:55:3
w.WriteHeader(200) w.Write([]byte(fmt.Sprintf("hi %s", user))) }middleware/strip.go1
14:6exported-declaration-comment
middleware/strip.go:14:6
// matches, then it will serve the handler.func StripSlashes(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) {middleware/strip_test.go1
56:6test-parallelism
middleware/strip_test.go:56:6
func TestStripSlashesInRoute(t *testing.T) { r := chi.NewRouter()middleware/request_id_test.go1
59:9add-constant
middleware/request_id_test.go:59:9
r.Get("/", func(w http.ResponseWriter, r *http.Request) { requestID := GetReqID(r.Context())mux_test.go1
60:3discarded-error-result
mux_test.go:60:3
w.WriteHeader(200) w.Write([]byte(".")) }middleware/strip.go1
41:6exported-declaration-comment
middleware/strip.go:41:6
// see https://github.com/go-chi/chi/issues/343func RedirectSlashes(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) {middleware/strip_test.go1
102:6test-parallelism
middleware/strip_test.go:102:6
func TestRedirectSlashes(t *testing.T) { r := chi.NewRouter()middleware/route_headers.go1
137:54add-constant
middleware/route_headers.go:137:54
p := Pattern{} p.prefix, p.suffix, p.wildcard = strings.Cut(value, "*") return pmux_test.go1
75:3discarded-error-result
mux_test.go:75:3
w.WriteHeader(200) w.Write([]byte("ping all")) }middleware/strip.go1
73:6exported-declaration-comment
middleware/strip.go:73:6
// request path before handing the request over to the next handler.func StripPrefix(prefix string) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler {middleware/strip_test.go1
203:6test-parallelism
middleware/strip_test.go:203:6
// In these cases, the routeContext is nilfunc TestStripSlashesWithNilContext(t *testing.T) { r := http.NewServeMux()middleware/route_headers_test.go1
53:14add-constant
middleware/route_headers_test.go:53:14
req := httptest.NewRequest("GET", "/", nil) req.Host = "example.com" req.Header.Set("Host", "example.com")mux_test.go1
80:3discarded-error-result
mux_test.go:80:3
w.WriteHeader(200) w.Write([]byte("ping all2")) }middleware/sunset.go1
11:6exported-declaration-comment
middleware/sunset.go:11:6
// For more: https://www.rfc-editor.org/rfc/rfc8594.htmlfunc Sunset(sunsetAt time.Time, links ...string) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler {middleware/strip_test.go1
241:6test-parallelism
middleware/strip_test.go:241:6
func TestStripPrefix(t *testing.T) { r := chi.NewRouter()middleware/route_headers_test.go1
54:18add-constant
middleware/route_headers_test.go:54:18
req.Host = "example.com" req.Header.Set("Host", "example.com") rec := httptest.NewRecorder()mux_test.go1
86:3discarded-error-result
mux_test.go:86:3
w.WriteHeader(200) w.Write([]byte(fmt.Sprintf("ping one id: %s", idParam))) }middleware/supress_notfound.go1
15:6exported-declaration-comment
middleware/supress_notfound.go:15:6
// example its super annoying to see a bunch of 404's in your logs from bots.func SupressNotFound(router *chi.Mux) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler {middleware/strip_test.go1
276:6test-parallelism
middleware/strip_test.go:276:6
func TestRedirectSlashes_PreventBackslashRelativeOpenRedirect(t *testing.T) { h := RedirectSlashes(http.NotFoundHandler())middleware/route_headers_test.go1
79:30add-constant
middleware/route_headers_test.go:79:30
req := httptest.NewRequest("GET", "/", nil) req.Header.Set("Host", "api.example.com")mux_test.go1
91:3discarded-error-result
mux_test.go:91:3
w.WriteHeader(200) w.Write([]byte("woop." + URLParam(r, "iidd"))) }middleware/terminal.go1
35:5exported-declaration-comment
middleware/terminal.go:35:5
var IsTTY boolmiddleware/strip_test.go1
294:18test-parallelism
middleware/strip_test.go:294:18
for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "http://example.test"+tc.target, nil)middleware/route_headers_test.go1
79:37add-constant
middleware/route_headers_test.go:79:37
req := httptest.NewRequest("GET", "/", nil) req.Header.Set("Host", "api.example.com")mux_test.go1
96:3discarded-error-result
mux_test.go:96:3
w.WriteHeader(200) w.Write([]byte("catchall")) }middleware/throttle.go1
32:6exported-declaration-comment
middleware/throttle.go:32:6
// being processed from the point from where the Throttle middleware is mounted.func Throttle(limit int) func(http.Handler) http.Handler { return ThrottleWithOpts(ThrottleOpts{Limit: limit, BacklogTimeout: defaultBacklogTimeout})middleware/sunset_test.go1
12:6test-parallelism
middleware/sunset_test.go:12:6
func TestSunset(t *testing.T) {middleware/route_headers_test.go1
111:26add-constant
middleware/route_headers_test.go:111:26
req := httptest.NewRequest("GET", "/", nil) req.Header.Set("Host", "other.com") rec := httptest.NewRecorder()mux_test.go1
213:3discarded-error-result
mux_test.go:213:3
v := URLParam(r, "hash") w.Write([]byte(fmt.Sprintf("/%s", v))) })middleware/throttle.go1
39:6exported-declaration-comment
middleware/throttle.go:39:6
// pending requests.func ThrottleBacklog(limit, backlogLimit int, backlogTimeout time.Duration) func(http.Handler) http.Handler { return ThrottleWithOpts(ThrottleOpts{Limit: limit, BacklogLimit: backlogLimit, BacklogTimeout: backlogTimeout})middleware/sunset_test.go1
14:31test-parallelism
middleware/sunset_test.go:14:31
t.Run("Sunset without link", func(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil)middleware/route_headers_test.go1
150:18add-constant
middleware/route_headers_test.go:150:18
req = httptest.NewRequest("POST", "/", nil) req.Header.Set("Content-Type", "application/xml") rec = httptest.NewRecorder()mux_test.go1
219:4discarded-error-result
mux_test.go:219:4
v := URLParam(r, "hash") w.Write([]byte(fmt.Sprintf("/%s/share", v))) })middleware/timeout.go1
32:6exported-declaration-comment
middleware/timeout.go:32:6
// })func Timeout(timeout time.Duration) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler {middleware/sunset_test.go1
45:28test-parallelism
middleware/sunset_test.go:45:28
t.Run("Sunset with link", func(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil)middleware/route_headers_test.go1
196:4add-constant
middleware/route_headers_test.go:196:4
{"*.example.com", "api.example.com", true}, {"*.example.com", "example.com", false}, {"api.*", "api.example.com", true},mux_test.go1
224:4discarded-error-result
mux_test.go:224:4
n := URLParam(r, "network") w.Write([]byte(fmt.Sprintf("/%s/share/%s", v, n))) })middleware/url_format.go1
14:2exported-declaration-comment
middleware/url_format.go:14:2
// for a request. URLFormatCtxKey = &contextKey{"URLFormat"})middleware/throttle_test.go1
17:6test-parallelism
middleware/throttle_test.go:17:6
func TestThrottleBacklog(t *testing.T) { r := chi.NewRouter()middleware/route_headers_test.go1
197:13add-constant
middleware/route_headers_test.go:197:13
{"*.example.com", "example.com", false}, {"api.*", "api.example.com", true}, {"*", "anything", true},mux_test.go1
248:3discarded-error-result
mux_test.go:248:3
r.Get("/hi", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("bye")) })middleware/url_format.go1
46:6exported-declaration-comment
middleware/url_format.go:46:6
// }func URLFormat(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) {middleware/throttle_test.go1
58:6test-parallelism
middleware/throttle_test.go:58:6
func TestThrottleClientTimeout(t *testing.T) { r := chi.NewRouter()middleware/route_headers_test.go1
201:4add-constant
middleware/route_headers_test.go:201:4
{"prefix*suffix", "prefixsuffix", true}, {"prefix*suffix", "wrongmiddlesuffix", false}, }mux_test.go1
252:3discarded-error-result
mux_test.go:252:3
w.WriteHeader(404) w.Write([]byte("nothing here")) })middleware/wrap_writer.go1
15:6exported-declaration-comment
middleware/wrap_writer.go:15:6
// hook into various parts of the response process.func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter { _, fl := w.(http.Flusher)middleware/throttle_test.go1
90:6test-parallelism
middleware/throttle_test.go:90:6
func TestThrottleTriggerGatewayTimeout(t *testing.T) { r := chi.NewRouter()middleware/strip_test.go1
39:42add-constant
middleware/strip_test.go:39:42
if _, resp := testRequest(t, ts, "GET", "/", nil); resp != "root" { t.Fatal(resp)mux_test.go1
289:3discarded-error-result
mux_test.go:289:3
w.WriteHeader(404) w.Write([]byte("nothing here")) })middleware/wrap_writer.go1
48:6exported-declaration-comment
middleware/wrap_writer.go:48:6
// into various parts of the response process.type WrapResponseWriter interface { http.ResponseWritermiddleware/throttle_test.go1
144:6test-parallelism
middleware/throttle_test.go:144:6
func TestThrottleMaximum(t *testing.T) { r := chi.NewRouter()middleware/strip_test.go1
42:62add-constant
middleware/strip_test.go:42:62
} if _, resp := testRequest(t, ts, "GET", "//", nil); resp != "root" { t.Fatal(resp)mux_test.go1
295:3discarded-error-result
mux_test.go:295:3
accountID := URLParam(r, "accountID") w.Write([]byte(accountID)) }middleware/wrap_writer.go1
82:23exported-declaration-comment
middleware/wrap_writer.go:82:23
func (b *basicWriter) WriteHeader(code int) { if code >= 100 && code <= 199 && code != http.StatusSwitchingProtocols {middleware/throttle_test.go1
202:6test-parallelism
middleware/throttle_test.go:202:6
func TestThrottleRetryAfter(t *testing.T) { r := chi.NewRouter()middleware/strip_test.go1
45:35add-constant
middleware/strip_test.go:45:35
} if _, resp := testRequest(t, ts, "GET", "/accounts/admin", nil); resp != "admin" { t.Fatal(resp)mux_test.go1
327:3discarded-error-result
mux_test.go:327:3
r.Get("/hi", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("bye")) })middleware/wrap_writer.go1
122:23exported-declaration-comment
middleware/wrap_writer.go:122:23
func (b *basicWriter) Status() int { return b.codemiddleware/throttle_test.go1
264:6test-parallelism
middleware/throttle_test.go:264:6
func TestThrottleCustomStatusCode(t *testing.T) { const timeout = time.Second * 3middleware/strip_test.go1
61:18add-constant
middleware/strip_test.go:61:18
w.WriteHeader(404) w.Write([]byte("nothing here")) })mux_test.go1
339:3discarded-error-result
mux_test.go:339:3
w.WriteHeader(404) w.Write([]byte(fmt.Sprintf("root 404 %s %s", chkMw, chkWith))) })middleware/wrap_writer.go1
126:23exported-declaration-comment
middleware/wrap_writer.go:126:23
func (b *basicWriter) BytesWritten() int { return b.bytesmiddleware/url_format_test.go1
11:6test-parallelism
middleware/url_format_test.go:11:6
func TestURLFormat(t *testing.T) { r := chi.NewRouter()middleware/strip_test.go1
91:76add-constant
middleware/strip_test.go:91:76
} if _, resp := testRequest(t, ts, "GET", "/accounts/admin/", nil); resp != "accounts index" { t.Fatal(resp)mux_test.go1
345:3discarded-error-result
mux_test.go:345:3
sr1.Get("/sub", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("sub")) })middleware/wrap_writer.go1
130:23exported-declaration-comment
middleware/wrap_writer.go:130:23
func (b *basicWriter) Tee(w io.Writer) { b.tee = wmiddleware/url_format_test.go1
52:6test-parallelism
middleware/url_format_test.go:52:6
func TestURLFormatInSubRouter(t *testing.T) { r := chi.NewRouter()middleware/strip_test.go1
94:81add-constant
middleware/strip_test.go:94:81
} if _, resp := testRequest(t, ts, "GET", "/accounts/admin/query", nil); resp != "admin" { t.Fatal(resp)mux_test.go1
357:4discarded-error-result
mux_test.go:357:4
w.WriteHeader(404) w.Write([]byte(fmt.Sprintf("sub 404 %s", chkMw2))) })middleware/wrap_writer.go1
138:23exported-declaration-comment
middleware/wrap_writer.go:138:23
func (b *basicWriter) Discard() { b.discard = truemiddleware/wrap_writer_test.go1
25:6test-parallelism
middleware/wrap_writer_test.go:25:6
func TestHttpFancyWriterRemembersWroteHeaderWhenFlushed(t *testing.T) { f := &httpFancyWriter{basicWriter: basicWriter{ResponseWriter: httptest.NewRecorder()}}middleware/strip_test.go1
118:10add-constant
middleware/strip_test.go:118:10
r.Route("/accounts/{accountID}", func(r chi.Router) { r.Get("/", func(w http.ResponseWriter, r *http.Request) {mux_test.go1
363:3discarded-error-result
mux_test.go:363:3
sr2.Get("/sub", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("sub2")) })middleware/wrap_writer.go1
147:23exported-declaration-comment
middleware/wrap_writer.go:147:23
func (f *flushWriter) Flush() { f.wroteHeader = truemiddleware/wrap_writer_test.go1
34:6test-parallelism
middleware/wrap_writer_test.go:34:6
func TestHttp2FancyWriterRemembersWroteHeaderWhenFlushed(t *testing.T) { f := &http2FancyWriter{basicWriter{ResponseWriter: httptest.NewRecorder()}}middleware/strip_test.go1
120:33add-constant
middleware/strip_test.go:120:33
r.Get("/", func(w http.ResponseWriter, r *http.Request) { accountID := chi.URLParam(r, "accountID") w.Write([]byte(accountID))mux_test.go1
398:3discarded-error-result
mux_test.go:398:3
r.Get("/hi", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("hi, get")) })middleware/wrap_writer.go1
160:24exported-declaration-comment
middleware/wrap_writer.go:160:24
func (f *hijackWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { hj := f.basicWriter.ResponseWriter.(http.Hijacker)middleware/wrap_writer_test.go1
43:6test-parallelism
middleware/wrap_writer_test.go:43:6
func TestBasicWritesTeesWritesWithoutDiscard(t *testing.T) { // explicitly create the struct instead of NewRecorder to control the value of Codemiddleware/strip_test.go1
137:45add-constant
middleware/strip_test.go:137:45
if resp, body := testRequest(t, ts, "GET", "/accounts/admin", nil); body != "admin" || resp.StatusCode != 200 { t.Fatal(body, resp.StatusCode)mux_test.go1
402:3discarded-error-result
mux_test.go:402:3
r.Head("/hi", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("hi, head")) })middleware/wrap_writer.go1
172:29exported-declaration-comment
middleware/wrap_writer.go:172:29
func (f *flushHijackWriter) Flush() { f.wroteHeader = truemiddleware/wrap_writer_test.go1
63:6test-parallelism
middleware/wrap_writer_test.go:63:6
func TestBasicWriterDiscardsWritesToOriginalResponseWriter(t *testing.T) { t.Run("With Tee", func(t *testing.T) {middleware/strip_test.go1
142:45add-constant
middleware/strip_test.go:142:45
// NOTE: the testRequest client will follow the redirection.. if resp, body := testRequest(t, ts, "GET", "/accounts/admin/", nil); body != "admin" || resp.StatusCode != 200 { t.Fatal(body, resp.StatusCode)mux_test.go1
434:3discarded-error-result
mux_test.go:434:3
r.Get("/root", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("root")) })middleware/wrap_writer.go1
178:29exported-declaration-comment
middleware/wrap_writer.go:178:29
func (f *flushHijackWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { hj := f.basicWriter.ResponseWriter.(http.Hijacker)middleware/wrap_writer_test.go1
64:20test-parallelism
middleware/wrap_writer_test.go:64:20
func TestBasicWriterDiscardsWritesToOriginalResponseWriter(t *testing.T) { t.Run("With Tee", func(t *testing.T) { // explicitly create the struct instead of NewRecorder to control the value of Codemiddleware/strip_test.go1
224:42add-constant
middleware/strip_test.go:224:42
} if _, resp := testRequest(t, ts, "GET", "//", nil); resp != "root" { t.Fatal(resp)mux_test.go1
438:3discarded-error-result
mux_test.go:438:3
w.WriteHeader(405) w.Write([]byte("root 405")) })middleware/wrap_writer.go1
194:27exported-declaration-comment
middleware/wrap_writer.go:194:27
func (f *httpFancyWriter) Flush() { f.wroteHeader = truemiddleware/wrap_writer_test.go1
85:23test-parallelism
middleware/wrap_writer_test.go:85:23
t.Run("Without Tee", func(t *testing.T) { // explicitly create the struct instead of NewRecorder to control the value of Codemiddleware/strip_test.go1
230:70add-constant
middleware/strip_test.go:230:70
} if _, resp := testRequest(t, ts, "GET", "/accounts/", nil); resp != "accounts" { t.Fatal(resp)mux_test.go1
443:3discarded-error-result
mux_test.go:443:3
sr1.Get("/sub1", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("sub1")) })middleware/wrap_writer.go1
200:27exported-declaration-comment
middleware/wrap_writer.go:200:27
func (f *httpFancyWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { hj := f.basicWriter.ResponseWriter.(http.Hijacker)middleware/wrap_writer_test.go1
108:6test-parallelism
middleware/wrap_writer_test.go:108:6
// resulting in double-counting the bytes when a Tee writer was set.func TestHttpFancyWriterReadFromByteCountWithTee(t *testing.T) { original := &httptest.ResponseRecorder{middleware/strip_test.go1
250:8add-constant
middleware/strip_test.go:250:8
r.Get("/accounts", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("api accounts"))mux_test.go1
447:3discarded-error-result
mux_test.go:447:3
w.WriteHeader(405) w.Write([]byte("sub1 405")) })middleware/wrap_writer.go1
205:28exported-declaration-comment
middleware/wrap_writer.go:205:28
func (f *http2FancyWriter) Push(target string, opts *http.PushOptions) error { return f.basicWriter.ResponseWriter.(http.Pusher).Push(target, opts)middleware/wrap_writer_test.go1
131:6test-parallelism
middleware/wrap_writer_test.go:131:6
// ReaderFrom, bypassing the discard flag entirely.func TestHttpFancyWriterReadFromHonorsDiscard(t *testing.T) { original := &readerFromRecorder{&httptest.ResponseRecorder{middleware/strip_test.go1
263:39add-constant
middleware/strip_test.go:263:39
if _, resp := testRequest(t, ts, "GET", "/api/", nil); resp != "api root" { t.Fatalf("got: %q, want: %q", resp, "api root") }mux_test.go1
452:3discarded-error-result
mux_test.go:452:3
sr2.Get("/sub2", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("sub2")) })middleware/wrap_writer.go1
209:27exported-declaration-comment
middleware/wrap_writer.go:209:27
func (f *httpFancyWriter) ReadFrom(r io.Reader) (int64, error) { if f.basicWriter.tee != nil || f.basicWriter.discard {mux_test.go1
16:6test-parallelism
mux_test.go:16:6
func TestMuxBasic(t *testing.T) { var count uint64middleware/strip_test.go1
266:39add-constant
middleware/strip_test.go:266:39
if _, resp := testRequest(t, ts, "GET", "/api/accounts", nil); resp != "api accounts" { t.Fatalf("got: %q, want: %q", resp, "api accounts") }mux_test.go1
457:3discarded-error-result
mux_test.go:457:3
pathVar.Get("/{var}", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("pv")) })middleware/wrap_writer.go1
239:28exported-declaration-comment
middleware/wrap_writer.go:239:28
func (f *http2FancyWriter) Flush() { f.wroteHeader = truemux_test.go1
208:6test-parallelism
mux_test.go:208:6
func TestMuxMounts(t *testing.T) { r := NewRouter()middleware/strip_test.go1
269:12add-constant
middleware/strip_test.go:269:12
if _, resp := testRequest(t, ts, "GET", "/api/accounts/admin", nil); resp != "admin" { t.Fatalf("got: %q, want: %q", resp, "admin") }mux_test.go1
461:3discarded-error-result
mux_test.go:461:3
w.WriteHeader(405) w.Write([]byte("pv 405")) })middleware/wrap_writer_test.go1
21:30exported-declaration-comment
middleware/wrap_writer_test.go:21:30
func (r *readerFromRecorder) ReadFrom(src io.Reader) (int64, error) { return io.Copy(r.ResponseRecorder.Body, src)mux_test.go1
245:6test-parallelism
mux_test.go:245:6
func TestMuxPlain(t *testing.T) { r := NewRouter()middleware/strip_test.go1
306:26add-constant
middleware/strip_test.go:306:26
loc := res.Header.Get("Location") if loc == "" {mux_test.go1
501:4discarded-error-result
mux_test.go:501:4
r.Get("/auth", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("auth get")) })mux.go1
21:6exported-declaration-comment
mux.go:21:6
// into many smaller parts composed of middlewares and end handlers.type Mux struct { // The computed mux handler made of the chained middleware stack andmux_test.go1
266:6test-parallelism
mux_test.go:266:6
func TestMuxEmptyRoutes(t *testing.T) { mux := NewRouter()middleware/sunset_test.go1
46:36add-constant
middleware/sunset_test.go:46:36
t.Run("Sunset with link", func(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil) w := httptest.NewRecorder()mux_test.go1
505:5discarded-error-result
mux_test.go:505:5
r.Get("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("public get")) })mux.go1
52:6exported-declaration-comment
mux.go:52:6
// interface.func NewMux() *Mux { mux := &Mux{tree: &node{}, pool: &sync.Pool{}}mux_test.go1
285:6test-parallelism
mux_test.go:285:6
// for an example of using a middleware to handle trailing slashes.func TestMuxTrailingSlash(t *testing.T) { r := NewRouter()middleware/sunset_test.go1
71:16add-constant
middleware/sunset_test.go:71:16
if sunset != "Wed, 24 Dec 2025 10:20:00 GMT" { t.Fatal("Test get sunset error.", sunset)mux_test.go1
513:5discarded-error-result
mux_test.go:513:5
r.Get("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("private get")) })mux.go1
100:16exported-declaration-comment
mux.go:100:16
// the next http.Handler.func (mx *Mux) Use(middlewares ...func(http.Handler) http.Handler) { if mx.handler != nil {mux_test.go1
316:6test-parallelism
mux_test.go:316:6
func TestMuxNestedNotFound(t *testing.T) { r := NewRouter()middleware/throttle_test.go1
95:8add-constant
middleware/throttle_test.go:95:8
r.Get("/", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK)mux_test.go1
522:5discarded-error-result
mux_test.go:522:5
r.Get("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("private get")) })mux.go1
109:16exported-declaration-comment
mux.go:109:16
// execute the `handler` http.Handler.func (mx *Mux) Handle(pattern string, handler http.Handler) { if i := strings.IndexAny(pattern, " \t"); i >= 0 {mux_test.go1
394:6test-parallelism
mux_test.go:394:6
func TestMethodNotAllowed(t *testing.T) { r := NewRouter()middleware/url_format_test.go1
44:35add-constant
middleware/url_format_test.go:44:35
} if _, resp := testRequest(t, ts, "GET", "/samples/articles/samples.1.json", nil); resp != "1" { t.Fatal(resp)mux_test.go1
573:4discarded-error-result
mux_test.go:573:4
r.NotFound(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("custom not-found")) })mux.go1
121:16exported-declaration-comment
mux.go:121:16
// execute the `handlerFn` http.HandlerFunc.func (mx *Mux) HandleFunc(pattern string, handlerFn http.HandlerFunc) { mx.Handle(pattern, handlerFn)mux_test.go1
408:29test-parallelism
mux_test.go:408:29
t.Run("Registered Method", func(t *testing.T) { resp, _ := testRequest(t, ts, "GET", "/hi", nil)middleware/url_format_test.go1
44:92add-constant
middleware/url_format_test.go:44:92
} if _, resp := testRequest(t, ts, "GET", "/samples/articles/samples.1.json", nil); resp != "1" { t.Fatal(resp)mux_test.go1
583:4discarded-error-result
mux_test.go:583:4
r.NotFound(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("custom not-found")) })mux.go1
127:16exported-declaration-comment
mux.go:127:16
// execute the `handler` http.Handler.func (mx *Mux) Method(method, pattern string, handler http.Handler) { m, ok := methodMap[strings.ToUpper(method)]mux_test.go1
418:31test-parallelism
mux_test.go:418:31
t.Run("Unregistered Method", func(t *testing.T) { resp, _ := testRequest(t, ts, "POST", "/hi", nil)middleware/url_format_test.go1
58:33add-constant
middleware/url_format_test.go:58:33
r.Get("/subroute", func(w http.ResponseWriter, r *http.Request) { articleID := chi.URLParam(r, "articleID") w.Write([]byte(articleID))mux_test.go1
611:3discarded-error-result
mux_test.go:611:3
r.Get("/hi", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("bye")) })mux.go1
137:16exported-declaration-comment
mux.go:137:16
// execute the `handlerFn` http.HandlerFunc.func (mx *Mux) MethodFunc(method, pattern string, handlerFn http.HandlerFunc) { mx.Method(method, pattern, handlerFn)mux_test.go1
431:6test-parallelism
mux_test.go:431:6
func TestMuxNestedMethodNotAllowed(t *testing.T) { r := NewRouter()middleware/wrap_writer_test.go1
59:24add-constant
middleware/wrap_writer_test.go:59:24
assertEqual(t, []byte("hello world"), original.Body.Bytes()) assertEqual(t, []byte("hello world"), buf.Bytes()) assertEqual(t, 11, wrap.BytesWritten())mux_test.go1
616:3discarded-error-result
mux_test.go:616:3
v2 := r.Context().Value(ctxKey{"inline2"}).(string) w.Write([]byte(fmt.Sprintf("inline %s %s", v1, v2))) })mux.go1
143:16exported-declaration-comment
mux.go:143:16
// execute the `handlerFn` http.HandlerFunc.func (mx *Mux) Connect(pattern string, handlerFn http.HandlerFunc) { mx.handle(mCONNECT, pattern, handlerFn)mux_test.go1
497:6test-parallelism
mux_test.go:497:6
func TestMuxComplicatedNotFound(t *testing.T) { decorateRouter := func(r *Mux) {mux.go1
341:33add-constant
mux.go:341:33
} n := mx.handle(method, pattern+"*", mountHandler)mux_test.go1
708:5discarded-error-result
mux_test.go:708:5
r1.Handle(tc.pattern, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(tc.expectedBody)) }))mux.go1
149:16exported-declaration-comment
mux.go:149:16
// execute the `handlerFn` http.HandlerFunc.func (mx *Mux) Delete(pattern string, handlerFn http.HandlerFunc) { mx.handle(mDELETE, pattern, handlerFn)mux_test.go1
570:15test-parallelism
mux_test.go:570:15
t.Run("pre", func(t *testing.T) { r := NewRouter()mux.go1
460:16add-constant
mux.go:460:16
if routePath == "" { routePath = "/" }mux_test.go1
714:5discarded-error-result
mux_test.go:714:5
r2.HandleFunc(tc.pattern, func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(tc.expectedBody)) })mux.go1
155:16exported-declaration-comment
mux.go:155:16
// execute the `handlerFn` http.HandlerFunc.func (mx *Mux) Get(pattern string, handlerFn http.HandlerFunc) { mx.handle(mGET, pattern, handlerFn)mux_test.go3
579:16test-parallelism
mux_test.go:579:16
t.Run("post", func(t *testing.T) { r := NewRouter()111:9add-constant
mux_test.go:111:9
m.Head("/ping", headPing) m.Post("/ping", createPing) m.Get("/ping/{id}", pingWoop)792:5discarded-error-result
mux_test.go:792:5
if r.URL.Path == "/ping" { w.Write([]byte("pong")) returnmux.go1
161:16exported-declaration-comment
mux.go:161:16
// execute the `handlerFn` http.HandlerFunc.func (mx *Mux) Head(pattern string, handlerFn http.HandlerFunc) { mx.handle(mHEAD, pattern, handlerFn)mux_test.go3
589:6test-parallelism
mux_test.go:589:6
func TestMuxWith(t *testing.T) { var cmwInit1, cmwHandler1 uint64122:35add-constant
mux_test.go:122:35
// GET / if _, body := testRequest(t, ts, "GET", "/", nil); body != "hi peter" { t.Fatal(body)805:3discarded-error-result
mux_test.go:805:3
ctxmwHandlerCount := ctx.Value(ctxKey{"count.ctxmwHandler"}).(uint64) w.Write([]byte(fmt.Sprintf("inits:%d reqs:%d ctxValue:%d", ctxmwInit, handlerCount, ctxmwHandlerCount))) })mux.go1
167:16exported-declaration-comment
mux.go:167:16
// execute the `handlerFn` http.HandlerFunc.func (mx *Mux) Options(pattern string, handlerFn http.HandlerFunc) { mx.handle(mOPTIONS, pattern, handlerFn)mux_test.go3
642:6test-parallelism
mux_test.go:642:6
func TestMuxHandlePatternValidation(t *testing.T) { testCases := []struct {141:69add-constant
mux_test.go:141:69
// GET /ping/all if _, body := testRequest(t, ts, "GET", "/ping/all", nil); body != "ping all" { t.Fatal(body)809:3discarded-error-result
mux_test.go:809:3
r.Get("/hi", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("wooot")) })mux.go1
173:16exported-declaration-comment
mux.go:173:16
// execute the `handlerFn` http.HandlerFunc.func (mx *Mux) Patch(pattern string, handlerFn http.HandlerFunc) { mx.handle(mPATCH, pattern, handlerFn)mux_test.go3
699:18test-parallelism
mux_test.go:699:18
for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { defer func() {198:21add-constant
mux_test.go:198:21
if string(body) != "catchall" { t.Error("expecting response body: 'catchall'")853:4discarded-error-result
mux_test.go:853:4
r.Get("/group", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("root group")) })mux.go1
179:16exported-declaration-comment
mux.go:179:16
// execute the `handlerFn` http.HandlerFunc.func (mx *Mux) Post(pattern string, handlerFn http.HandlerFunc) { mx.handle(mPOST, pattern, handlerFn)mux_test.go3
754:6test-parallelism
mux_test.go:754:6
func TestMuxMiddlewareStack(t *testing.T) { var stdmwInit, stdmwHandler uint64217:9add-constant
mux_test.go:217:9
r.Route("/{hash}/share", func(r Router) { r.Get("/", func(w http.ResponseWriter, r *http.Request) { v := URLParam(r, "hash")859:4discarded-error-result
mux_test.go:859:4
r.Get("/group2", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("root group2")) })mux.go1
185:16exported-declaration-comment
mux.go:185:16
// execute the `handlerFn` http.HandlerFunc.func (mx *Mux) Put(pattern string, handlerFn http.HandlerFunc) { mx.handle(mPUT, pattern, handlerFn)mux_test.go3
829:6test-parallelism
mux_test.go:829:6
func TestMuxRouteGroups(t *testing.T) { var stdmwInit, stdmwHandler uint64222:21add-constant
mux_test.go:222:21
r.Get("/{network}", func(w http.ResponseWriter, r *http.Request) { v := URLParam(r, "hash") n := URLParam(r, "network")980:4discarded-error-result
mux_test.go:980:4
r.Get("/favicon.ico", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("fav")) })mux.go1
191:16exported-declaration-comment
mux.go:191:16
// execute the `handlerFn` http.HandlerFunc.func (mx *Mux) Query(pattern string, handlerFn http.HandlerFunc) { mx.handle(mQUERY, pattern, handlerFn)mux_test.go3
885:6test-parallelism
mux_test.go:885:6
func TestMuxBig(t *testing.T) { r := bigMux()289:18add-constant
mux_test.go:289:18
w.WriteHeader(404) w.Write([]byte("nothing here")) })986:4discarded-error-result
mux_test.go:986:4
ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"})) w.Write([]byte(s)) })mux.go1
197:16exported-declaration-comment
mux.go:197:16
// execute the `handlerFn` http.HandlerFunc.func (mx *Mux) Trace(pattern string, handlerFn http.HandlerFunc) { mx.handle(mTRACE, pattern, handlerFn)mux_test.go3
1096:6test-parallelism
mux_test.go:1096:6
func TestMuxSubroutesBasic(t *testing.T) { hIndex := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {326:8add-constant
mux_test.go:326:8
r.Get("/hi", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("bye"))992:4discarded-error-result
mux_test.go:992:4
URLParam(r, "*"), ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"})) w.Write([]byte(s)) })mux.go1
203:16exported-declaration-comment
mux.go:203:16
// not be found. The default 404 handler is `http.NotFound`.func (mx *Mux) NotFound(handlerFn http.HandlerFunc) { // Build NotFound handler chainmux_test.go3
1177:6test-parallelism
mux_test.go:1177:6
func TestMuxSubroutes(t *testing.T) { hHubView1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {327:18add-constant
mux_test.go:327:18
r.Get("/hi", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("bye")) })998:4discarded-error-result
mux_test.go:998:4
URLParam(r, "*"), ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"})) w.Write([]byte(s)) })mux.go1
223:16exported-declaration-comment
mux.go:223:16
// method is unresolved. The default handler returns a 405 with an empty body.func (mx *Mux) MethodNotAllowed(handlerFn http.HandlerFunc) { // Build MethodNotAllowed handler chainmux_test.go3
1292:6test-parallelism
mux_test.go:1292:6
func TestSingleHandler(t *testing.T) { h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {336:37add-constant
mux_test.go:336:37
}).NotFound(func(w http.ResponseWriter, r *http.Request) { chkMw := r.Context().Value(ctxKey{"mw"}).(string) chkWith := r.Context().Value(ctxKey{"with"}).(string)1011:4discarded-error-result
mux_test.go:1011:4
s := fmt.Sprintf("/ reqid:%s session:%s", ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"})) w.Write([]byte(s)) })mux.go1
268:16exported-declaration-comment
mux.go:268:16
// set of middlewares. See _examples/.func (mx *Mux) Group(fn func(r Router)) Router { im := mx.With()mux_test.go3
1336:6test-parallelism
mux_test.go:1336:6
func TestServeHTTPExistingContext(t *testing.T) { r := NewRouter()337:39add-constant
mux_test.go:337:39
chkMw := r.Context().Value(ctxKey{"mw"}).(string) chkWith := r.Context().Value(ctxKey{"with"}).(string) w.WriteHeader(404)1016:4discarded-error-result
mux_test.go:1016:4
s := fmt.Sprintf("/suggestions reqid:%s session:%s", ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"})) w.Write([]byte(s)) })mux.go1
278:16exported-declaration-comment
mux.go:278:16
// Effectively, this is a short-hand call to Mount. See _examples/.func (mx *Mux) Route(pattern string, fn func(r Router)) Router { if fn == nil {mux_test.go3
1392:6test-parallelism
mux_test.go:1392:6
func TestNestedGroups(t *testing.T) { handlerPrintCounter := func(w http.ResponseWriter, r *http.Request) {355:39add-constant
mux_test.go:355:39
sr1.NotFound(func(w http.ResponseWriter, r *http.Request) { chkMw2 := r.Context().Value(ctxKey{"mw2"}).(string) w.WriteHeader(404)1021:4discarded-error-result
mux_test.go:1021:4
s := fmt.Sprintf("/woot/%s/%s", URLParam(r, "wootID"), URLParam(r, "*")) w.Write([]byte(s)) })mux.go1
295:16exported-declaration-comment
mux.go:295:16
// if you define two Mount() routes on the exact same pattern the mount will panic.func (mx *Mux) Mount(pattern string, handler http.Handler) { if handler == nil {mux_test.go3
1448:6test-parallelism
mux_test.go:1448:6
func TestMiddlewarePanicOnLateUse(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) {375:42add-constant
mux_test.go:375:42
} if _, body := testRequest(t, ts, "GET", "/nothing-here", nil); body != "root 404 mw with" { t.Fatal(body)1032:6discarded-error-result
mux_test.go:1032:6
URLParam(r, "hubID"), ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"})) w.Write([]byte(s)) })mux.go1
350:16exported-declaration-comment
mux.go:350:16
// useful for traversing available routes of a router.func (mx *Mux) Routes() []Route { return mx.tree.routes()mux_test.go3
1470:6test-parallelism
mux_test.go:1470:6
func TestMountingExistingPath(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) {}452:18add-constant
mux_test.go:452:18
sr2.Get("/sub2", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("sub2")) })1038:6discarded-error-result
mux_test.go:1038:6
ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"})) w.Write([]byte(s)) })mux.go1
365:16exported-declaration-comment
mux.go:365:16
// the state carefully or make a NewRouteContext().func (mx *Mux) Match(rctx *Context, method, path string) bool { return mx.Find(rctx, method, path) != ""mux_test.go3
1485:6test-parallelism
mux_test.go:1485:6
func TestMountingSimilarPattern(t *testing.T) { r := NewRouter()474:42add-constant
mux_test.go:474:42
} if _, body := testRequest(t, ts, "PUT", "/root", nil); body != "root 405" { t.Fatal(body)1046:6discarded-error-result
mux_test.go:1046:6
ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"})) w.Write([]byte(s)) })mux.go1
374:16exported-declaration-comment
mux.go:374:16
// the state carefully or make a NewRouteContext().func (mx *Mux) Find(rctx *Context, method, path string) string { m, ok := methodMap[method]mux_test.go3
1512:6test-parallelism
mux_test.go:1512:6
func TestMuxEmptyParams(t *testing.T) { r := NewRouter()486:35add-constant
mux_test.go:486:35
} if _, body := testRequest(t, ts, "PUT", "/prefix2/sub2", nil); body != "root 405" { t.Fatal(body)1054:7discarded-error-result
mux_test.go:1054:7
URLParam(r, "webhookID"), ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"})) w.Write([]byte(s)) })mux.go1
404:16exported-declaration-comment
mux.go:404:16
// cannot be found.func (mx *Mux) NotFoundHandler() http.HandlerFunc { if mx.notFoundHandler != nil {mux_test.go3
1532:6test-parallelism
mux_test.go:1532:6
func TestMuxMissingParams(t *testing.T) { r := NewRouter()486:73add-constant
mux_test.go:486:73
} if _, body := testRequest(t, ts, "PUT", "/prefix2/sub2", nil); body != "root 405" { t.Fatal(body)1070:7discarded-error-result
mux_test.go:1070:7
ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"})) w.Write([]byte(s)) })mux.go1
413:16exported-declaration-comment
mux.go:413:16
// a method cannot be resolved for a route.func (mx *Mux) MethodNotAllowedHandler(methodsAllowed ...methodTyp) http.HandlerFunc { if mx.methodNotAllowedHandler != nil {mux_test.go3
1554:6test-parallelism
mux_test.go:1554:6
func TestMuxWildcardRoute(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) {}539:69add-constant
mux_test.go:539:69
} if _, body := testRequest(t, ts, "GET", "/public/", nil); body != "public get" { t.Fatal(body)1082:5discarded-error-result
mux_test.go:1082:5
ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"})) w.Write([]byte(s)) })tree.go1
69:6exported-declaration-comment
tree.go:69:6
// via Router#Method and Router#MethodFuncfunc RegisterMethod(method string) { if method == "" {mux_test.go3
1567:6test-parallelism
mux_test.go:1567:6
func TestMuxWildcardRouteCheckTwo(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) {}542:78add-constant
mux_test.go:542:78
} if _, body := testRequest(t, ts, "GET", "/private/resource", nil); body != "private get" { t.Fatal(body)1088:5discarded-error-result
mux_test.go:1088:5
ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"})) w.Write([]byte(s)) })tree.go1
138:20exported-declaration-comment
tree.go:138:20
func (s endpoints) Value(method methodTyp) *endpoint { mh, ok := s[method]mux_test.go3
1580:6test-parallelism
mux_test.go:1580:6
func TestMuxRegexp(t *testing.T) { r := NewRouter()552:74add-constant
mux_test.go:552:74
} if _, body := testRequest(t, ts, "GET", "/private/nope", nil); body != "custom not-found" { t.Fatal(body)1098:3discarded-error-result
mux_test.go:1098:3
hIndex := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("index")) })tree.go1
147:16exported-declaration-comment
tree.go:147:16
func (n *node) InsertRoute(method methodTyp, pattern string, handler http.Handler) *node { var parent *nodemux_test.go3
1596:6test-parallelism
mux_test.go:1596:6
func TestMuxRegexp2(t *testing.T) { r := NewRouter()869:12add-constant
mux_test.go:869:12
if body != "root group" { t.Fatalf("got: '%s'", body) }1101:3discarded-error-result
mux_test.go:1101:3
hArticlesList := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("articles-list")) })tree.go1
382:16exported-declaration-comment
tree.go:382:16
func (n *node) FindRoute(rctx *Context, method methodTyp, path string) (*node, endpoints, http.Handler) { // Reset the context routing pattern and paramsmux_test.go3
1612:6test-parallelism
mux_test.go:1612:6
func TestMuxRegexp3(t *testing.T) { r := NewRouter()905:31add-constant
mux_test.go:905:31
} _, body = testRequest(t, ts, "POST", "/hubs/ethereumhub/view/index.html", nil) if body != "/hubs/ethereumhub/view/index.html reqid:1 session:anonymous" {1104:3discarded-error-result
mux_test.go:1104:3
hSearchArticles := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("search-articles")) })tree.go1
795:17exported-declaration-comment
tree.go:795:17
func (ns nodes) Sort() { sort.Sort(ns); ns.tailSort() }func (ns nodes) Len() int { return len(ns) }func (ns nodes) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] }mux_test.go3
1653:6test-parallelism
mux_test.go:1653:6
func TestMuxSubrouterWildcardParam(t *testing.T) { h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {907:12add-constant
mux_test.go:907:12
if body != "/hubs/ethereumhub/view/index.html reqid:1 session:anonymous" { t.Fatalf("got '%s'", body) }1107:3discarded-error-result
mux_test.go:1107:3
hGetArticle := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(fmt.Sprintf("get-article:%s", URLParam(r, "id")))) })tree.go1
796:17exported-declaration-comment
tree.go:796:17
func (ns nodes) Len() int { return len(ns) }func (ns nodes) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] }func (ns nodes) Less(i, j int) bool { return ns[i].label < ns[j].label }mux_test.go3
1685:6test-parallelism
mux_test.go:1685:6
func TestMuxContextIsThreadSafe(t *testing.T) { router := NewRouter()939:13add-constant
mux_test.go:939:13
_, body = testRequest(t, ts, "GET", "/folders", nil) if body != "404 page not found\n" { t.Fatalf("got '%s'", body)1110:3discarded-error-result
mux_test.go:1110:3
hSyncArticle := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(fmt.Sprintf("sync-article:%s", URLParam(r, "id")))) })tree.go1
797:17exported-declaration-comment
tree.go:797:17
func (ns nodes) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] }func (ns nodes) Less(i, j int) bool { return ns[i].label < ns[j].label }mux_test.go3
1721:6test-parallelism
mux_test.go:1721:6
func TestEscapedURLParams(t *testing.T) { m := NewRouter()991:40add-constant
mux_test.go:991:40
s := fmt.Sprintf("/hubs/%s/view/%s reqid:%s session:%s", URLParamFromCtx(ctx, "hubID"), URLParam(r, "*"), ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"})) w.Write([]byte(s))1179:3discarded-error-result
mux_test.go:1179:3
hHubView1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("hub1")) })tree.go1
832:6exported-declaration-comment
tree.go:832:6
// Handlers map key is an HTTP methodtype Route struct { SubRoutes Routesmux_test.go11
1761:6test-parallelism
mux_test.go:1761:6
func TestCustomHTTPMethod(t *testing.T) { // first we must register this method to be accepted, then we991:72add-constant
mux_test.go:991:72
s := fmt.Sprintf("/hubs/%s/view/%s reqid:%s session:%s", URLParamFromCtx(ctx, "hubID"), URLParam(r, "*"), ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"})) w.Write([]byte(s))1182:3discarded-error-result
mux_test.go:1182:3
hHubView2 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("hub2")) })1807:6test-parallelism
mux_test.go:1807:6
func TestQueryHTTPMethod(t *testing.T) { r := NewRouter()1020:71add-constant
mux_test.go:1020:71
r.Get("/woot/{wootID}/*", func(w http.ResponseWriter, r *http.Request) { s := fmt.Sprintf("/woot/%s/%s", URLParam(r, "wootID"), URLParam(r, "*")) w.Write([]byte(s))1185:3discarded-error-result
mux_test.go:1185:3
hHubView3 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("hub3")) })1858:6test-parallelism
mux_test.go:1858:6
func TestMuxMatch(t *testing.T) { r := NewRouter()1031:19add-constant
mux_test.go:1031:19
s := fmt.Sprintf("/hubs/%s reqid:%s session:%s", URLParam(r, "hubID"), ctx.Value(ctxKey{"requestID"}), ctx.Value(ctxKey{"session.user"})) w.Write([]byte(s))1188:3discarded-error-result
mux_test.go:1188:3
hAccountView1 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("account1")) })1896:6test-parallelism
mux_test.go:1896:6
func TestMuxMatch_HasBasePath(t *testing.T) { r := NewRouter()1084:10add-constant
mux_test.go:1084:10
}) r.Get("/public", func(w http.ResponseWriter, r *http.Request) { ctx := r.Context()