Commit 9ff2e333 authored by Yutaka Hirano's avatar Yutaka Hirano Committed by Commit Bot

Handle error code in WebRequestProxyingWebSocket::ContinueToStartRequest

The bug broke extension scripts cancelling WebSocket connections in
onBeforeRequest handlers with "extraHeaders" option.

Bug: 1011108
Change-Id: I6aec9ff124384b80818955ee66cad05a016579bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1844912Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704859}
parent e641c801
...@@ -200,6 +200,43 @@ chrome.tabs.getCurrent(function(tab) { ...@@ -200,6 +200,43 @@ chrome.tabs.getCurrent(function(tab) {
testWebSocketConnection(url, true /* expectedToConnect */); testWebSocketConnection(url, true /* expectedToConnect */);
}, },
// Tries to open a WebSocket connection, with a blocking handler that
// cancels the request. The connection will not be established.
function handshakeRequestCancelledWithExtraHeaders() {
var url = getWSTestURL(testWebSocketPort);
expect(
[ // events
{ label: 'onBeforeRequest',
event: 'onBeforeRequest',
details: {
url: url,
type: 'websocket',
frameUrl: 'unknown frame URL',
initiator: getDomain(initiators.WEB_INITIATED)
},
retval: {cancel: true}
},
// Cancelling is considered an error.
{ label: 'onErrorOccurred',
event: 'onErrorOccurred',
details: {
url: url,
type: 'websocket',
fromCache: false,
initiator: getDomain(initiators.WEB_INITIATED),
error: 'net::ERR_BLOCKED_BY_CLIENT'
}
},
],
[ // event order
['onBeforeRequest', 'onErrorOccurred']
],
{urls: ['ws://*/*']}, // filter
['blocking', 'extraHeaders'] // extraInfoSpec
);
testWebSocketConnection(url, false /* expectedToConnect */);
},
// Tests that all the requests headers that are added by net/ are visible // Tests that all the requests headers that are added by net/ are visible
// if extraHeaders is specified. // if extraHeaders is specified.
function testExtraRequestHeadersVisible() { function testExtraRequestHeadersVisible() {
......
...@@ -360,6 +360,11 @@ void WebRequestProxyingWebSocket::OnBeforeSendHeadersComplete( ...@@ -360,6 +360,11 @@ void WebRequestProxyingWebSocket::OnBeforeSendHeadersComplete(
} }
void WebRequestProxyingWebSocket::ContinueToStartRequest(int error_code) { void WebRequestProxyingWebSocket::ContinueToStartRequest(int error_code) {
if (error_code != net::OK) {
OnError(error_code);
return;
}
base::flat_set<std::string> used_header_names; base::flat_set<std::string> used_header_names;
std::vector<network::mojom::HttpHeaderPtr> additional_headers; std::vector<network::mojom::HttpHeaderPtr> additional_headers;
for (net::HttpRequestHeaders::Iterator it(request_headers_); it.GetNext();) { for (net::HttpRequestHeaders::Iterator it(request_headers_); it.GetNext();) {
......
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