Commit 7e6c3233 authored by Joey Arhar's avatar Joey Arhar Committed by Commit Bot

[DevTools] Add ResourceType to HAR exports

Bug: 881327
Change-Id: I7e9f50f598210e75d613561855dd4bde95ebaa0f
Reviewed-on: https://chromium-review.googlesource.com/c/1342761
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611505}
parent 481569c8
......@@ -78,6 +78,19 @@ Common.ResourceType = class {
return Common.ResourceType._resourceTypeByExtension.get(Common.ParsedURL.extractExtension(url)) || null;
}
/**
* @param {string} name
* @return {?Common.ResourceType}
*/
static fromName(name) {
for (const resourceTypeId in Common.resourceTypes) {
const resourceType = Common.resourceTypes[resourceTypeId];
if (resourceType.name() === name)
return resourceType;
}
return null;
}
/**
* @param {string} url
* @return {string|undefined}
......
......@@ -163,6 +163,7 @@ HARImporter.HAREntry = class extends HARImporter.HARBase {
if (data['_initiator'])
this._initiator = new HARImporter.HARInitiator(data['_initiator']);
this._priority = HARImporter.HARBase._optionalString(data['_priority']);
this._resourceType = HARImporter.HARBase._optionalString(data['_resourceType']);
}
};
......
......@@ -116,12 +116,7 @@ HARImporter.Importer = class {
// Meta data.
request.setRemoteAddress(entry.serverIPAddress || '', 80); // Har does not support port numbers.
let resourceType = (pageLoad && pageLoad.mainRequest === request) ?
Common.resourceTypes.Document :
Common.ResourceType.fromMimeType(entry.response.content.mimeType);
if (!resourceType)
resourceType = Common.ResourceType.fromURL(entry.request.url) || Common.resourceTypes.Other;
request.setResourceType(resourceType);
request.setResourceType(HARImporter.Importer._getResourceType(request, entry, pageLoad));
const priority = entry.customAsString('priority');
if (Protocol.Network.ResourcePriority.hasOwnProperty(priority))
......@@ -130,6 +125,34 @@ HARImporter.Importer = class {
request.finished = true;
}
/**
* @param {!SDK.NetworkRequest} request
* @param {!HARImporter.HAREntry} entry
* @param {?SDK.NetworkLog.PageLoad} pageLoad
* @return {!Common.ResourceType}
*/
static _getResourceType(request, entry, pageLoad) {
const customResourceTypeName = entry.customAsString('resourceType');
if (customResourceTypeName) {
const customResourceType = Common.ResourceType.fromName(customResourceTypeName);
if (customResourceType)
return customResourceType;
}
if (pageLoad && pageLoad.mainRequest === request)
return Common.resourceTypes.Document;
const resourceTypeFromMime = Common.ResourceType.fromMimeType(entry.response.content.mimeType);
if (resourceTypeFromMime !== Common.resourceTypes.Other)
return resourceTypeFromMime;
const resourceTypeFromUrl = Common.ResourceType.fromURL(entry.request.url);
if (resourceTypeFromUrl)
return resourceTypeFromUrl;
return Common.resourceTypes.Other;
}
/**
* @param {!SDK.NetworkRequest} request
* @param {number} issueTime
......
......@@ -169,7 +169,8 @@ SDK.HARLog.Entry = class {
// IPv6 address should not have square brackets per (https://tools.ietf.org/html/rfc2373#section-2.2).
serverIPAddress: ipAddress.replace(/\[\]/g, ''),
_initiator: exportedInitiator,
_priority: harEntry._request.priority()
_priority: harEntry._request.priority(),
_resourceType: harEntry._request.resourceType().name()
};
// Chrome specific.
......
Verifies that imported HAR files create matching NetworkRequests
requests: [
{
"url": "http://localhost:8000/",
"documentURL": "http://localhost:8000/",
"initiator": {
"type": "other"
},
"requestFormData": null,
"connectionId": "2945",
"requestMethod": "GET",
"requestHeaders": [
{
"name": "Host",
"value": "localhost:8000"
}
],
"mimeType": "text/html",
"responseHeaders": [
{
"name": "Content-Type",
"value": "text/html;charset=ISO-8859-1"
}
],
"statusCode": 200,
"statusText": "OK",
"protocol": "http/1.1",
"resourceSize": 4633,
"transferSize": 4821,
"cached": false,
"cachedInMemory": false,
"contentData": {
"error": null,
"content": "fake page data",
"encoded": false
},
"remoteAddress": "[::1]:80",
"resourceType": {
"_name": "document",
"_title": "Document",
"_category": {
"title": "Documents",
"shortTitle": "Doc"
},
"_isTextType": true
},
"priority": "VeryHigh",
"finished": true,
"timing": {
"proxyStart": 2.0154479999188335,
"proxyEnd": 2.4644479999188333,
"requestTime": 1542746587.755448,
"dnsStart": -1,
"dnsEnd": -1,
"connectStart": -1,
"connectEnd": -1,
"sslStart": -1,
"sslEnd": -1,
"workerStart": -1,
"workerReady": -1,
"sendStart": 2.4644479999188333,
"sendEnd": 2.534447999918833,
"pushStart": 0,
"pushEnd": 0,
"receiveHeadersEnd": 5.624447982991114
},
"endTime": 1542746587.7661417
},
{
"url": "http://localhost:8000/post-endpoint",
"documentURL": "http://localhost:8000/",
"initiator": {
"type": "parser",
"url": "http://localhost/",
"lineNumber": 1
},
"requestFormData": "one=urlencodedvalueone&two=urlencodedvaluetwo",
"connectionId": "2945",
"requestMethod": "POST",
"requestHeaders": [],
"mimeType": "image/x-icon",
"responseHeaders": [],
"statusCode": 200,
"statusText": "OK",
"protocol": "http/1.1",
"resourceSize": 1150,
"transferSize": 1417,
"cached": false,
"cachedInMemory": false,
"contentData": {
"error": null,
"content": null,
"encoded": false
},
"remoteAddress": "[::1]:80",
"resourceType": {
"_name": "image",
"_title": "Image",
"_category": {
"title": "Images",
"shortTitle": "Img"
},
"_isTextType": false
},
"priority": "Low",
"finished": true,
"timing": {
"proxyStart": 1.7575360001232476,
"proxyEnd": 2.2485360001232477,
"requestTime": 1542746587.8705359,
"dnsStart": -1,
"dnsEnd": -1,
"connectStart": -1,
"connectEnd": -1,
"sslStart": -1,
"sslEnd": -1,
"workerStart": -1,
"workerReady": -1,
"sendStart": 2.2485360001232477,
"sendEnd": 2.3095360001232477,
"pushStart": 0,
"pushEnd": 0,
"receiveHeadersEnd": 2.828536113491282
},
"endTime": 1542746587.8738945
},
{
"url": "http://localhost:8000/js_file.js",
"documentURL": "http://localhost:8000/",
"initiator": {
"type": "parser",
"url": "http://localhost/",
"lineNumber": 1
},
"requestFormData": null,
"connectionId": "2945",
"requestMethod": "GET",
"requestHeaders": [],
"mimeType": "undefined",
"responseHeaders": [],
"statusCode": 200,
"statusText": "OK",
"protocol": "http/1.1",
"resourceSize": 1150,
"transferSize": 1417,
"cached": false,
"cachedInMemory": false,
"contentData": {
"error": null,
"content": null,
"encoded": false
},
"remoteAddress": "[::1]:80",
"resourceType": {
"_name": "script",
"_title": "Script",
"_category": {
"title": "Scripts",
"shortTitle": "JS"
},
"_isTextType": true
},
"priority": "Low",
"finished": true,
"timing": {
"proxyStart": 1.7575360001232476,
"proxyEnd": 2.2485360001232477,
"requestTime": 1542746587.8705359,
"dnsStart": -1,
"dnsEnd": -1,
"connectStart": -1,
"connectEnd": -1,
"sslStart": -1,
"sslEnd": -1,
"workerStart": -1,
"workerReady": -1,
"sendStart": 2.2485360001232477,
"sendEnd": 2.3095360001232477,
"pushStart": 0,
"pushEnd": 0,
"receiveHeadersEnd": 2.828536113491282
},
"endTime": 1542746587.8738945
},
{
"url": "http://localhost:8000/endpoint",
"documentURL": "http://localhost:8000/",
"initiator": {
"type": "script"
},
"requestFormData": null,
"connectionId": "2945",
"requestMethod": "GET",
"requestHeaders": [],
"mimeType": "undefined",
"responseHeaders": [],
"statusCode": 200,
"statusText": "OK",
"protocol": "http/1.1",
"resourceSize": 1150,
"transferSize": 1417,
"cached": false,
"cachedInMemory": false,
"contentData": {
"error": null,
"content": null,
"encoded": false
},
"remoteAddress": "[::1]:80",
"resourceType": {
"_name": "fetch",
"_title": "Fetch",
"_category": {
"title": "XHR and Fetch",
"shortTitle": "XHR"
},
"_isTextType": true
},
"priority": "Low",
"finished": true,
"timing": {
"proxyStart": 1.7575360001232476,
"proxyEnd": 2.2485360001232477,
"requestTime": 1542746587.8705359,
"dnsStart": -1,
"dnsEnd": -1,
"connectStart": -1,
"connectEnd": -1,
"sslStart": -1,
"sslEnd": -1,
"workerStart": -1,
"workerReady": -1,
"sendStart": 2.2485360001232477,
"sendEnd": 2.3095360001232477,
"pushStart": 0,
"pushEnd": 0,
"receiveHeadersEnd": 2.828536113491282
},
"endTime": 1542746587.8738945
}
]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(async function() {
TestRunner.addResult(
'Verifies that imported HAR files create matching NetworkRequests');
await TestRunner.loadModule('application_test_runner');
await TestRunner.loadModule('network_test_runner');
const harRoot = new HARImporter.HARRoot(harJson);
const requests = HARImporter.Importer.requestsFromHARLog(harRoot.log);
const formattedRequests = await Promise.all(requests.map(async request => {
return {
url: request.url(),
documentURL: request.documentURL,
initiator: request.initiator(),
requestFormData: await(request.requestFormData()),
connectionId: request.connectionId,
requestMethod: request.requestMethod,
requestHeaders: request.requestHeaders(),
mimeType: request.mimeType,
responseHeaders: request.responseHeaders,
statusCode: request.statusCode,
statusText: request.statusText,
protocol: request.protocol,
resourceSize: request.resourceSize,
transferSize: request.transferSize,
cached: request.cached(),
cachedInMemory: request.cachedInMemory(),
contentData: await(request.contentData()),
remoteAddress: request.remoteAddress(),
resourceType: request.resourceType(),
priority: request.priority(),
finished: request.finished,
timing: request.timing,
endTime: request.endTime
};
}));
TestRunner.addResult(
'requests: ' + JSON.stringify(formattedRequests, null, 2));
TestRunner.completeTest();
})();
const harJson = {
'log': {
'version': '1.2',
'creator': {'name': 'WebInspector', 'version': '537.36'},
'pages': [{
'startedDateTime': '2018-11-20T20:43:07.756Z',
'id': 'page_1',
'title': 'http://localhost:8000/',
'pageTimings':
{'onContentLoad': 67.84599996171892, 'onLoad': 112.05600015819073}
}],
'entries': [
{
'startedDateTime': '2018-11-20T20:43:07.755Z',
'time': 11.14144808263518,
'request': {
'method': 'GET',
'url': 'http://localhost:8000/',
'httpVersion': 'HTTP/1.1',
'headers': [{'name': 'Host', 'value': 'localhost:8000'}],
'queryString': [],
'cookies': [],
'headersSize': 418,
'bodySize': 0
},
'response': {
'status': 200,
'statusText': 'OK',
'httpVersion': 'HTTP/1.1',
'headers': [
{'name': 'Content-Type', 'value': 'text/html;charset=ISO-8859-1'}
],
'cookies': [{
'name': 'test-cookie-name',
'value': '1',
'path': '/',
'domain': '.localhost',
'expires': '2018-11-19T18:17:22.000Z',
'httpOnly': false,
'secure': false
}],
'content':
{'size': 4633, 'mimeType': 'text/html', 'text': 'fake page data'},
'redirectURL': '',
'headersSize': 188,
'bodySize': 4633,
'_transferSize': 4821
},
'cache': {},
'timings': {
'blocked': 2.4644479999188333,
'dns': -1,
'ssl': -1,
'connect': -1,
'send': 0.06999999999999984,
'wait': 3.089999983072281,
'receive': 5.517000099644065,
'_blocked_queueing': 0.447999918833375,
'_blocked_proxy': 0.44899999999999984
},
'serverIPAddress': '[::1]',
'_initiator': {'type': 'other'},
'_priority': 'VeryHigh',
'connection': '2945',
'pageref': 'page_1'
},
{
'startedDateTime': '2018-11-20T20:43:07.870Z',
'time': 3.8945360814686865,
'request': {
'method': 'POST',
'url': 'http://localhost:8000/post-endpoint',
'httpVersion': 'HTTP/1.1',
'headers': [],
'queryString': [],
'cookies': [],
'headersSize': 386,
'bodySize': 0,
'postData': {
'mimeType': 'application/x-www-form-urlencoded',
'text': 'one=urlencodedvalueone&two=urlencodedvaluetwo',
'params': [
{'name': 'one', 'value': 'urlencodedvalueone'},
{'name': 'two', 'value': 'urlencodedvaluetwo'}
]
}
},
'response': {
'status': 200,
'statusText': 'OK',
'httpVersion': 'HTTP/1.1',
'headers': [],
'cookies': [],
'content':
{'size': 1150, 'mimeType': 'image/x-icon', 'compression': 0},
'redirectURL': '',
'headersSize': 267,
'bodySize': 1150,
'_transferSize': 1417
},
'cache': {},
'timings': {
'blocked': 2.2485360001232477,
'dns': -1,
'ssl': -1,
'connect': -1,
'send': 0.06099999999999994,
'wait': 0.5190001133680342,
'receive': 1.0659999679774046,
'_blocked_queueing': 0.5360001232475042,
'_blocked_proxy': 0.4910000000000001
},
'serverIPAddress': '[::1]',
'_initiator':
{'type': 'parser', 'url': 'http://localhost/', 'lineNumber': 1},
'_priority': 'Low',
'connection': '2945',
'pageref': 'page_1'
},
{
'startedDateTime': '2018-11-20T20:43:07.870Z',
'time': 3.8945360814686865,
'request': {
'method': 'GET',
'url': 'http://localhost:8000/js_file.js',
'httpVersion': 'HTTP/1.1',
'headers': [],
'queryString': [],
'cookies': [],
'headersSize': 386,
'bodySize': 0
},
'response': {
'status': 200,
'statusText': 'OK',
'httpVersion': 'HTTP/1.1',
'headers': [],
'cookies': [],
'content': {'size': 1150, 'compression': 0},
'redirectURL': '',
'headersSize': 267,
'bodySize': 1150,
'_transferSize': 1417
},
'cache': {},
'timings': {
'blocked': 2.2485360001232477,
'dns': -1,
'ssl': -1,
'connect': -1,
'send': 0.06099999999999994,
'wait': 0.5190001133680342,
'receive': 1.0659999679774046,
'_blocked_queueing': 0.5360001232475042,
'_blocked_proxy': 0.4910000000000001
},
'serverIPAddress': '[::1]',
'_initiator':
{'type': 'parser', 'url': 'http://localhost/', 'lineNumber': 1},
'_priority': 'Low',
'connection': '2945',
'pageref': 'page_1'
},
{
'startedDateTime': '2018-11-20T20:43:07.870Z',
'time': 3.8945360814686865,
'request': {
'method': 'GET',
'url': 'http://localhost:8000/endpoint',
'httpVersion': 'HTTP/1.1',
'headers': [],
'queryString': [],
'cookies': [],
'headersSize': 386,
'bodySize': 0
},
'response': {
'status': 200,
'statusText': 'OK',
'httpVersion': 'HTTP/1.1',
'headers': [],
'cookies': [],
'content': {'size': 1150, 'compression': 0},
'redirectURL': '',
'headersSize': 267,
'bodySize': 1150,
'_transferSize': 1417
},
'cache': {},
'timings': {
'blocked': 2.2485360001232477,
'dns': -1,
'ssl': -1,
'connect': -1,
'send': 0.06099999999999994,
'wait': 0.5190001133680342,
'receive': 1.0659999679774046,
'_blocked_queueing': 0.5360001232475042,
'_blocked_proxy': 0.4910000000000001
},
'serverIPAddress': '[::1]',
'_initiator': {
'type': 'script',
'stack': {
'callFrames': {
'functionName': '',
'scriptId': '32',
'url': 'http://localhost:8000/script.js',
'lineNumber': 5,
'colNumber': 2
}
}
},
'_priority': 'Low',
'_resourceType': 'fetch',
'connection': '2945',
'pageref': 'page_1'
}
]
}
};
......@@ -10,6 +10,7 @@ Page reloaded.
{
_initiator : <object>
_priority : <string>
_resourceType : "document"
cache : {
}
connection : <string>
......@@ -107,6 +108,7 @@ Page reloaded.
{
_initiator : <object>
_priority : <string>
_resourceType : "xhr"
cache : {
}
connection : <string>
......
......@@ -31,6 +31,7 @@ HAR:{
url : "http://example.com/inspector-test.js"
}
_priority : "VeryHigh"
_resourceType : "fetch"
cache : {
}
request : {
......
......@@ -26,6 +26,7 @@
request.resourceSize = 1000;
request._transferSize = 539; // 39 = header size at the end of the day
request.setPriority('VeryHigh');
request.setResourceType(Common.resourceTypes.Fetch);
// sample timing values used here are copied from a real request
request.setIssueTime(357904.060558);
......
......@@ -4,6 +4,7 @@ http://127.0.0.1:8000/devtools/resources/post-target.cgi?queryParam1=queryValue1
{
_initiator : <object>
_priority : <string>
_resourceType : "document"
cache : {
}
connection : <string>
......
......@@ -4,6 +4,7 @@ http://[::1]:8000/devtools/resources/post-target.cgi?queryParam1=queryValue1&que
{
_initiator : <object>
_priority : <string>
_resourceType : "document"
cache : {
}
connection : <string>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment