8.5 KiB
Traffic HAR 1.2 Import and Export
ARTEX supports importing and exporting captured HTTP traffic using the HAR 1.2 JSON format so operators can bring captures from browser DevTools or external proxies into the Traffic store and export filtered subsets out of ARTEX.
Both routes require the standard administrator JWT (Authorization: Bearer <token>) like the rest of /api/traffic, and return 503 when the traffic store is unavailable.
Import: POST /api/traffic/import/har
Request format
Send a raw HAR 1.2 JSON document directly as the HTTP request body (Content-Type: application/json), capped at the standard API JSON body limit (32 MiB; oversized bodies return 413 Request Entity Too Large).
curl -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
--data-binary @capture.har \
http://127.0.0.1:8787/api/traffic/import/har
The Traffic page also provides an Import HAR file picker (with the same 32 MiB limit) that reads a .har / .json file, posts it to this endpoint, displays loading/error state and a count summary, and refreshes the table.
Validation & error handling
The request is rejected with 400 Bad Request naming the reason when:
- the body is empty or malformed JSON (including trailing content after the root object),
- the
logobject is missing, log.versionis not"1.2",log.entriesis missing ornull,log.entriesexceeds the per-import entry cap (2000entries).
Individual malformed entries (invalid startedDateTime, non-HTTP(S) URL, invalid HTTP method, header/cookie names or values containing CR/LF/NUL, out-of-range status, invalid base64 or unsupported body encoding) do not fail the whole import: they are counted in failed and reported in errors (up to 50 error details) while valid entries continue importing. HTTP/2 pseudo-headers starting with : (such as :authority or :method from browser DevTools) are skipped cleanly.
Response
{
"imported": 12,
"skipped": 3,
"failed": 1,
"truncated": false,
"errors": [
{ "index": 4, "url": "notaurl", "reason": "invalid request url \"notaurl\"" }
]
}
Deterministic IDs, round-trip fidelity, & idempotence
- ARTEX exports (
_artexExchangeId): Every entry exported by ARTEX carries the HAR 1.2 custom field_artexExchangeIdset to the exchange's stored ID. When a valid_artexExchangeId([A-Za-z0-9._:-], 1–128 chars) is present on import, ARTEX preserves it. This guarantees that two distinct ARTEX exchanges recorded within the same second with identical method, URL, status, and bodies do not collapse into one row when imported into a fresh store, and that re-importing an export into the source store stays idempotent (skipped). - External HARs (no
_artexExchangeId): Each entry receives a deterministic content-based ID:
har-<hex(sha256(ts_unix_seconds + NUL + METHOD + NUL + canonical_url + NUL + status + NUL + sha256(req_body) + NUL + sha256(resp_body)))>
ts_unix_seconds is startedDateTime parsed as RFC 3339 and truncated to UTC Unix seconds (matching exchanges.ts). Re-importing the same external HAR skips existing IDs (INSERT OR IGNORE, hot rows always win). Identical entries in the same external HAR sharing (ts_unix_seconds, method, canonical_url, status, req_body, resp_body) are deduplicated (the first is imported, duplicates are counted in skipped).
Storage, bodies, cookies, postData.params, and userinfo
- URL userinfo: Any
user:pass@userinfo inrequest.urlis stripped before storing, indexing, listing, exporting, or reporting errors (matching ARTEX's asset store). hostis derived fromURL.Hostname()andurl_templatefromdb.TemplatePath(URL.EscapedPath());pathstays empty.- Bodies & base64:
response.content.textandrequest.postData.textare stored as raw UTF-8 bytes whenencodingis empty, and decoded via standard base64 whenencodingis"base64". Whenrequest.postData.textis empty andrequest.postData.paramsis populated, ARTEX reconstructs the form body asapplication/x-www-form-urlencoded(preserving parameter order). - Cookies arrays: When
request.headersdoes not already include aCookieheader andrequest.cookiesis non-empty, ARTEX synthesizes aCookieheader fromrequest.cookies. Likewise, whenresponse.headersdoes not already include aSet-Cookieheader andresponse.cookiesis non-empty, ARTEX synthesizesSet-Cookieheaders fromresponse.cookies. When the headers are already present, they are kept as-is without duplication. req_lenandresp_lenrecord the actual decoded byte lengths.content_typecomes fromresponse.content.mimeType(falling back to the responseContent-Typeheader).- Bodies larger than the 256 KiB inline threshold spill to the content-addressed blob store (
_blobs/sha256/...) withblob_refsrows, and searchable text bodies are added to theex_ftsfull-text index — identical to proxy capture andImportArchive.
Capture rewrite rules are NOT applied
HAR import writes directly to the traffic store without passing through the MITM capture proxy. Capture rewrite rules are never applied to imported exchanges, no exchange_rewrites rows are created, and imported rows always have rewritten: false.
Import limits
| Limit | Default | Behavior when exceeded |
|---|---|---|
| Raw HTTP request body | 32 MiB | 413 Request Entity Too Large |
| Entries per HAR | 2,000 | 400 Bad Request |
| Total decoded request + response body bytes | 32 MiB | Stops importing remaining entries, sets "truncated": true, counts remaining entries in skipped, and appends an explanatory item in errors. |
Export: GET /api/traffic/export/har
Request & filters
Returns an application/json HAR 1.2 document (Content-Disposition: attachment; filename="artex-traffic.har") ordered deterministically by (ts ASC, id ASC).
It reuses the same filter parser and SQL predicate builder as GET /api/traffic, supporting:
host,method,path,status,q,body,rewritten(all|rewritten|original|true|false),resp_min,resp_max.
HAR 1.2 compliance & unknown placeholders
log.versionis"1.2"andlog.creatoris{"name": "ARTEX", "version": "<build-version>"}.startedDateTimeis formatted fromexchanges.tsas UTC RFC 3339, and_artexExchangeIdcarries the exchange's stored ID.- Request and response headers are parsed from the stored raw heads (
req_head/resp_head). ARTEX does not inventserverIPAddressor headers that are not present in the store. - Required HAR 1.2 fields whose values are not recorded by ARTEX are emitted with explicit unknown placeholders rather than fabricated measurements:
entry.time:0entry.cache:{}entry.timings:{"send": -1, "wait": -1, "receive": -1}(unknown/unavailable per HAR 1.2)request.cookies,request.queryString,response.cookies:[]request.headersSize,response.headersSize:-1(unknown per HAR 1.2)response.redirectURL:""
- Bodies are read in full from inline columns or spilled blobs: valid NUL-free UTF-8 bodies are emitted as plain
text, and binary / non-UTF-8 bodies are emitted withencoding: "base64".
Export limits, import-compatibility invariant, & truncation reporting
| Limit | Default | truncatedReason |
|---|---|---|
| Exported entries | 1,000 | max_entries |
| Total raw request + response headers and bodies | 20 MiB | max_bytes |
| Marshaled JSON size backstop | 31 MiB | max_bytes |
Cap invariant: Every HAR produced by GET /api/traffic/export/har fits inside POST /api/traffic/import/har's 32 MiB HTTP body limit (and the Traffic page's 32 MiB file limit). Raw headers and bodies are capped at 20 MiB so worst-case base64 expansion (4/3x ≈ 26.7 MiB) plus JSON structure stays comfortably under 32 MiB, backed by an explicit 31 MiB marshaled-JSON cap so even heavily JSON-escaped payloads cannot trigger a 413 on re-import.
Truncation is never silent. Every export reports it in both HTTP response headers and HAR 1.2 custom (_-prefixed) log fields:
- Headers:
X-ARTEX-HAR-Truncated: true|falseX-ARTEX-HAR-Truncated-Reason: max_entries|max_bytes(when truncated)X-ARTEX-HAR-Exported: <count>X-ARTEX-HAR-Matched: <total matching rows>
- JSON (
logobject, omitted when not truncated):_truncated: true_truncatedReason: "max_entries" | "max_bytes"_totalMatched: <total matching rows>