MCPcopy Index your code
hub / github.com/dunglas/httpsfv / checkKey

Function checkKey

key.go:28–44  ·  view source on GitHub ↗

checkKey checks if the given value is a valid parameter key according to https://httpwg.org/specs/rfc9651.html#param.

(k string)

Source from the content-addressed store, hash-verified

26// checkKey checks if the given value is a valid parameter key according to
27// https://httpwg.org/specs/rfc9651.html#param.
28func checkKey(k string) error {
29 if len(k) == 0 {
30 return fmt.Errorf("a key cannot be empty: %w", ErrInvalidKeyFormat)
31 }
32
33 if !isLowerCaseAlpha(k[0]) && k[0] != '*' {
34 return fmt.Errorf("a key must start with a lower case alpha character or *: %w", ErrInvalidKeyFormat)
35 }
36
37 for i := 1; i < len(k); i++ {
38 if !isKeyChar(k[i]) {
39 return fmt.Errorf("the character %c isn't allowed in a key: %w", k[i], ErrInvalidKeyFormat)
40 }
41 }
42
43 return nil
44}
45
46// marshalKey serializes as defined in
47// https://httpwg.org/specs/rfc9651.html#ser-key.

Callers 1

marshalKeyFunction · 0.85

Calls 2

isLowerCaseAlphaFunction · 0.85
isKeyCharFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…