Skip to content

Commit

Permalink
Remove the silliness :)
Browse files Browse the repository at this point in the history
December 28 has passed already
  • Loading branch information
shackra committed Jan 2, 2025
1 parent c4af553 commit 07ff8f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions pkg/uhttp/body_print.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package uhttp

// Implements a debugging facility for request responses. This changes
// the behavior of `BaseHttpClient` with an unexported flag.
//
// If you always wanted to see the actual body of your response, now
// you can 👁️👄👁️undress it🫦 to uncover all its... data!

import (
"io"
Expand All @@ -24,18 +21,18 @@ func (pr *printReader) Read(p []byte) (int, error) {
return n, err
}

func wrapBodyToUndress(body io.Reader) io.Reader {
func wrapPrintBody(body io.Reader) io.Reader {
return &printReader{reader: body}
}

type undressOption struct {
undress bool
type printBodyOption struct {
debugPrintBody bool
}

func (o undressOption) Apply(c *BaseHttpClient) {
c.debugPrintBody = o.undress
func (o printBodyOption) Apply(c *BaseHttpClient) {
c.debugPrintBody = o.debugPrintBody
}

func WithUndressBody(undress bool) WrapperOption {
return undressOption{undress: undress}
func WithPrintBody(shouldPrint bool) WrapperOption {
return printBodyOption{debugPrintBody: shouldPrint}
}
2 changes: 1 addition & 1 deletion pkg/uhttp/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (c *BaseHttpClient) Do(req *http.Request, options ...DoOption) (*http.Respo

// Replace resp.Body with a no-op closer so nobody has to worry about closing the reader.
if c.debugPrintBody {
resp.Body = io.NopCloser(wrapBodyToUndress(bytes.NewBuffer(body)))
resp.Body = io.NopCloser(wrapPrintBody(bytes.NewBuffer(body)))
} else {
resp.Body = io.NopCloser(bytes.NewBuffer(body))
}
Expand Down

0 comments on commit 07ff8f6

Please sign in to comment.