Skip to main content

Module har

Module har 

Source
Expand description

HAR recording/replay (route_from_har).

This module parses HAR 1.2 files (the HTTP Archive format) and produces a set of canned route responses. The [BrowserContext::route_from_har] call turns each HAR entry into a context-level route handler that, on a matching request, serves the recorded response via Route::fulfill and lets non-matching requests fall through to the network.

§Scope

Replay is fully implemented. Recording (capturing live traffic into a new HAR file) is deferred — HarRecorder exists as a thin writer that can append entries, but wiring it into the live request stream of every page is not yet done. See the report notes.

The parsing structs lean heavily on #[serde(default)] because real-world HAR files are messy: fields are frequently missing or carry unexpected types.

Structs§

Har
The top-level HAR document: { "log": { ... } }.
HarContent
Response body payload + mime.
HarCookie
{ "name": "...", "value": "..." } cookie (comment/domain/etc tolerated).
HarCreator
log.creator / log.browser.
HarEntry
One request/response pair.
HarHeader
{ "name": "...", "value": "..." } header.
HarLog
The log object. Only entries is consulted for replay; creator / browser / pages are tolerated but ignored.
HarPage
log.pages[*] (page-level timing metadata). Parsed for tolerance only.
HarPostData
request.postData.
HarQuery
{ "name": "...", "value": "..." } query parameter.
HarRecorder
A minimal HAR recorder: builds a Har in memory and can write it to disk.
HarRequest
A recorded request.
HarResponse
A recorded response.
HarRoute
A single HAR-derived route: the request signature to match against and the canned response to serve.
RouteFromHarOptions
Options for route_from_har, mirroring Playwright’s RouteFromHarOptions.

Functions§

routes_from_har
Parse a HAR file from disk and produce one HarRoute per usable entry.