Fixed a bug in handling an "*/*" Accept header.
diff --git a/accept.go b/accept.go index ed7d16e..335cc6f 100644 --- a/accept.go +++ b/accept.go
@@ -32,8 +32,8 @@ Only the first "Accept" header on the request is considered. */ func SelectMediaType(req *http.Request, choices []string) string { - hdr := req.Header.Get("Accept") - if hdr == "" { + hdr := strings.TrimSpace(req.Header.Get("Accept")) + if hdr == "" || hdr == "*" || hdr == "*/*" { if len(choices) >= 1 { return choices[0] }
diff --git a/accept_test.go b/accept_test.go index f9cfe75..346f284 100644 --- a/accept_test.go +++ b/accept_test.go
@@ -31,6 +31,18 @@ []string{"application/json", "text/plain"})).Should(Equal("application/json")) }) + It("Accept all, two choices", func() { + Expect(SelectMediaType( + makeRequest("*/*"), + []string{"text/plain", "text/xml"})).Should(Equal("text/plain")) + }) + + It("Accept all, two choices 2", func() { + Expect(SelectMediaType( + makeRequest("*/*"), + []string{"application/json", "text/plain"})).Should(Equal("application/json")) + }) + It("One Header, two choices", func() { Expect(SelectMediaType( makeRequest("application/json"),