Support negotiation wildcards, fix #391 (#1112)

* support negotiation wildcards, fix #391

* fix typo
This commit is contained in:
Equim
2019-03-01 10:03:14 +08:00
committed by 田欧
parent 9bacadd3ea
commit 2dd3193006
2 changed files with 38 additions and 3 deletions

View File

@ -952,7 +952,18 @@ func (c *Context) NegotiateFormat(offered ...string) string {
}
for _, accepted := range c.Accepted {
for _, offert := range offered {
if accepted == offert {
// According to RFC 2616 and RFC 2396, non-ASCII characters are not allowed in headers,
// therefore we can just iterate over the string without casting it into []rune
i := 0
for ; i < len(accepted); i++ {
if accepted[i] == '*' || offert[i] == '*' {
return offert
}
if accepted[i] != offert[i] {
break
}
}
if i == len(accepted) {
return offert
}
}