Debian Codegraph @

strict/headers.go

raw
1 // Copyright 2023-2025 Princess Beef Heavy Industries, LLC / Dave Shanley
2 // SPDX-License-Identifier: MIT
3
4 package strict
5
6 import "strings"
7
8 // isHeaderIgnored checks if a header name should be ignored in strict validation.
9 // Uses the effective ignored headers list from options (defaults, replaced, or merged).
10 // Set-Cookie is direction-aware: ignored in responses but reported in requests.
11 func (v *Validator) isHeaderIgnored(name string, direction Direction) bool {
12 lower := strings.ToLower(name)
13
14 // Set-Cookie is expected in responses but unexpected in requests
15 if lower == "set-cookie" {
16 return direction == DirectionResponse
17 }
18
19 // Check effective ignored list
20 for _, h := range v.getEffectiveIgnoredHeaders() {
21 if strings.ToLower(h) == lower {
22 return true
23 }
24 }
25 return false
26 }
27
28 // getEffectiveIgnoredHeaders returns the list of headers to ignore based on
29 // configuration. Uses the ValidationOptions method for consistency.
30 func (v *Validator) getEffectiveIgnoredHeaders() []string {
31 if v.options == nil {
32 return nil
33 }
34 return v.options.GetEffectiveStrictIgnoredHeaders()
35 }