-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.go
38 lines (33 loc) · 880 Bytes
/
header.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package filters
import (
"net/http"
"net/textproto"
"strings"
"github.com/clinia/x/otelx/instrumentation/otelhttpx"
)
// Header returns a Filter that returns true if the request
// includes a header k with a value equal to v.
func Header(k, v string) otelhttpx.Filter {
return func(r *http.Request) bool {
for _, hv := range r.Header[textproto.CanonicalMIMEHeaderKey(k)] {
if v == hv {
return true
}
}
return false
}
}
// HeaderContains returns a Filter that returns true if the request
// includes a header k with a value that contains v.
func HeaderContains(k, v string) otelhttpx.Filter {
return func(r *http.Request) bool {
for _, hv := range r.Header[textproto.CanonicalMIMEHeaderKey(k)] {
if strings.Contains(hv, v) {
return true
}
}
return false
}
}