http_gun/redaction

Decides which request and response data cassettes never store.

default() removes the credential headers authorization, proxy-authorization, cookie, set-cookie, x-api-key, api-key and x-goog-api-key. Add your own secrets, then pass the redaction to config.with_redaction:

let redaction =
  redaction.default()
  |> redaction.with_headers(["x-signature"])
  |> redaction.with_query_parameters(["token"])
  |> redaction.with_body(fn(bytes) { scrub_card_numbers(bytes) })
config.default() |> config.with_redaction(redaction)

A recording client stores requests and responses with the redaction applied: listed headers are removed, listed query parameters keep their name with the value REDACTED, and the body function rewrites request bodies and whole response bodies. A playback client applies the same redaction to the scripted request and to each incoming request before comparing them, so a recorded cassette matches the live code that made it. The live request on the network is never changed.

Failures and telemetry events never contain a URL, query or body, nor a request header. A send or batch failure after the response head arrived keeps the response headers (error.headers) with the listed headers removed. A waiting request’s headers are held in a closure that crash reports print as a function reference.

Types

What to remove from stored exchanges. Credential headers are always removed; the functions below only add to the list.

pub opaque type Redaction

Values

pub fn body(redaction: Redaction, bytes: BitArray) -> BitArray

Apply the body function, if any.

pub fn default() -> Redaction

Remove the credential headers. Query parameters and bodies are kept.

pub fn headers(
  redaction: Redaction,
  headers: List(#(String, String)),
) -> List(#(String, String))

Remove the redacted headers from a header list.

pub fn request(
  redaction: Redaction,
  req: request.Request(BitArray),
) -> request.Request(BitArray)

Apply the redaction to a request: remove headers, replace query values and rewrite the body.

pub fn rewrites_bodies(redaction: Redaction) -> Bool

Whether this redaction rewrites bodies.

pub fn with_body(
  redaction: Redaction,
  redact: fn(BitArray) -> BitArray,
) -> Redaction

Rewrite stored bodies with redact: each request body, and each response body as a whole. A recording buffers a response body until it ends, within the recording’s byte budget, and stores the rewritten body as one chunk, so a secret split across chunks is still seen whole. Playback applies redact to the scripted and the incoming request bodies before comparing. Calling it again replaces the function.

pub fn with_headers(
  redaction: Redaction,
  names: List(String),
) -> Redaction

Also remove these headers, compared without case, from stored requests and responses, including trailers, and from the response headers a failure keeps.

pub fn with_query_parameters(
  redaction: Redaction,
  names: List(String),
) -> Redaction

Replace the value of these query parameters with REDACTED, compared by exact, percent-decoded name. The parameter order and every other byte of the query stay as sent.

✨ Search Document