HAR Adapter¶
Convert HAR (HTTP Archive) files to IR format.
Overview¶
HAR is a standard format supported by:
- Browser DevTools: Chrome, Firefox, Safari (Network tab → Save as HAR)
- Playwright: Built-in
recordHaroption - Charles Proxy: File → Export Session as HAR
- Fiddler: File → Export → HTTPArchive
- mitmproxy:
mitmdump --save-stream-file - Postman: Collection export
CLI Usage¶
# Convert a single HAR file
traffic2openapi convert har -i recording.har -o traffic.ndjson
# Convert multiple HAR files from a directory
traffic2openapi convert har -i ./har-files/ -o traffic.ndjson
# Filter by host
traffic2openapi convert har -i recording.har -o traffic.ndjson --host api.example.com
# Filter by method
traffic2openapi convert har -i recording.har -o traffic.ndjson --method POST
# Exclude headers from output
traffic2openapi convert har -i recording.har -o traffic.ndjson --headers=false
Capturing HAR Files¶
Browser DevTools¶
- Open DevTools (F12)
- Go to Network tab
- Perform your API operations
- Right-click in the network panel → "Save all as HAR with content"
Playwright¶
const context = await browser.newContext({
recordHar: { path: 'traffic.har', content: 'embed' }
});
await page.goto('https://api.example.com');
// ... perform actions ...
await context.close(); // HAR file written here
Charles Proxy¶
- File → Start Recording
- Perform API operations
- File → Export Session → HTTPArchive (.har)
Go Package Usage¶
import "github.com/grokify/traffic2openapi/pkg/adapters/har"
// Read HAR file
reader := har.NewReader()
records, err := reader.ReadFile("recording.har")
// Read directory of HAR files
records, err := reader.ReadDir("./har-files/")
// Parse HAR and filter
h, err := har.ParseFile("recording.har")
apiEntries := har.FilterByHost(h, "api.example.com")
postEntries := har.FilterByMethod(h, "POST")
Configuration¶
Header Filtering¶
By default, sensitive headers are excluded:
authorizationcookie/set-cookiex-api-keyx-auth-tokenx-csrf-tokenproxy-authorization
Customize:
reader := har.NewReader()
reader.Converter.IncludeHeaders = true
reader.Converter.FilterHeaders = []string{"authorization", "x-api-key"}