@@ -2,6 +2,7 @@ package browser
22
33import (
44 "maps"
5+ "net/http"
56 "slices"
67 "strings"
78)
@@ -11,10 +12,10 @@ type allowance struct {
1112 headers map [string ]any
1213}
1314
14- func lookup (ss []string ) map [string ]any {
15+ func lookup (ss []string , canonicalize func ( string ) string ) map [string ]any {
1516 us := make (map [string ]any , len (ss ))
1617 for _ , s := range ss {
17- us [strings . ToLower (s )] = nil
18+ us [canonicalize (s )] = nil
1819 }
1920 return us
2021}
@@ -24,13 +25,13 @@ func has[K comparable, V any](m map[K]V, k K) bool {
2425 return ok
2526}
2627
27- func contains (asked string , allowed map [string ]any ) bool {
28- return has (allowed , strings . ToLower (asked ))
28+ func contains (asked string , allowed map [string ]any , canonicalize func ( string ) string ) bool {
29+ return has (allowed , canonicalize (asked ))
2930}
3031
31- func containsAll (asked []string , allowed map [string ]any ) bool {
32+ func containsAll (asked []string , allowed map [string ]any , canonicalize func ( string ) string ) bool {
3233 for _ , a := range asked {
33- if ! contains (a , allowed ) {
34+ if ! contains (a , allowed , canonicalize ) {
3435 return false
3536 }
3637 }
@@ -54,8 +55,8 @@ func NewMatcher(origin, path StringMatcher, allowedmethods, allowedheaders []str
5455 origin : origin ,
5556 path : path ,
5657 allowance : & allowance {
57- methods : lookup (allowedmethods ),
58- headers : lookup (allowedheaders ),
58+ methods : lookup (allowedmethods , strings . ToLower ),
59+ headers : lookup (allowedheaders , http . CanonicalHeaderKey ),
5960 },
6061 }
6162}
@@ -72,10 +73,10 @@ func (m Matcher) Match(origin, method, path string, headers []string) *Scope {
7273 if ! m .origin .MatchString (origin ) || ! m .path .MatchString (path ) {
7374 return nil
7475 }
75- if ! contains (method , m .allowance .methods ) {
76+ if ! contains (method , m .allowance .methods , strings . ToLower ) {
7677 return nil
7778 }
78- if ! containsAll (headers , m .allowance .headers ) {
79+ if ! containsAll (headers , m .allowance .headers , http . CanonicalHeaderKey ) {
7980 return nil
8081 }
8182 return & Scope {
0 commit comments