Skip to content

Commit 485a268

Browse files
authored
show headers in run (#70)
1 parent 5fe0941 commit 485a268

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

Diff for: render/http.go

+24-15
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (m httpRootModel) View() string {
123123
str += renderTests(req.tests, s)
124124
str += renderTestResponseVars(req.responseVariables)
125125
if req.results != nil && m.finalized {
126-
str += printHTTPResult(*req.results)
126+
str += printHTTPResult(req)
127127
}
128128
}
129129
if m.failure != nil {
@@ -135,22 +135,31 @@ func (m httpRootModel) View() string {
135135
return str
136136
}
137137

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)
141144
}
142145

143146
str := ""
144147

145-
str += fmt.Sprintf(" Response Status Code: %v\n", result.StatusCode)
148+
str += fmt.Sprintf(" Response Status Code: %v\n", req.results.StatusCode)
146149

147150
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
152158
}
153159
}
160+
if found {
161+
filteredHeaders[respK] = respV
162+
}
154163
}
155164

156165
if len(filteredHeaders) > 0 {
@@ -161,29 +170,29 @@ func printHTTPResult(result checks.HttpTestResult) string {
161170
}
162171

163172
str += " Response Body: \n"
164-
bytes := []byte(result.BodyString)
173+
bytes := []byte(req.results.BodyString)
165174
contentType := http.DetectContentType(bytes)
166175
if contentType == "application/json" || strings.HasPrefix(contentType, "text/") {
167176
var unmarshalled interface{}
168-
err := json.Unmarshal([]byte(result.BodyString), &unmarshalled)
177+
err := json.Unmarshal([]byte(req.results.BodyString), &unmarshalled)
169178
if err == nil {
170179
pretty, err := json.MarshalIndent(unmarshalled, "", " ")
171180
if err == nil {
172181
str += string(pretty)
173182
} else {
174-
str += result.BodyString
183+
str += req.results.BodyString
175184
}
176185
} else {
177-
str += result.BodyString
186+
str += req.results.BodyString
178187
}
179188
} else {
180189
str += fmt.Sprintf("Binary %s file", contentType)
181190
}
182191
str += "\n"
183192

184-
if len(result.Variables) > 0 {
193+
if len(req.results.Variables) > 0 {
185194
str += " Variables available: \n"
186-
for k, v := range result.Variables {
195+
for k, v := range req.results.Variables {
187196
if v != "" {
188197
str += fmt.Sprintf(" - %v: %v\n", k, v)
189198
} else {

0 commit comments

Comments
 (0)