Skip to content

Commit

Permalink
feat: support only statusCode in continueResponse (#2598)
Browse files Browse the repository at this point in the history
Just a WIP for now

---------

Co-authored-by: browser-automation-bot <133232582+browser-automation-bot@users.noreply.github.com>
  • Loading branch information
Lightning00Blade and browser-automation-bot authored Sep 10, 2024
1 parent 30a5920 commit 1eeff5b
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 466 deletions.
27 changes: 21 additions & 6 deletions src/bidiMapper/modules/network/NetworkRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ export class NetworkRequest {
bodySize?: number;
};

#responseOverrides?: {
statusCode?: number;
headers?: Network.Header[];
cookies?: Network.CookieHeader[];
};

#response: {
hasExtraInfo?: boolean;
info?: Protocol.Network.Response;
Expand Down Expand Up @@ -242,9 +248,10 @@ export class NetworkRequest {
/** Returns the HTTP status code associated with this request if any. */
get #statusCode(): number | undefined {
return (
this.#response.paused?.responseStatusCode ??
this.#responseOverrides?.statusCode ??
this.#response.info?.status ??
this.#response.extraInfo?.statusCode ??
this.#response.info?.status
this.#response.paused?.responseStatusCode
);
}

Expand Down Expand Up @@ -627,10 +634,18 @@ export class NetworkRequest {
cdpFetchHeadersFromBidiNetworkHeaders(overrideHeaders);

await this.#continueResponse({
responseCode: overrides.statusCode,
responsePhrase: overrides.reasonPhrase,
responseHeaders,
responseCode:
overrides.statusCode ?? this.#response.paused?.responseStatusCode,
responsePhrase:
overrides.reasonPhrase ?? this.#response.paused?.responseStatusText,
responseHeaders:
responseHeaders ?? this.#response.paused?.responseHeaders,
});

this.#responseOverrides = {
statusCode: overrides.statusCode,
headers: overrideHeaders,
};
}
}

Expand Down Expand Up @@ -821,7 +836,7 @@ export class NetworkRequest {
this.#response.info?.fromDiskCache ||
this.#response.info?.fromPrefetchCache ||
this.#servedFromCache,
headers,
headers: this.#responseOverrides?.headers ?? headers,
mimeType: this.#response.info?.mimeType || '',
bytesReceived: this.#response.info?.encodedDataLength || 0,
headersSize: computeHeadersSize(headers),
Expand Down
64 changes: 0 additions & 64 deletions tests/network/test_continue_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,70 +191,6 @@ async def test_continue_response_non_blocked_request(websocket, context_id,
})


@pytest.mark.parametrize("continueResponseParams", [
{
"headers": [{
"name": "header1",
"value": {
"type": "string",
"value": "value1",
}
}]
},
{
"statusCode": 401,
},
],
ids=["headers-only", "statusCode-only"])
@pytest.mark.asyncio
async def test_continue_response_must_specify_both_status_and_headers(
websocket, context_id, url_example, continueResponseParams):
await subscribe(websocket,
["network.responseStarted", "network.responseCompleted"],
[context_id])

await execute_command(
websocket, {
"method": "network.addIntercept",
"params": {
"phases": ["responseStarted"],
"urlPatterns": [{
"type": "string",
"pattern": url_example,
}, ],
},
})

await send_JSON_command(
websocket, {
"method": "browsingContext.navigate",
"params": {
"url": url_example,
"context": context_id,
"wait": "complete",
}
})

event_response = await wait_for_event(websocket, "network.responseStarted")
network_id = event_response["params"]["request"]["request"]

# TODO(https://github.com/w3c/webdriver-bidi/issues/572): Follow up with spec.
with pytest.raises(
Exception,
match=str({
"error": "unknown error",
"message": "Cannot override only status or headers, both should be provided"
})):
await execute_command(
websocket, {
"method": "network.continueResponse",
"params": {
"request": network_id,
"reasonPhrase": "Remember to drink water",
} | continueResponseParams,
})


@pytest.mark.asyncio
@pytest.mark.skip(reason="CDP does not update the response correctly")
async def test_continue_response_completes(websocket, context_id, url_example):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,3 @@

[test_cookie_attributes_before_request_sent[same site strict\]]
expected: FAIL

[test_no_cookie_before_request_sent]
expected: FAIL
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
[headers.py]
[test_headers[headers0\]]
expected: FAIL

[test_headers[headers1\]]
expected: FAIL

[test_headers[headers2\]]
expected: FAIL

[test_headers_overrides_original_headers[headers0\]]
expected: FAIL

[test_headers_overrides_original_headers[headers1\]]
expected: FAIL

[test_headers_overrides_original_headers[headers2\]]
expected: FAIL

[test_set_cookie_header]
expected: FAIL

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,3 @@

[test_cookie_attributes_before_request_sent[same site strict\]]
expected: FAIL

[test_no_cookie_before_request_sent]
expected: FAIL
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
[headers.py]
[test_headers[headers0\]]
expected: FAIL

[test_headers[headers1\]]
expected: FAIL

[test_headers[headers2\]]
expected: FAIL

[test_headers_overrides_original_headers[headers0\]]
expected: FAIL

[test_headers_overrides_original_headers[headers1\]]
expected: FAIL

[test_headers_overrides_original_headers[headers2\]]
expected: FAIL

[test_set_cookie_header]
expected: FAIL

Expand Down

This file was deleted.

Loading

0 comments on commit 1eeff5b

Please sign in to comment.