Create Cors handler with permissive configuration (#7186)

Create new Cors handler allowing all origins with all standard
methods with any header and credentials.

Fixes #7181
This commit is contained in:
kannappanr
2019-02-05 14:06:52 -08:00
committed by GitHub
parent 9a65f6dc97
commit df418a2783
6 changed files with 101 additions and 98 deletions
+5 -4
View File
@@ -12,7 +12,7 @@ type wildcard struct {
}
func (w wildcard) match(s string) bool {
return len(s) >= len(w.prefix+w.suffix) && strings.HasPrefix(s, w.prefix) && strings.HasSuffix(s, w.suffix)
return len(s) >= len(w.prefix)+len(w.suffix) && strings.HasPrefix(s, w.prefix) && strings.HasSuffix(s, w.suffix)
}
// convert converts a list of string using the passed converter function
@@ -39,19 +39,20 @@ func parseHeaderList(headerList string) []string {
headers := make([]string, 0, t)
for i := 0; i < l; i++ {
b := headerList[i]
if b >= 'a' && b <= 'z' {
switch {
case b >= 'a' && b <= 'z':
if upper {
h = append(h, b-toLower)
} else {
h = append(h, b)
}
} else if b >= 'A' && b <= 'Z' {
case b >= 'A' && b <= 'Z':
if !upper {
h = append(h, b+toLower)
} else {
h = append(h, b)
}
} else if b == '-' || b == '_' || (b >= '0' && b <= '9') {
case b == '-' || b == '_' || (b >= '0' && b <= '9'):
h = append(h, b)
}