more robust command response content-type checking (#7412)
Этот коммит содержится в:
@@ -7,6 +7,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -33,7 +34,7 @@ func (o *CommandResponse) ToJson() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CommandResponseFromHTTPBody(contentType string, body io.Reader) *CommandResponse {
|
func CommandResponseFromHTTPBody(contentType string, body io.Reader) *CommandResponse {
|
||||||
if contentType == "application/json" {
|
if strings.TrimSpace(strings.Split(contentType, ";")[0]) == "application/json" {
|
||||||
return CommandResponseFromJson(body)
|
return CommandResponseFromJson(body)
|
||||||
}
|
}
|
||||||
if b, err := ioutil.ReadAll(body); err == nil {
|
if b, err := ioutil.ReadAll(body); err == nil {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ func TestCommandResponseFromHTTPBody(t *testing.T) {
|
|||||||
{"", "foo", "foo"},
|
{"", "foo", "foo"},
|
||||||
{"text/plain", "foo", "foo"},
|
{"text/plain", "foo", "foo"},
|
||||||
{"application/json", `{"text": "foo"}`, "foo"},
|
{"application/json", `{"text": "foo"}`, "foo"},
|
||||||
|
{"application/json; charset=utf-8", `{"text": "foo"}`, "foo"},
|
||||||
} {
|
} {
|
||||||
response := CommandResponseFromHTTPBody(test.ContentType, strings.NewReader(test.Body))
|
response := CommandResponseFromHTTPBody(test.ContentType, strings.NewReader(test.Body))
|
||||||
if response.Text != test.ExpectedText {
|
if response.Text != test.ExpectedText {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user