Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/is_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func isJson(reqAndResp *httpRequestAndResponse, maxContentLength int64) bool {
if err != nil {
return false
}
var v map[string]interface{}
var v interface{}
if json.Unmarshal(bodyBytes, &v) == nil {
return true
}
Expand All @@ -39,7 +39,7 @@ func isJson(reqAndResp *httpRequestAndResponse, maxContentLength int64) bool {
if err != nil {
return false
}
var v map[string]interface{}
var v interface{}
if json.Unmarshal(bodyBytes, &v) == nil {
return true
}
Expand Down
54 changes: 54 additions & 0 deletions src/is_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,60 @@ func TestIsJson(t *testing.T) {
maxContentLength: 1024,
expectedResult: true,
},
{
name: "Request payload is an array at the root",
reqContentType: "",
reqBody: ``,
respContentType: "",
respBody: `[{"key": "value"}]`,
maxContentLength: 1024,
expectedResult: true,
},
{
name: "Request payload is an array at the root",
reqContentType: "",
reqBody: `[{"key": "value"}]`,
respContentType: "",
respBody: ``,
maxContentLength: 1024,
expectedResult: true,
},
{
name: "Request payload is an string at the root",
reqContentType: "",
reqBody: `"foo"`,
respContentType: "",
respBody: ``,
maxContentLength: 1024,
expectedResult: true,
},
{
name: "Request payload is a number at the root",
reqContentType: "",
reqBody: `3.14159`,
respContentType: "",
respBody: ``,
maxContentLength: 1024,
expectedResult: true,
},
{
name: "Request payload is a bool at the root",
reqContentType: "",
reqBody: `true`,
respContentType: "",
respBody: ``,
maxContentLength: 1024,
expectedResult: true,
},
{
name: "Request payload is null",
reqContentType: "",
reqBody: `null`,
respContentType: "",
respBody: ``,
maxContentLength: 1024,
expectedResult: true,
},
}

for _, tt := range tests {
Expand Down