httpexpect
httpexpect copied to clipboard
Colorize http requests and responses
Follow-up for https://github.com/gavv/httpexpect/issues/159
Currently defaultFailureTemplate colorizes requests/responses as follows:
{{ .Request | indent | trim | color $.EnableColors "HiMagenta" }}
{{ .Response | indent | trim | color $.EnableColors "HiMagenta" }}
The following improvement is suggested:
- add new function "colorhttp" to defaultTemplateFuncs and use it for request and response
- if colors are disabled, the function will return original value
- the function will apply the following colorization:
- in lines like
GET /test HTTP/1.1it will highlightGET(method) andHTTP/1.1(protocol) - in lines like
HTTP/1.1 200 OK 229.642µsit will highlightHTTP/1.1(protocol) and200 OK(status code) - in lines like
Host: 127.0.0.1:38681it will highlightHost:(header field name)
- in lines like
- the suggested color for highlighting is HiMagenta (in line with #334)
Example for testing:
$ FORCE_COLOR=1 go test -v -run TestE2EReport_Names
=== RUN TestE2EReport_Names
e2e_report_test.go:52:
invalid "Content-Type" response header
mime: no media type
test name: TestExample
request name: RequestExample
request: GET /test HTTP/1.1
Host: 127.0.0.1:35779
response: HTTP/1.1 200 OK 246.75µs
Date: Wed, 22 Mar 2023 18:38:49 GMT
Content-Length: 0
assertion:
Request("GET").Expect().JSON()
actual value:
""
--- PASS: TestE2EReport_Names (0.00s)
PASS
ok github.com/gavv/httpexpect/v2 0.003s
Related: #334, #335.
Hey @gavv, can I take this one? 🙂
Sure, thanks!
Hey @gavv can I pick this task if @gdguesser is not working on this?. I have made code changes for this. https://github.com/gavv/httpexpect/pull/414