Commit 93409376 authored by Mike Jackson's avatar Mike Jackson Committed by Commit Bot

DevTools: HAR file exported from CDT doesn't load in HttpWatch

When a page makes a 'POST' XHR request, and then sends a typed array as
binary data, there is no request content type.

If the user, then exports the contents of the network tool to a HAR
file, the postData section is missing the mimeType field. HttpWatch
requires the MimeType field, otherwise it treats the file as if its
incorrectly formatted.

The fix is to ensure we always generate the mimeType field for the
postData section.


Change-Id: Id110887fac50057ccab7a257a8de770a9d92b03c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1535348
Commit-Queue: Mike Jackson <mjackson@microsoft.com>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644467}
parent 663217db
......@@ -111,18 +111,29 @@ NetworkTestRunner.makeSimpleXHRWithPayload = function(method, url, async, payloa
NetworkTestRunner.makeXHR(method, url, async, undefined, undefined, [], false, payload, undefined, callback);
};
NetworkTestRunner.makeXHRWithTypedArrayPayload = function(method, url, async, payload, callback) {
const args = {};
args.typedArrayPayload = new TextDecoder('utf-8').decode(payload);
NetworkTestRunner.makeXHRImpl(method, url, async, args, callback);
};
NetworkTestRunner.makeXHR = function(
method, url, async, user, password, headers, withCredentials, payload, type, callback) {
const args = {};
args.method = method;
args.url = TestRunner.url(url);
args.async = async;
args.user = user;
args.password = password;
args.headers = headers;
args.withCredentials = withCredentials;
args.payload = payload;
args.type = type;
NetworkTestRunner.makeXHRImpl(method, url, async, args, callback);
};
NetworkTestRunner.makeXHRImpl = function(method, url, async, args, callback) {
args.method = method;
args.url = TestRunner.url(url);
args.async = async;
const jsonArgs = JSON.stringify(args).replace(/\"/g, '\\"');
function innerCallback(msg) {
......@@ -219,6 +230,10 @@ TestRunner.deprecatedInitAsync(`
function makeXHRForJSONArguments(jsonArgs) {
let args = JSON.parse(jsonArgs);
let payload = args.payload;
if (args.typedArrayPayload)
payload = new TextEncoder('utf-8').encode(args.typedArrayPayload);
makeXHR(
args.method,
......@@ -228,7 +243,7 @@ TestRunner.deprecatedInitAsync(`
args.password,
args.headers || [],
args.withCredentials,
args.payload,
payload,
args.type,
xhrLoadedCallback
);
......
......@@ -325,7 +325,7 @@ SDK.HARLog.Entry = class {
const postData = await this._request.requestFormData();
if (!postData)
return null;
const res = {mimeType: this._request.requestContentType(), text: postData};
const res = {mimeType: this._request.requestContentType() || '', text: postData};
const formParameters = await this._request.formParameters();
if (formParameters)
res.params = this._buildParameters(formParameters);
......
......@@ -3,7 +3,7 @@ Tests that XMLHttpRequest Logging works when Enabled and doesn't show logs when
XHR with logging enabled:
VM:37 XHR finished loading: GET "http://127.0.0.1:8000/devtools/resources/xhr-exists.html".
makeXHR @ VM:37
makeXHRForJSONArguments @ VM:43
makeXHRForJSONArguments @ VM:47
(anonymous) @ VM:1
VM:5 XHR loaded: 1
XHR with logging disabled:
......
......@@ -36,3 +36,12 @@ request: {
}
}
request: {
"url": "http://127.0.0.1:8000/devtools/network/resources/echo-payload.php",
"bodySize": 2,
"postData": {
"mimeType": "",
"text": "Cr"
}
}
......@@ -15,10 +15,19 @@
'POST', '/devtools/network/resources/echo-payload.php', false, data,
resolve));
}
async function doTypedArrayPost(data) {
await new Promise(
resolve => NetworkTestRunner.makeXHRWithTypedArrayPayload(
'POST', '/devtools/network/resources/echo-payload.php', false, data,
resolve));
}
await doPost('1 byte utf-8 char: a');
await doPost('2 byte utf-8 char: ž');
await doPost('3 byte utf-8 char: ツ');
await doPost('4 byte utf-8 char: 🔥');
await doTypedArrayPost(new Uint8Array([67, 114]));
const harString = await new Promise(async resolve => {
const stream = new TestRunner.StringOutputStream(resolve);
......
Checks that we show warning message for long cookie.
Message count: 1
VM:58 Set-Cookie header is ignored in response from url: http://127.0.0.1:8000/devtools/network/resources/set-cookie.php?length=4097. Cookie length should be less than or equal to 4096 characters.
makeFetch @ VM:58
VM:62 Set-Cookie header is ignored in response from url: http://127.0.0.1:8000/devtools/network/resources/set-cookie.php?length=4097. Cookie length should be less than or equal to 4096 characters.
makeFetch @ VM:62
(anonymous) @ VM:1
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