Class BowireHarConverter
- Namespace
- Kuestenlogik.Bowire.Mocking
- Assembly
- Kuestenlogik.Bowire.dll
Maps HAR 1.2 documents to BowireRecording instances.
HAR is a well-specified browser-trace format produced by Chrome / Firefox
DevTools, Charles, Fiddler, Postman, and Playwright (browser.newContext({
recordHar })). Every entries[] element pairs one HTTP request
with its response — exactly what a Bowire REST recording step holds. The
mapping is one-to-one for unary REST traffic; streaming / WebSocket / gRPC
frames inside a HAR are out of scope (HAR has no native shape for them and
the Bowire native recorder covers those protocols directly).
Symmetric to exportRecordingAsHar in the workbench: a recording
exported as HAR and re-imported via this class round-trips the unary REST
steps. Lossy fields (cache, timings, page IDs, server IPs)
are intentionally dropped — the recording format only carries what the
mock replayer needs.
Lives in Kuestenlogik.Bowire (core) so both the CLI (bowire
import har) and the MCP tool (bowire.har.import) can call it
without depending on the CLI host project. The Tool's HarImporter
wraps this with file-IO + exit-code shape for the CLI.
public static class BowireHarConverter
- Inheritance
-
BowireHarConverter
- Inherited Members
Fields
RedactedPlaceholder
Placeholder written in place of a redacted header value.
public const string RedactedPlaceholder = "***redacted***"
Field Value
Methods
Convert(string, string?)
Parse a HAR document and return a fresh BowireRecording.
Throws BowireHarImportException with a user-facing
message on any structural problem (missing log, malformed
entries, …).
public static BowireRecording Convert(string harJson, string? recordingName = null)
Parameters
harJsonstringHAR 1.2 document content.
recordingNamestringOptional name for the resulting recording. Defaults to the HAR's
creator.name— or the literal"Imported HAR"when the creator field is missing.
Returns
Convert(string, string?, bool)
Parse a HAR document into a BowireRecording, optionally stripping credential-bearing headers (#186).
public static BowireRecording Convert(string harJson, string? recordingName, bool redactSecrets)
Parameters
harJsonstringHAR 1.2 document content.
recordingNamestringSee the other overload.
redactSecretsboolWhen
true, header values in Kuestenlogik.Bowire.Mocking.BowireHarConverter.SensitiveHeaders (Authorization, Cookie, X-Api-Key, …) are replaced with RedactedPlaceholder on both request + response steps — so a HAR captured against production can be imported without persisting live tokens / session cookies into a recording file.
Returns
DeriveGrpcServiceAndMethod(string)
Derive a (service, method) pair from a gRPC-Web request path. The
wire shape is always /package.Service/Method, so the last
two path segments map straight onto service + method — no id
heuristics needed. Falls back to a grpc catch-all service
for malformed paths so the step still lands somewhere visible.
public static (string Service, string Method) DeriveGrpcServiceAndMethod(string path)
Parameters
pathstring
Returns
DeriveServiceAndMethod(string, string)
Derive a (service, method) pair from a request path. Heuristics:
last meaningful path segment becomes the method name; the segment
before that becomes the service. GET /users/42 →
(users, GET_42) — but pure-numeric segments fall back to the
verb-prefixed name to avoid ID-as-method noise. Empty paths use
"http" as the catch-all service.
public static (string Service, string Method) DeriveServiceAndMethod(string path, string verb)
Parameters
Returns
DetectAuthHeaders(string)
Scan a HAR document and return the distinct credential-bearing header names it contains (canonical casing from Kuestenlogik.Bowire.Mocking.BowireHarConverter.SensitiveHeaders), sorted. Lets the importer surface "this trace carries an Authorization / Cookie header — redact it, or feed it into auth-recording (#190)" without the operator eyeballing raw JSON. Best-effort: returns an empty list for malformed input rather than throwing.
public static IReadOnlyList<string> DetectAuthHeaders(string harJson)
Parameters
harJsonstring
Returns
SplitUrl(string)
Pull the path + (optional) host out of a URL. Relative URLs in HAR are
rare but legal — those land with host as null and the
matcher only keys on the path.
public static (string Path, string? Host) SplitUrl(string url)
Parameters
urlstring
Returns
ToHar(BowireRecording, string?)
Export a BowireRecording back to a HAR 1.2 document — the
inverse of Convert(string, string?) for the unary REST/
gRPC-Web steps it round-trips (#39). Deterministic: headers are sorted by
name and timestamps derive from the step's captured time, so
ToHar(Convert(har)) is stable and golden-testable. Lossy fields the
import already drops (cache / timings detail / page IDs) are emitted as
their conventional empty shapes.
public static string ToHar(BowireRecording recording, string? creatorName = null)
Parameters
recordingBowireRecordingcreatorNamestring