Documentation
¶
Overview ¶
Package httpx holds small HTTP helpers shared by the Microsoft admin REST clients: request correlation IDs, a uniform API error with a not-found check, and response-body decompression.
These clients set Accept-Encoding themselves for wire fidelity (so net/http does not auto-decompress) and the services negotiate brotli, gzip and deflate — so decoding is centralised here. This is the one place go-msadmin takes a dependency (a pure-Go brotli decoder); everything else stays dependency-free.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DebugEnabled ¶ added in v0.3.0
func DebugEnabled() bool
DebugEnabled reports whether full HTTP request/response logging is on. It is enabled when Terraform's log level is DEBUG or TRACE (via TF_LOG or the provider-scoped TF_LOG_PROVIDER), or when MSADMIN_HTTP_DEBUG is set to any non-empty value (a standalone toggle for non-Terraform callers/tests).
func DecodeBody ¶
DecodeBody reads resp.Body (closing it) and returns the decompressed bytes, honouring Content-Encoding: br | gzip | deflate. It is defensive — some error responses advertise gzip yet aren't — so on any decode failure it falls back to the raw bytes rather than erroring.
func IsNotFound ¶
IsNotFound reports whether err (or anything it wraps) is an APIError with HTTP 404 — i.e. a missing object. Terraform providers wire their isNotFound to this.
func NewCorrelationID ¶
func NewCorrelationID() string
NewCorrelationID returns a random RFC-4122 v4 GUID (lowercase), suitable for the per-request correlation headers these APIs expect (client-request-id, X-MS-Correlation-Id, …).
Types ¶
type APIError ¶
type APIError struct {
Status int // HTTP status code
Code string // service error code, if any
Message string // human-readable message
Body string // raw response body (truncated by the client), for debugging
}
APIError is a non-2xx response from a Microsoft admin API. Clients parse their own error envelope into it; consumers use IsNotFound (and errors.As) uniformly.
type DebugTransport ¶ added in v0.3.0
type DebugTransport struct {
Base http.RoundTripper // nil -> http.DefaultTransport
Out io.Writer // nil -> os.Stderr
// Enabled overrides the env-based check; nil -> DebugEnabled. For tests.
Enabled func() bool
}
DebugTransport is an http.RoundTripper that logs the full request and response — method, URL, headers (with credentials redacted), and body — when DebugEnabled reports true; otherwise it is a transparent pass-through. Response bodies are decompressed for display (br/gzip/deflate), and the response handed downstream is left byte-for-byte unchanged.
Wrap it as the base of retry.NewTransport so every attempt (and the service discovery handshake) is logged:
client := &http.Client{Transport: retry.NewTransport(httpx.NewDebugTransport(nil), cfg)}
func NewDebugTransport ¶ added in v0.3.0
func NewDebugTransport(base http.RoundTripper) *DebugTransport
NewDebugTransport wraps base (nil -> http.DefaultTransport) with debug logging.