Commit f01cef63 authored by Harley Li's avatar Harley Li Committed by Commit Bot

[DevTools] Disable copy as options for blob network requests

Blob requests do not make sense when running outside
of the page which created them, so generating a cURL command
would be misleading.

Bug: 791974
Change-Id: Ica9295d4e9f1cced9fd47b78a5338f68f71e5373
Reviewed-on: https://chromium-review.googlesource.com/1213825Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Haihong Li (Harley) <hhli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589976}
parent e1879b6e
......@@ -70,4 +70,24 @@ cURL Windows: curl "http://example.org/path" -H "Cookie: _x=fdsfs; aA=fdsfdsf; F
cURL Unix: curl 'http://example.org/path' -H 'Cookie: _x=fdsfs; aA=fdsfdsf; FOO=ID=BAR:BAZ=FOO:F=d:AO=21.212.2.212-:A=dsadas8d9as8d9a8sd9sa8d9a; AAA=117' --compressed
Powershell: Invoke-WebRequest -Uri "http://example.org/path" -Headers @{"Cookie"="_x=fdsfs; aA=fdsfdsf; FOO=ID=BAR:BAZ=FOO:F=d:AO=21.212.2.212-:A=dsadas8d9as8d9a8sd9sa8d9a; AAA=117"}
fetch: fetch("http://example.org/path", {"credentials":"include","method":"GET","mode":"cors"});
cURL Windows:
cURL Unix:
Powershell:
fetch:
cURL Windows:
cURL Unix:
Powershell:
fetch:
cURL Windows:
cURL Unix:
Powershell:
fetch:
cURL Windows: curl "http://example.org/path" -H "Content-Type: foo/bar" --data-binary "baz" --compressed
cURL Unix: curl 'http://example.org/path' -H 'Content-Type: foo/bar' --data-binary 'baz' --compressed
Powershell: Invoke-WebRequest -Uri "http://example.org/path" -Method "POST" -ContentType "foo/bar" -Body "baz"
fetch: fetch("http://example.org/path", {"credentials":"omit","headers":{"content-type":"foo/bar"},"body":"baz","method":"POST","mode":"cors"});
cURL Windows: curl "http://example.org/path" -H "Content-Type: foo/bar" --data-binary "baz" --compressed
cURL Unix: curl 'http://example.org/path' -H 'Content-Type: foo/bar' --data-binary 'baz' --compressed
Powershell: Invoke-WebRequest -Uri "http://example.org/path" -Method "POST" -ContentType "foo/bar" -Body "baz"
fetch: fetch("http://example.org/path", {"credentials":"omit","headers":{"content-type":"foo/bar"},"body":"baz","method":"POST","mode":"cors"});
......@@ -9,8 +9,8 @@
var logView = UI.panels.network._networkLogView;
function newRequest(headers, data, opt_url) {
var request = new SDK.NetworkRequest(0, opt_url || 'http://example.org/path', 0, 0, 0);
function newRequest(isBlob, headers, data, opt_url) {
var request = new SDK.NetworkRequest(0, (isBlob === true ? 'blob:' : '') + (opt_url || 'http://example.org/path'), 0, 0, 0);
request.requestMethod = data ? 'POST' : 'GET';
var headerList = [];
if (headers) {
......@@ -25,16 +25,31 @@
}
async function dumpRequest(headers, data, opt_url) {
var curlWin = await logView._generateCurlCommand(newRequest(headers, data, opt_url), 'win');
var curlUnix = await logView._generateCurlCommand(newRequest(headers, data, opt_url), 'unix');
var powershell = await logView._generatePowerShellCommand(newRequest(headers, data, opt_url));
var fetch = await logView._generateFetchCall(newRequest(headers, data, opt_url));
var curlWin = await logView._generateCurlCommand(newRequest(false, headers, data, opt_url), 'win');
var curlUnix = await logView._generateCurlCommand(newRequest(false, headers, data, opt_url), 'unix');
var powershell = await logView._generatePowerShellCommand(newRequest(false, headers, data, opt_url));
var fetch = await logView._generateFetchCall(newRequest(false, headers, data, opt_url));
TestRunner.addResult(`cURL Windows: ${curlWin}`);
TestRunner.addResult(`cURL Unix: ${curlUnix}`);
TestRunner.addResult(`Powershell: ${powershell}`);
TestRunner.addResult(`fetch: ${fetch}`);
}
async function dumpMultipleRequests(blobPattern) {
const header = {'Content-Type': 'foo/bar'};
const data = 'baz';
const allRequests = blobPattern.map(isBlob => newRequest(isBlob, header, data));
var allCurlWin = await logView._generateAllCurlCommand(allRequests, 'win');
var allCurlUnix = await logView._generateAllCurlCommand(allRequests, 'unix');
var allPowershell = await logView._generateAllPowerShellCommand(allRequests);
var allFetch = await logView._generateAllFetchCall(allRequests);
TestRunner.addResult(`cURL Windows: ${allCurlWin}`);
TestRunner.addResult(`cURL Unix: ${allCurlUnix}`);
TestRunner.addResult(`Powershell: ${allPowershell}`);
TestRunner.addResult(`fetch: ${allFetch}`);
}
await dumpRequest({});
await dumpRequest({}, '123');
await dumpRequest({'Content-Type': 'application/x-www-form-urlencoded'}, '1&b');
......@@ -55,5 +70,11 @@
await dumpRequest({':host': 'h', 'version': 'v'});
await dumpRequest({'Cookie': '_x=fdsfs; aA=fdsfdsf; FOO=ID=BAR:BAZ=FOO:F=d:AO=21.212.2.212-:A=dsadas8d9as8d9a8sd9sa8d9a; AAA=117'});
await dumpMultipleRequests([]);
await dumpMultipleRequests([true]);
await dumpMultipleRequests([true, true]);
await dumpMultipleRequests([false]);
await dumpMultipleRequests([true, false]);
TestRunner.completeTest();
})();
......@@ -1146,22 +1146,26 @@ Network.NetworkLogView = class extends UI.VBox {
Common.UIString('Copy response'), Network.NetworkLogView._copyResponse.bind(null, request));
}
const disableIfBlob = request.isBlobRequest();
if (Host.isWin()) {
footerSection.appendItem(
Common.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request));
footerSection.appendItem(Common.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request));
Common.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request), disableIfBlob);
footerSection.appendItem(
Common.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'));
Common.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request), disableIfBlob);
footerSection.appendItem(
Common.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'));
Common.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'), disableIfBlob);
footerSection.appendItem(
Common.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
footerSection.appendItem(Common.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
footerSection.appendItem(Common.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this));
footerSection.appendItem(Common.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
footerSection.appendItem(
Common.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
} else {
footerSection.appendItem(Common.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request));
footerSection.appendItem(Common.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'));
footerSection.appendItem(
Common.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request), disableIfBlob);
footerSection.appendItem(
Common.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
footerSection.appendItem(Common.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this));
footerSection.appendItem(Common.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
}
......@@ -1250,12 +1254,8 @@ Network.NetworkLogView = class extends UI.VBox {
* @param {string} platform
*/
async _copyAllCurlCommand(platform) {
const requests = SDK.networkLog.requests();
const commands = await Promise.all(requests.map(request => this._generateCurlCommand(request, platform)));
if (platform === 'win')
InspectorFrontendHost.copyText(commands.join(' &\r\n'));
else
InspectorFrontendHost.copyText(commands.join(' ;\n'));
const commands = await this._generateAllCurlCommand(SDK.networkLog.requests(), platform);
InspectorFrontendHost.copyText(commands);
}
/**
......@@ -1268,9 +1268,8 @@ Network.NetworkLogView = class extends UI.VBox {
}
async _copyAllFetchCall() {
const requests = SDK.networkLog.requests();
const commands = await Promise.all(requests.map(request => this._generateFetchCall(request)));
InspectorFrontendHost.copyText(commands.join(' ;\n'));
const commands = await this._generateAllFetchCall(SDK.networkLog.requests());
InspectorFrontendHost.copyText(commands);
}
/**
......@@ -1282,9 +1281,8 @@ Network.NetworkLogView = class extends UI.VBox {
}
async _copyAllPowerShellCommand() {
const requests = SDK.networkLog.requests();
const commands = await Promise.all(requests.map(request => this._generatePowerShellCommand(request)));
InspectorFrontendHost.copyText(commands.join(';\r\n'));
const commands = this._generateAllPowerShellCommand(SDK.networkLog.requests());
InspectorFrontendHost.copyText(commands);
}
async _exportAll() {
......@@ -1490,6 +1488,14 @@ Network.NetworkLogView = class extends UI.VBox {
this._highlightedNode = node;
}
/**
* @param {!Array<!SDK.NetworkRequest>} requests
* @return {!Array<!SDK.NetworkRequest>}
*/
_filterOutBlobRequests(requests) {
return requests.filter(request => !request.isBlobRequest());
}
/**
* @param {!SDK.NetworkRequest} request
* @return {!Promise<string>}
......@@ -1572,6 +1578,16 @@ Network.NetworkLogView = class extends UI.VBox {
return `fetch(${url}, ${options});`;
}
/**
* @param {!Array<!SDK.NetworkRequest>} requests
* @return {!Promise<string>}
*/
async _generateAllFetchCall(requests) {
const nonBlobRequests = this._filterOutBlobRequests(requests);
const commands = await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request)));
return commands.join(' ;\n');
}
/**
* @param {!SDK.NetworkRequest} request
* @param {string} platform
......@@ -1694,6 +1710,20 @@ Network.NetworkLogView = class extends UI.VBox {
return command.join(' ');
}
/**
* @param {!Array<!SDK.NetworkRequest>} requests
* @param {string} platform
* @return {!Promise<string>}
*/
async _generateAllCurlCommand(requests, platform) {
const nonBlobRequests = this._filterOutBlobRequests(requests);
const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
if (platform === 'win')
return commands.join(' &\r\n');
else
return commands.join(' ;\n');
}
/**
* @param {!SDK.NetworkRequest} request
* @return {!Promise<string>}
......@@ -1751,6 +1781,16 @@ Network.NetworkLogView = class extends UI.VBox {
return command.join(' ');
}
/**
* @param {!Array<!SDK.NetworkRequest>} requests
* @return {!Promise<string>}
*/
async _generateAllPowerShellCommand(requests) {
const nonBlobRequests = this._filterOutBlobRequests(requests);
const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
return commands.join(';\r\n');
}
};
Network.NetworkLogView._isFilteredOutSymbol = Symbol('isFilteredOut');
......
......@@ -149,6 +149,13 @@ SDK.NetworkRequest = class extends Common.Object {
return this._url;
}
/**
* @return {boolean}
*/
isBlobRequest() {
return this._url.startsWith('blob:');
}
/**
* @param {string} x
*/
......
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