Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colorize http requests and responses #343

Closed
gavv opened this issue Mar 22, 2023 · 3 comments
Closed

Colorize http requests and responses #343

gavv opened this issue Mar 22, 2023 · 3 comments
Assignees
Labels
feature New feature or request good first issue Good for newcomers help wanted Contributions are welcome
Milestone

Comments

@gavv
Copy link
Owner

gavv commented Mar 22, 2023

Follow-up for #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.1 it will highlight GET (method) and HTTP/1.1 (protocol)
    • in lines like HTTP/1.1 200 OK 229.642µs it will highlight HTTP/1.1 (protocol) and 200 OK (status code)
    • in lines like Host: 127.0.0.1:38681 it will highlight Host: (header field name)
  • the suggested color for highlighting is HiMagenta (in line with Colorize json values #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.

@gavv gavv added feature New feature or request help wanted Contributions are welcome good first issue Good for newcomers labels Mar 22, 2023
@gdguesser
Copy link
Contributor

Hey @gavv, can I take this one? 🙂

@gavv
Copy link
Owner Author

gavv commented Mar 22, 2023

Sure, thanks!

FillerFree pushed a commit to FillerFree/httpexpect that referenced this issue Apr 27, 2023
@FillerFree
Copy link

Hey @gavv can I pick this task if @gdguesser is not working on this?. I have made code changes for this. #414

@gavv gavv closed this as completed in 420f3ae Oct 3, 2023
@gavv gavv assigned FillerFree and unassigned gdguesser Oct 3, 2023
@gavv gavv added this to the v2 milestone Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request good first issue Good for newcomers help wanted Contributions are welcome
Projects
None yet
Development

No branches or pull requests

3 participants