Created
April 28, 2023 10:49
-
-
Save nsrCodes/87a6284c78131e919574c00a1bf5d2ed to your computer and use it in GitHub Desktop.
Typescript interfaces for working with the HAR v1.2. Based on https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Based on Har v1.2 | |
* | |
* Detailed specification references can be founnd at: | |
* http://www.softwareishard.com/blog/har-12-spec/ | |
* https://github.com/ahmadnassri/har-spec | |
* | |
* Note: All the optional attributes in the interfaces | |
* are also optional in the spec | |
*/ | |
/* CORE */ | |
interface Har { | |
log: { | |
version: string | |
creator: Creator | |
browser?: Creator | |
pages?: Page[] | |
entries: Entry[] | |
comment?: string | |
} | |
} | |
// The array of entries is sorted | |
// by startedDateTime (starting from the oldest) | |
// | |
// startedDateTime is base on ISO 8601 -> https://en.wikipedia.org/wiki/ISO_8601 | |
// example -> "2009-04-16T12:07:25.123+01:00" | |
// can be generated with -> (new Date()).toISOString() | |
interface Entry { | |
pageref?: Page["id"] // unique string | |
startedDateTime: string, | |
time: number, // elapsed time | |
request: HarRequest, | |
response: HarResponse, | |
cache: CacheEntry, | |
timings: Timing, | |
comment?: string | |
serverIPAddress?: string | |
connection?: string | |
} | |
/* REQUEST */ | |
interface HarRequest { | |
method: string | |
url: string | |
httpVersion: string | |
cookies: HarCookie[] | |
headers: Header[] | |
queryString: RequestQueryParam[] | |
postData?: PostRequestData | |
headersSize: number | |
bodySize: number | |
comment?: string | |
} | |
interface PostRequestData { | |
mimeType: string | |
params: PostRequestParams[] | |
text: string | |
comment?: string | |
} | |
interface PostRequestParams { | |
name: string | |
value?: string | |
fileName?: string | |
contentType?: string | |
comment?: string | |
} | |
/* RESPONSE */ | |
interface HarResponse { | |
status: number | |
statusText: string | |
httpVersion: string | |
cookies: HarCookie[] | |
headers: Header[] | |
content: ResponseContent | |
redirectUrl: string | |
headersSize: number | |
bodySize: number | |
comment?: string | |
} | |
interface ResponseContent { | |
size: number | |
compression?: number | |
mimeType: string | |
text?: string | |
encoding?: string | |
comment?: string | |
} | |
/* COMMON */ | |
interface HarCookie { | |
name: string | |
value: string | |
path?: string | |
domain?: string | |
expires?: string // ISO 8601 | |
httpOnly?: boolean | |
secure?: boolean | |
comment?: string | |
} | |
interface Page { | |
startedDateTime: string // ISO 8601 | |
id: string | |
title: string | |
pageTimings?: HarPageTimings | |
comment?: string | |
} | |
interface HarPageTimings { | |
onContentLoaded?: number | |
onLoad?: number | |
comment?: string | |
} | |
type RequestQueryParam = NameValueEntry | |
type Header = NameValueEntry | |
interface NameValueEntry { | |
name: string, | |
value: string, | |
comment?: string | |
} | |
type Browser = NameVersionEntry | |
type Creator = NameVersionEntry | |
interface NameVersionEntry { | |
name: string | |
version: string | |
comment?: string | |
} | |
/* SUPPORTING CORE ATTRIBUTES */ | |
interface Timing { | |
blocked?: number | |
dns?: number | |
connect?: number | |
send: number | |
wait: number | |
recieve: number | |
ssl?: number | |
comment?: string | |
} | |
interface CacheEntry { | |
beforeRequest?: HarRequestCache | |
afterRequest?: HarRequestCache | |
comment?: string | |
} | |
interface HarRequestCache { | |
expires?: string | |
lastAccess: string | |
eTag: string | |
hitCount: number | |
comment?: string | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment