Skip to content
Permalink
Browse files
Web Inspector: only override request headers if they are provided
https://bugs.webkit.org/show_bug.cgi?id=240734

Reviewed by Patrick Angle.

* Source/WebInspectorUI/UserInterface/Controllers/NetworkManager.js:
(WI.NetworkManager.prototype.async requestIntercepted):
(WI.NetworkManager.prototype.async responseIntercepted):

* LayoutTests/http/tests/inspector/network/intercept-request-properties.html:
* LayoutTests/http/tests/inspector/network/intercept-request-properties-expected.txt:
* LayoutTests/http/tests/inspector/network/local-resource-override-basic.html:
* LayoutTests/http/tests/inspector/network/local-resource-override-basic-expected.txt:

Canonical link: https://commits.webkit.org/250823@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294590 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
dcrousso committed May 20, 2022
1 parent f4ecf71 commit 280e1ae56d761d57d0a840b6c66915c0bb2f3c3e
Showing 5 changed files with 59 additions and 3 deletions.
@@ -79,6 +79,17 @@ Request details:
Request Headers:
X-Value: overridden

-- Running test case: Network.interceptRequest.Headers.Passthrough
Triggering load...
Request details:
URI: /inspector/network/resources/intercept-echo.py
Response URL: http://127.0.0.1:8000/inspector/network/resources/intercept-echo.py
Method: POST
Request Headers:
Content-Type: application/x-www-form-urlencoded
Post:
value: overridden

-- Running test case: Network.interceptRequest.PostData
Triggering load...
Request details:
@@ -163,6 +163,16 @@
override: { requestHeaders: { "X-Value": "overridden" } },
});

addTestCase({
name: "Network.interceptRequest.Headers.Passthrough",
description: "Tests request headers passthrough",
expression: "postData('resources/intercept-echo.py')",
override: {
requestMethod: "POST",
requestData: "value=overridden",
},
});

addTestCase({
name: "Network.interceptRequest.PostData",
description: "Tests request post data interception",
@@ -127,6 +127,26 @@ Response Headers:
X-Expected: PASS
Content: PASS

-- Running test case: LocalResourceOverride.Headers.Passthrough
Creating Local Resource Override for: http://127.0.0.1:8000/inspector/network/resources/override.txt
Triggering load...
Resource Loaded:
URL: http://127.0.0.1:8000/inspector/network/resources/override.txt
MIME Type: text/plain
Status: 200 OK
Response Source: Symbol(inspector-override)
Response Headers:
Accept-Ranges: <filtered>
Connection: <filtered>
Content-Length: 29
Content-Type: text/plain
Date: <filtered>
ETag: <filtered>
Keep-Alive: <filtered>
Last-Modified: <filtered>
Server: <filtered>
Content: PASS

-- Running test case: LocalResourceOverride.404
Creating Local Resource Override for: http://127.0.0.1:8000/inspector/network/resources/override.txt
Triggering load...
@@ -122,7 +122,7 @@
responseBase64Encoded: true,
responseStatusCode: 200,
responseStatusText: "OK",
responseHeaders: {},
responseHeaders: {"Content-Type": "image/png"},
}]
});

@@ -213,6 +213,21 @@
}]
});

addTestCase({
name: "LocalResourceOverride.Headers.Passthrough",
description: "Load an override without modifying headers.",
expression: `triggerOverrideLoad()`,
overrides: [{
url: "http://127.0.0.1:8000/inspector/network/resources/override.txt",
responseMIMEType: "text/plain",
responseContent: "PASS",
responseBase64Encoded: false,
responseStatusCode: 200,
responseStatusText: "OK",
responseHeaders: {},
}]
});

addTestCase({
name: "LocalResourceOverride.404",
description: "Test for a 404 override.",
@@ -982,7 +982,7 @@ WI.NetworkManager = class NetworkManager extends WI.Object
requestId,
url: localResourceOverride.generateRequestRedirectURL(request.url) ?? undefined,
method: localResource.requestMethod ?? undefined,
headers: localResource.requestHeaders,
headers: !isEmptyObject(localResource.requestHeaders) ? localResource.requestHeaders : undefined,
postData: (WI.HTTPUtilities.RequestMethodsWithBody.has(localResource.requestMethod) && localResource.requestData) ? btoa(localResource.requestData) : undefined,
});
return;
@@ -1033,7 +1033,7 @@ WI.NetworkManager = class NetworkManager extends WI.Object
mimeType: revision.mimeType ?? undefined,
status: !isNaN(localResource.statusCode) ? localResource.statusCode : undefined,
statusText: !isNaN(localResource.statusCode) ? (localResource.statusText ?? "") : undefined,
headers: localResource.responseHeaders,
headers: !isEmptyObject(localResource.responseHeaders) ? localResource.responseHeaders : undefined,
});
return;
}

0 comments on commit 280e1ae

Please sign in to comment.