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

Tee request/response body #13

Open
VojtechVitek opened this issue Mar 17, 2025 · 0 comments
Open

Tee request/response body #13

VojtechVitek opened this issue Mar 17, 2025 · 0 comments

Comments

@VojtechVitek
Copy link
Contributor

It'd be nice to have a transport that would be able to "tee" request or response body into a bytes.Buffer on a per-request basis.

This could be used for debugging or to enhance errors returned by external HTTP client packages.

httpClient := http.Client{
    Transport: transport.Chain(
        http.DefaultTransport,
        transport.Tee,
    ),
    Timeout: 15 * time.Second,
}

// Enable debugging:
var reqBody bytes.Buffer
var respBody bytes.Buffer
ctx = transport.TeeRequestBody(ctx, &reqBody)
ctx = transport.TeeResponseBody(ctx, &respBody)

httpClient.Get(ctx, "https://example.com")

Perhaps we could reuse the very same logic even for request/response logging using
transport.LogRequests(transport.LogOptions{Concise: true, CURL: true}).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant