| 1 | package utilsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/ |
| 2 | |
| 3 | import ( |
| 4 | "net/httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/" |
| 5 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 6 | |
| 7 | "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/" |
| 8 | ) |
| 9 | |
| 10 | func headerKeySamplesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/headerKeySamples().() []string { |
| 11 | return []string{ |
| 12 | "", |
| 13 | "Content-Type", |
| 14 | "content-type", |
| 15 | "CONTENT-TYPE", |
| 16 | "cOnTeNt-TyPe", |
| 17 | "Host", |
| 18 | "host", |
| 19 | "x-request-id", |
| 20 | "X-Request-ID", |
| 21 | "x--double-dash", |
| 22 | "-leading-dash", |
| 23 | "trailing-dash-", |
| 24 | "1-2-3", |
| 25 | "etag", |
| 26 | "WWW-Authenticate", |
| 27 | "www-authenticate", |
| 28 | "Header With Space", |
| 29 | "Bad:Colon", |
| 30 | "Tab\tKey", |
| 31 | "non-ascii-é", |
| 32 | "under_score", |
| 33 | "tilde~ok", |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | func Test_CanonicalHeaderKeyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_CanonicalHeaderKey().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 38 | t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().() |
| 39 | for _, in := range headerKeySamplesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/headerKeySamples().() { |
| 40 | want := httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.CanonicalHeaderKeyscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/CanonicalHeaderKey().(in) |
| 41 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, want, CanonicalHeaderKeyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/CanonicalHeaderKey().(in), "input %q", in) |
| 42 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, want, string(CanonicalHeaderKeyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/CanonicalHeaderKey().([]byte(in))), "input %q", in) |
| 43 | } |
| 44 | |
| 45 | // Already-canonical and invalid keys come back without copying: for |
| 46 | // []byte inputs the same backing array is returned. |
| 47 | for _, in := range []string{"Content-Type", "Bad Key", "X-Id"} { |
| 48 | b := []byte(in) |
| 49 | out := CanonicalHeaderKeyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/CanonicalHeaderKey().(b) |
| 50 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Samescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Same().(t, &b[0], &out[0], "input %q must not copy", in) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | func Benchmark_CanonicalHeaderKeyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Benchmark_CanonicalHeaderKey().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 55 | inputs := []struct { |
| 56 | name string |
| 57 | value string |
| 58 | }{ |
| 59 | {"canonical", "Content-Type"}, |
| 60 | {"common-lower", "content-type"}, |
| 61 | {"custom-lower", "x-custom-request-id"}, |
| 62 | } |
| 63 | for _, input := range inputs { |
| 64 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().(input.name+"/fiber", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 65 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.25.0 testing/B#ReportAllocs().() |
| 66 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 67 | CanonicalHeaderKeyscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/CanonicalHeaderKey().(input.value) |
| 68 | } |
| 69 | }) |
| 70 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().(input.name+"/default", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 71 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.25.0 testing/B#ReportAllocs().() |
| 72 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 73 | httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.CanonicalHeaderKeyscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/CanonicalHeaderKey().(input.value) |
| 74 | } |
| 75 | }) |
| 76 | } |
| 77 | } |