Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handling for Accept header q=./d #206

Merged
merged 1 commit into from
Aug 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add handling for Accept header q=./d
It is not consistent with RFC 7231 but it is present in default value for Accept header in Java clients
  • Loading branch information
tomaszs committed Aug 4, 2021

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tormath1 Mathieu Tortuyaux
commit 9f04698f50628e46b4905eb56adfe1acafafc719
7 changes: 5 additions & 2 deletions middleware/header/header.go
Original file line number Diff line number Diff line change
@@ -265,13 +265,16 @@ func expectQuality(s string) (q float64, rest string) {
case len(s) == 0:
return -1, ""
case s[0] == '0':
q = 0
// q is already 0
s = s[1:]
case s[0] == '1':
s = s[1:]
q = 1
case s[0] == '.':
// q is already 0
default:
return -1, ""
}
s = s[1:]
if !strings.HasPrefix(s, ".") {
return q, s
}
2 changes: 2 additions & 0 deletions middleware/negotiate_test.go
Original file line number Diff line number Diff line change
@@ -62,6 +62,8 @@ var negotiateContentTypeTests = []struct {
{"application/json", []string{"application/json; charset=utf-8", "image/png"}, "", "application/json; charset=utf-8"},
{"application/json; charset=utf-8", []string{"application/json; charset=utf-8", "image/png"}, "", "application/json; charset=utf-8"},
{"application/json", []string{"application/vnd.cia.v1+json"}, "", ""},
// Default header of java clients
{"text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2", []string{"application/json"}, "", "application/json"},
}

func TestNegotiateContentType(t *testing.T) {