Skip to content

Commit

Permalink
Merge pull request #206 from immunochomik/205-handle-java-default-accept
Browse files Browse the repository at this point in the history
Add handling for Accept header q=./d
  • Loading branch information
casualjim committed Aug 4, 2021
2 parents 539cabc + 9f04698 commit a98b067
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions middleware/header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions middleware/negotiate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a98b067

Please sign in to comment.