Skip to content

Commit

Permalink
More permissive JSON detection (#190)
Browse files Browse the repository at this point in the history
Match the logic that the API server uses to detect content-type, assuming that everything is JSON unless told that it is msgpack
  • Loading branch information
martin308 authored Nov 13, 2020
1 parent 50772e3 commit b30d601
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,7 @@ func unmarshal(r *http.Request, data io.Reader, v interface{}) error {
return msgpack.NewDecoder(data).
UseDecodeInterfaceLoose(true).
Decode(v)
case "application/json":
return jsoniter.NewDecoder(data).Decode(v)
default:
return errors.New("Bad Content-Type")
return jsoniter.NewDecoder(data).Decode(v)
}
}
2 changes: 1 addition & 1 deletion route/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestUnmarshal(t *testing.T) {

w = httptest.NewRecorder()
body = bytes.NewBufferString(`{"traceId": "test"}`)
unmarshalRequest(w, "application/json", body)
unmarshalRequest(w, "application/json; charset=utf-8", body)

if b := w.Body.String(); b != "test" {
t.Error("Expecting test")
Expand Down

0 comments on commit b30d601

Please sign in to comment.