diff --git a/middleware/header/header.go b/middleware/header/header.go index 3e342258..e069743e 100644 --- a/middleware/header/header.go +++ b/middleware/header/header.go @@ -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 } diff --git a/middleware/negotiate_test.go b/middleware/negotiate_test.go index d7addee4..6d28ddfb 100644 --- a/middleware/negotiate_test.go +++ b/middleware/negotiate_test.go @@ -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) {