This repository has been archived by the owner on Jul 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a1b0e5
commit 3ac3d9c
Showing
5 changed files
with
277 additions
and
31 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
{ | ||
"modules" : [ | ||
{ "name": "ndb_sdk", "type": "autostart" }, | ||
{ "name": "ndb", "type": "autostart" }, | ||
{ "name": "layer_viewer" }, | ||
{ "name": "timeline_model" }, | ||
{ "name": "timeline" }, | ||
{ "name": "product_registry" }, | ||
{ "name": "mobile_throttling" }, | ||
{ "name": "ndb_ui" }, | ||
{ "name": "xterm" } | ||
], | ||
"modules": [ | ||
{ "name": "ndb_sdk", "type": "autostart" }, | ||
{ "name": "ndb", "type": "autostart" }, | ||
{ "name": "layer_viewer" }, | ||
{ "name": "timeline_model" }, | ||
{ "name": "timeline" }, | ||
{ "name": "product_registry" }, | ||
{ "name": "mobile_throttling" }, | ||
{ "name": "ndb_ui" }, | ||
{ "name": "xterm" }, | ||
{ "name": "emulation", "type": "autostart" }, | ||
{ "name": "inspector_main", "type": "autostart" }, | ||
{ "name": "mobile_throttling", "type": "autostart" }, | ||
{ "name": "cookie_table" }, | ||
{ "name": "har_importer" }, | ||
{ "name": "network" } | ||
], | ||
"extends": "shell", | ||
"has_html": true | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
const zlib = require('zlib'); | ||
const http = require('http'); | ||
const https = require('https'); | ||
|
||
const initTime = process.hrtime(); | ||
|
||
// DT requires us to use relative time in a strange format (xxx.xxx) | ||
const getTime = () => { | ||
const diff = process.hrtime(initTime); | ||
|
||
return diff[0] + diff[1] / 1e9; | ||
}; | ||
|
||
const formatRequestHeaders = req => { | ||
if (!req.headers) return {}; | ||
return Object.keys(req.headers).reduce((acc, k) => { | ||
if (typeof req.headers[k] === 'string') acc[k] = req.headers[k]; | ||
return acc; | ||
}, {}); | ||
}; | ||
|
||
const formatResponseHeaders = res => { | ||
if (!res.headers) return {}; | ||
return Object.keys(res.headers).reduce((acc, k) => { | ||
if (typeof res.headers[k] === 'string') acc[k] = res.headers[k]; | ||
return acc; | ||
}, {}); | ||
}; | ||
|
||
const getMineType = mimeType => { | ||
// nasty hack for ASF | ||
if (mimeType === 'OPENJSON') | ||
return 'application/json;charset=UTF-8'; | ||
|
||
|
||
return mimeType; | ||
}; | ||
|
||
const cacheRequests = {}; | ||
let id = 1; | ||
const getId = () => id++; | ||
|
||
const callbackWrapper = (callback, req) => res => { | ||
const requestId = getId(); | ||
res.req.__requestId = requestId; | ||
|
||
process.send({ | ||
payload: { | ||
requestId: requestId, | ||
loaderId: requestId, | ||
documentURL: req.href, | ||
request: { | ||
url: req.href, | ||
method: req.method, | ||
headers: formatRequestHeaders(req), | ||
mixedContentType: 'none', | ||
initialPriority: 'VeryHigh', | ||
referrerPolicy: 'no-referrer-when-downgrade', | ||
postData: req.body | ||
}, | ||
timestamp: getTime(), | ||
wallTime: Date.now(), | ||
initiator: { | ||
type: 'other' | ||
}, | ||
type: 'Document' | ||
}, | ||
type: 'Network.requestWillBeSent' | ||
}); | ||
|
||
const encoding = res.headers['content-encoding']; | ||
let rawData = []; | ||
|
||
const onEnd = function() { | ||
rawData = Buffer.concat(rawData); | ||
rawData = rawData.toString('base64'); | ||
|
||
cacheRequests[res.req.__requestId] = { | ||
...res, | ||
__rawData: rawData, | ||
base64Encoded: true | ||
}; | ||
const payload = { | ||
id: res.req.__requestId, | ||
requestId: res.req.__requestId, | ||
loaderId: res.req.__requestId, | ||
base64Encoded: true, | ||
data: cacheRequests[res.req.__requestId].__rawData, | ||
timestamp: getTime(), | ||
type: 'XHR', | ||
encodedDataLength: 100, | ||
response: { | ||
url: req.href, | ||
status: res.statusCode, | ||
statusText: res.statusText, | ||
// set-cookie prop in the header has value as an array | ||
// for example: ["__cfduid=dbfe006ef71658bf4dba321343c227f9a15449556…20:29 GMT; path=/; domain=.typicode.com; HttpOnly"] | ||
headers: formatResponseHeaders(res), | ||
mimeType: getMineType( | ||
res.headers['content-encoding'] || | ||
res.headers['content-type'] | ||
), | ||
requestHeaders: formatRequestHeaders(req) | ||
} | ||
}; | ||
|
||
// Send the response back. | ||
process.send({ payload: payload, type: 'Network.responseReceived' }); | ||
process.send({ payload: payload, type: 'Network.loadingFinished' }); | ||
}; | ||
|
||
if (encoding === 'gzip' || encoding === 'x-gzip') { | ||
const gunzip = zlib.createGunzip(); | ||
res.pipe(gunzip); | ||
|
||
gunzip.on('data', function(data) { | ||
rawData.push(data); | ||
}); | ||
gunzip.on('end', onEnd); | ||
} else { | ||
res.on('data', chunk => { | ||
rawData.push(chunk); | ||
}); | ||
res.on('end', onEnd); | ||
} | ||
|
||
callback && callback(res); | ||
}; | ||
|
||
const originHTTPRequest = http.request; | ||
http.request = function wrapMethodRequest(req, callback) { | ||
const request = originHTTPRequest.call( | ||
this, | ||
req, | ||
callbackWrapper(callback, req) | ||
); | ||
return request; | ||
}; | ||
|
||
const originHTTPSRequest = https.request; | ||
https.request = function wrapMethodRequest(req, callback) { | ||
const request = originHTTPSRequest.call( | ||
this, | ||
req, | ||
callbackWrapper(callback, req) | ||
); | ||
const originWrite = request.write.bind(request); | ||
request.write = data => { | ||
req.body = data.toString(); | ||
originWrite(data); | ||
}; | ||
return request; | ||
}; |
Oops, something went wrong.