httpdebug

package
v0.11.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package httpdebug logs HTTP request / response traffic for developer-facing debugging while redacting credentials.

Three redaction layers run independently:

  • sensitive headers (Authorization, Proxy-Authorization) collapse to a placeholder before any header dump is written;
  • URL userinfo (user@ or user:pass@) is stripped from any text run through RedactURLCredentials, covering Location headers and HTML redirect bodies;
  • JSON token fields (access_token, id_token, refresh_token, subject_token) — the shapes the STS / OAuth endpoints return — collapse to the placeholder.

The redactors run in that order in BodyPreview. Truncation comes last: if a long JWT or URL password extends past the preview boundary, truncating first would leave the regex's terminator outside the slice and silently leak the secret. Tests in this package pin the order.

Index

Constants

View Source
const Placeholder = "***REDACTED***"

Placeholder replaces any redacted value in dumps.

View Source
const PreviewBytes = 512

PreviewBytes is the upper bound on the size of a body preview written to the log. Anything beyond is truncated.

Variables

View Source
var SensitiveHeaders = map[string]struct{}{
	"Authorization":       {},
	"Proxy-Authorization": {},
}

SensitiveHeaders carries credentials we never want to log verbatim. Stored by canonical key so RedactHeaders can do a single map lookup per header.

Functions

func BodyPreview

func BodyPreview(body []byte) []byte

BodyPreview returns the first PreviewBytes of body after URL + JSON-token redaction. Redaction MUST happen before truncation: a long JWT or URL password can extend past PreviewBytes, leaving its terminator (closing quote or `@`) outside the preview slice and out of reach of the regexes — truncate-first silently leaks the secret.

When the body contains a packfile, the preview ends just after the PACK signature so the rest of the binary stream doesn't flood the log.

func RedactHeaders

func RedactHeaders(h http.Header) http.Header

RedactHeaders returns a copy of h with values for SensitiveHeaders replaced by Placeholder. The input is not mutated — callers still need the real headers on the live request/response.

func RedactJSONTokens

func RedactJSONTokens(body []byte) []byte

RedactJSONTokens replaces JWT values inside a JSON body with Placeholder. Bodies that aren't JSON (or don't carry token fields) pass through unchanged.

func RedactURLCredentials

func RedactURLCredentials(s []byte) []byte

RedactURLCredentials replaces the userinfo of any http/https URL in s with Placeholder. Safe to run over arbitrary text — header dumps, HTML bodies, log lines.

Types

type RoundTripper

type RoundTripper struct {
	Next http.RoundTripper
}

RoundTripper wraps another http.RoundTripper and logs each request/response when debuglog.Enabled returns true. Bodies and sensitive headers are redacted before logging.

When debugging is off, the wrapper is a thin pass-through: no allocations, no body buffering.

func (*RoundTripper) RoundTrip

func (d *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper. Response bodies are read in full (so the preview can render correctly) and re-wrapped before returning — the caller sees an io.ReadCloser as before. This is a debug-only cost; non-debug mode skips the read entirely.

type TimingRoundTripper added in v0.8.0

type TimingRoundTripper struct {
	Next http.RoundTripper
	// Label distinguishes the client the request rode on (e.g. "auth", "git").
	Label string
}

TimingRoundTripper logs one ENTIRE_DEBUG-gated line per request with the wall-clock time to response headers and a breakdown of where it went:

conn=new|reused  whether the request rode a pooled connection
dns_ms           name resolution (absent for IP literals and reused conns)
connect_ms       TCP connect (absent for reused conns)
tls_ms           TLS handshake (absent for reused conns and plain HTTP)
ttfb_ms          request fully written to first response byte, i.e. one
                 round trip plus server processing time

dur_ms stays the last field so line-oriented tooling can read it with $NF. Bodies stream after RoundTrip returns, so transfer time is not included unless a wrapper below this one buffers the body (httpdebug.RoundTripper does under ENTIRE_DEBUG).

func (*TimingRoundTripper) RoundTrip added in v0.8.0

func (t *TimingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL