@@ -123,7 +123,7 @@ func (m httpRootModel) View() string {
123
123
str += renderTests (req .tests , s )
124
124
str += renderTestResponseVars (req .responseVariables )
125
125
if req .results != nil && m .finalized {
126
- str += printHTTPResult (* req . results )
126
+ str += printHTTPResult (req )
127
127
}
128
128
}
129
129
if m .failure != nil {
@@ -135,22 +135,31 @@ func (m httpRootModel) View() string {
135
135
return str
136
136
}
137
137
138
- func printHTTPResult (result checks.HttpTestResult ) string {
139
- if result .Err != "" {
140
- return fmt .Sprintf (" Err: %v\n \n " , result .Err )
138
+ func printHTTPResult (req httpReqModel ) string {
139
+ if req .results == nil {
140
+ return ""
141
+ }
142
+ if req .results .Err != "" {
143
+ return fmt .Sprintf (" Err: %v\n \n " , req .results .Err )
141
144
}
142
145
143
146
str := ""
144
147
145
- str += fmt .Sprintf (" Response Status Code: %v\n " , result .StatusCode )
148
+ str += fmt .Sprintf (" Response Status Code: %v\n " , req . results .StatusCode )
146
149
147
150
filteredHeaders := make (map [string ]string )
148
- for respK , respV := range result .ResponseHeaders {
149
- for reqK := range result .Request .Request .Headers {
150
- if strings .ToLower (respK ) == strings .ToLower (reqK ) {
151
- filteredHeaders [respK ] = respV
151
+ for respK , respV := range req .results .ResponseHeaders {
152
+ // only show headers that are tested
153
+ found := false
154
+ for _ , test := range req .tests {
155
+ if strings .Contains (test .text , respK ) {
156
+ found = true
157
+ break
152
158
}
153
159
}
160
+ if found {
161
+ filteredHeaders [respK ] = respV
162
+ }
154
163
}
155
164
156
165
if len (filteredHeaders ) > 0 {
@@ -161,29 +170,29 @@ func printHTTPResult(result checks.HttpTestResult) string {
161
170
}
162
171
163
172
str += " Response Body: \n "
164
- bytes := []byte (result .BodyString )
173
+ bytes := []byte (req . results .BodyString )
165
174
contentType := http .DetectContentType (bytes )
166
175
if contentType == "application/json" || strings .HasPrefix (contentType , "text/" ) {
167
176
var unmarshalled interface {}
168
- err := json .Unmarshal ([]byte (result .BodyString ), & unmarshalled )
177
+ err := json .Unmarshal ([]byte (req . results .BodyString ), & unmarshalled )
169
178
if err == nil {
170
179
pretty , err := json .MarshalIndent (unmarshalled , "" , " " )
171
180
if err == nil {
172
181
str += string (pretty )
173
182
} else {
174
- str += result .BodyString
183
+ str += req . results .BodyString
175
184
}
176
185
} else {
177
- str += result .BodyString
186
+ str += req . results .BodyString
178
187
}
179
188
} else {
180
189
str += fmt .Sprintf ("Binary %s file" , contentType )
181
190
}
182
191
str += "\n "
183
192
184
- if len (result .Variables ) > 0 {
193
+ if len (req . results .Variables ) > 0 {
185
194
str += " Variables available: \n "
186
- for k , v := range result .Variables {
195
+ for k , v := range req . results .Variables {
187
196
if v != "" {
188
197
str += fmt .Sprintf (" - %v: %v\n " , k , v )
189
198
} else {
0 commit comments