Debian Codegraph @

instrumentation/net/http/otelhttp/filters/header.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package filters // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/filters"
5
6 import (
7 "net/http"
8 "net/textproto"
9 "slices"
10 "strings"
11
12 "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
13 )
14
15 // Header returns a Filter that returns true if the request
16 // includes a header k with a value equal to v.
17 func Header(k, v string) otelhttp.Filter {
18 return func(r *http.Request) bool {
19 return slices.Contains(r.Header[textproto.CanonicalMIMEHeaderKey(k)], v)
20 }
21 }
22
23 // HeaderContains returns a Filter that returns true if the request
24 // includes a header k with a value that contains v.
25 func HeaderContains(k, v string) otelhttp.Filter {
26 return func(r *http.Request) bool {
27 for _, hv := range r.Header[textproto.CanonicalMIMEHeaderKey(k)] {
28 if strings.Contains(hv, v) {
29 return true
30 }
31 }
32 return false
33 }
34 }