-
Notifications
You must be signed in to change notification settings - Fork 32
feat: http debug transport #37
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to rework it a bit
78248a6 to
0ded7cf
Compare
|
I may want to do some additional things to handle body printing differently |
| // Add body as raw | ||
| body := strings.TrimSpace(bodyBuilder.String()) | ||
| if body != "" { | ||
| payload["Body"] = body | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I would expect the body to be decoded as JSON in payload["Body_JSON"] it would help, having the body is not that useful, especially when dumped on one line with truncation
| // Add body as raw | |
| body := strings.TrimSpace(bodyBuilder.String()) | |
| if body != "" { | |
| payload["Body"] = body | |
| } | |
| // Add body as raw | |
| body := strings.TrimSpace(bodyBuilder.String()) | |
| if body != "" { | |
| payload["Body"] = body | |
| var rawJSON any | |
| if err := json.Unmarshal(body, &rawJSON); err == nil { | |
| payload["Body_JSON"] = rawJSON | |
| } | |
| } |
Or maybe this
| // Add body as raw | |
| body := strings.TrimSpace(bodyBuilder.String()) | |
| if body != "" { | |
| payload["Body"] = body | |
| } | |
| // Add body as raw | |
| body := strings.TrimSpace(bodyBuilder.String()) | |
| if body != "" { | |
| payload["Body"] = body | |
| var rawJSON any | |
| if err := json.Unmarshal(body, &rawJSON); err == nil { | |
| payload["Body"] = rawJSON | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code that is here doesn't make any sense. The last main remaining action item of this PR is to address body printing which I'll do at a later point. I'm not in a rush to merge this.
| for k := range headers { | ||
| keys = append(keys, k) | ||
| } | ||
| sort.Strings(keys) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sort.Strings is somehow deprecated
Note: as of Go 1.22, this function simply calls slices.Sort.
use slices.Sort
| sort.Strings(keys) | |
| slices.Sort(keys) |
I was working on a client project and needed the ability to print HTTP requests and found myself creating this quickly.
It works when environment variable
HTTP_DEBUGis set, users can also set it through a setter method as well.It works by wrapping your provided transport (or default transport)
Before
After
Example Code