File tree 1 file changed +14
-5
lines changed
1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,9 @@ package render
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "net/http"
6
7
"os"
8
+ "strings"
7
9
"sync"
8
10
"time"
9
11
@@ -138,14 +140,21 @@ func printHTTPResult(result checks.HttpTestResult) string {
138
140
str += fmt .Sprintf (" Response Status Code: %v\n " , result .StatusCode )
139
141
str += " Response Body: \n "
140
142
unmarshalled := map [string ]interface {}{}
141
- err := json .Unmarshal ([]byte (result .BodyString ), & unmarshalled )
142
- if err == nil {
143
- pretty , err := json .MarshalIndent (unmarshalled , "" , " " )
143
+ bytes := []byte (result .BodyString )
144
+
145
+ contentType := http .DetectContentType (bytes )
146
+ if contentType == "application/json" || strings .HasPrefix (contentType , "text/" ) {
147
+ err := json .Unmarshal ([]byte (result .BodyString ), & unmarshalled )
144
148
if err == nil {
145
- str += string (pretty )
149
+ pretty , err := json .MarshalIndent (unmarshalled , "" , " " )
150
+ if err == nil {
151
+ str += string (pretty )
152
+ }
153
+ } else {
154
+ str += result .BodyString
146
155
}
147
156
} else {
148
- str += fmt .Sprint ( result . BodyString )
157
+ str += fmt .Sprintf ( "Binary %s file" , contentType )
149
158
}
150
159
}
151
160
str += "\n "
You can’t perform that action at this time.
0 commit comments