Expands HTTP Archive (HAR) objects with helpful utility properties and a sprinkle of magic.
Utility Properties
Request
- creates a new property
queryObj
as a standard object fromqueryString
array - creates a new property
headersObj
as a standard object fromheaders
array - creates a new property
cookieObj
as a standard object fromcookies
array - parses
url
property for any query string params and adds them toqueryString
&queryObj
- creates a new property
fullUrl
by combiningurl
withqueryString
- creates a new property
uriObj
by parsingfullUrl
- restores
url
to queryString-less state after parsing - creates a new property
postData.jsonObj
from parsingreq.postData.text
with appropriate mimeType - creates a new property
postData.paramsObj
frompostData.params
array - creates a new property
postData.paramsObj
from parsingreq.postData.text
with appropriate mimeType (multipart/form-data
,application/x-www-form-urlencoded
)
Response
- creates a new property
headersObj
as a standard object fromheaders
array - creates a new property
cookieObj
as a standard object fromcookies
array - creates a new property
redirectURLObj
by parsingredirectURL
- creates a new property
content.jsonObj
from parsingreq.postData.text
with appropriate mimeType
Example
Before
{
"log": {
"version": "1.2",
"creator": {
"name": "har-expander",
"version": "1.0"
},
"entries": [
{
"startedDateTime": "2015-02-10T07:33:17.146Z",
"time": 110,
"request": {
"method": "GET",
"url": "http://mockbin.com/har?key=value",
"httpVersion": "HTTP/1.1",
"headers": [
{ "name": "Host", "value": "mockbin.com" },
{ "name": "Connection", "value": "keep-alive" }
],
"queryString": [
{ "name": "foo", "value": "bar"}
],
"cookies": [
{ "name": "foo", "value": "bar" }
],
"headersSize": 0,
"bodySize": 0
},
"response": {
"status": 200,
"statusText": "OK",
"httpVersion": "HTTP/1.1",
"headers": [
{ "name": "Date", "value": "Tue, 10 Feb 2015 07:33:16 GMT" },
{ "name": "X-Powered-By", "value": "mockbin.com" },
{ "name": "Content-Type", "value": "text/html; charset=utf-8" }
],
"cookies": [
{ "name": "foo", "value": "bar" }
],
"content": {
"size": 0,
"mimeType": "application/json",
"text": "{\"foo\": \"bar\"}"
},
"redirectURL": "",
"headersSize": 0,
"bodySize": 0
},
"cache": {},
"timings": {
"send": -1,
"wait": -1,
"receive": -1
}
}
]
}
}
After
{
"log": {
"version": "1.2",
"creator": {
"name": "har-expander",
"version": "1.0"
},
"entries": [
{
"startedDateTime": "2015-02-10T07:33:17.146Z",
"time": 110,
"request": {
"method": "GET",
"url": "http://mockbin.com/har",
"httpVersion": "HTTP/1.1",
"headers": [
{ "name": "Host", "value": "mockbin.com" },
{ "name": "Connection", "value": "keep-alive" }
],
"queryString": [
{ "name": "foo", "value": "bar"}
],
"cookies": [
{ "name": "foo", "value": "bar" }
],
"headersSize": 0,
"bodySize": 0,
"queryObj": {
"foo": "bar",
"key": "value"
},
"headersObj": {
"connection": "keep-alive",
"host": "mockbin.com",
"cookie": "foo=bar"
},
"cookiesObj": {
"foo": "bar"
},
"uriObj": {
"protocol": "http:",
"slashes": true,
"auth": null,
"host": "mockbin.com",
"port": null,
"hostname": "mockbin.com",
"hash": null,
"search": "?foo=bar&key=value",
"query": {
"foo": "bar",
"key": "value"
},
"pathname": "/har",
"path": "/har?foo=bar&key=value",
"href": "http://mockbin.com/har?foo=bar&key=value"
},
"fullUrl": "http://mockbin.com/har?foo=bar&key=value"
},
"response": {
"status": 200,
"statusText": "OK",
"httpVersion": "HTTP/1.1",
"headers": [
{ "name": "Date", "value": "Tue, 10 Feb 2015 07:33:16 GMT" },
{ "name": "X-Powered-By", "value": "mockbin.com" },
{ "name": "Content-Type", "value": "text/html; charset=utf-8" }
],
"cookies": [
{ "name": "foo", "value": "bar" }
],
"content": {
"size": 0,
"mimeType": "application/json",
"text": "{\"foo\": \"bar\"}",
"jsonObj": {
"foo": "bar"
},
"paramsObj": false
},
"redirectURL": "",
"headersSize": 0,
"bodySize": 0,
"headersObj": {
"content-type": "text/html; charset=utf-8",
"x-powered-by": "mockbin.com",
"date": "Tue, 10 Feb 2015 07:33:16 GMT",
"cookie": "foo=bar"
},
"cookiesObj": {
"foo": "bar"
},
"redirectURLObj": {
"protocol": null,
"slashes": null,
"auth": null,
"host": null,
"port": null,
"hostname": null,
"hash": null,
"search": "",
"query": {},
"pathname": null,
"path": null,
"href": ""
}
},
"cache": {},
"timings": {
"send": -1,
"wait": -1,
"receive": -1
}
}
]
}
}
Install
npm install --save har-expander
Usage
Usage: har-expander [options]
Options:
-h, --help output usage information
-V, --version output the version number
API
har-expander()
var expander = require('har-expander')
// expand full HAR log
var expandedHAR = expander(HAR)
// expand request object only
var expandedReq = expander.request(HAR.log.entries[0].request)
// expand response object only
var expandedRes = expander.request(HAR.log.entries[0].response)
Support
Donations are welcome to help support the continuous development of this project.