From 674a606bd00b276d0a05b3b29a3d5f5e5e7f8206 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 11 Sep 2017 10:09:24 -0500 Subject: more robust command response content-type checking (#7412) --- model/command_response.go | 3 ++- model/command_response_test.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/model/command_response.go b/model/command_response.go index 0b80b297b..d17bd00e3 100644 --- a/model/command_response.go +++ b/model/command_response.go @@ -7,6 +7,7 @@ import ( "encoding/json" "io" "io/ioutil" + "strings" ) const ( @@ -33,7 +34,7 @@ func (o *CommandResponse) ToJson() string { } func CommandResponseFromHTTPBody(contentType string, body io.Reader) *CommandResponse { - if contentType == "application/json" { + if strings.TrimSpace(strings.Split(contentType, ";")[0]) == "application/json" { return CommandResponseFromJson(body) } if b, err := ioutil.ReadAll(body); err == nil { diff --git a/model/command_response_test.go b/model/command_response_test.go index 19be796b8..dde8d032b 100644 --- a/model/command_response_test.go +++ b/model/command_response_test.go @@ -27,6 +27,7 @@ func TestCommandResponseFromHTTPBody(t *testing.T) { {"", "foo", "foo"}, {"text/plain", "foo", "foo"}, {"application/json", `{"text": "foo"}`, "foo"}, + {"application/json; charset=utf-8", `{"text": "foo"}`, "foo"}, } { response := CommandResponseFromHTTPBody(test.ContentType, strings.NewReader(test.Body)) if response.Text != test.ExpectedText { -- cgit v1.2.3-1-g7c22