Skip to content

Commit

Permalink
feat: support body in network.continueRequest (#2075)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightning00Blade authored Mar 26, 2024
1 parent 5162b0a commit d0c4955
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
41 changes: 28 additions & 13 deletions src/bidiMapper/domains/network/NetworkProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ export class NetworkProcessor {
async continueRequest(
params: Network.ContinueRequestParameters
): Promise<EmptyResult> {
const {url, method, headers, request: networkId} = params;
const {
url,
method,
headers: commandHeaders,
body,
request: networkId,
} = params;

if (params.url !== undefined) {
NetworkProcessor.parseUrlString(params.url);
Expand All @@ -84,13 +90,17 @@ export class NetworkProcessor {
Network.InterceptPhase.BeforeRequestSent,
]);

const requestHeaders: Protocol.Fetch.HeaderEntry[] | undefined =
cdpFetchHeadersFromBidiNetworkHeaders(headers);
const headers: Protocol.Fetch.HeaderEntry[] | undefined =
cdpFetchHeadersFromBidiNetworkHeaders(commandHeaders);

// TODO: Set / expand.
// ; Step 9. cookies
// ; Step 10. body
await request.continueRequest(url, method, requestHeaders);
await request.continueRequest({
url,
method,
headers,
postData: getCdpBodyFromBiDiBytesValue(body),
});

return {};
}
Expand Down Expand Up @@ -238,18 +248,11 @@ export class NetworkProcessor {

const responseCode = statusCode ?? request.statusCode ?? 200;

let parsedBody: string | undefined;
if (body?.type === 'string') {
parsedBody = btoa(body.value);
} else if (body?.type === 'base64') {
parsedBody = body.value;
}

await request.provideResponse({
responseCode,
responsePhrase,
responseHeaders,
body: parsedBody,
body: getCdpBodyFromBiDiBytesValue(body),
});

return {};
Expand Down Expand Up @@ -435,3 +438,15 @@ function unescapeURLPattern(pattern: string) {
}
return result;
}

function getCdpBodyFromBiDiBytesValue(
body?: Network.BytesValue
): string | undefined {
let parsedBody: string | undefined;
if (body?.type === 'string') {
parsedBody = btoa(body.value);
} else if (body?.type === 'base64') {
parsedBody = body.value;
}
return parsedBody;
}
16 changes: 8 additions & 8 deletions src/bidiMapper/domains/network/NetworkRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,21 +381,20 @@ export class NetworkRequest {
}

/** @see https://chromedevtools.github.io/devtools-protocol/tot/Fetch/#method-continueRequest */
async continueRequest(
url?: string,
method?: string,
headers?: Protocol.Fetch.HeaderEntry[]
) {
async continueRequest({
url,
method,
headers,
postData,
}: Omit<Protocol.Fetch.ContinueRequestRequest, 'requestId'> = {}) {
assert(this.#fetchId, 'Network Interception not set-up.');

await this.cdpClient.sendCommand('Fetch.continueRequest', {
requestId: this.#fetchId,
url,
method,
headers,
// TODO: Set?
// postData:,
// interceptResponse:,
postData,
});
this.#interceptPhase = undefined;
}
Expand Down Expand Up @@ -541,6 +540,7 @@ export class NetworkRequest {
this.#response.info?.headers
);

// TODO: get headers from Fetch.requestPaused
const authChallenges = this.#authChallenges(
this.#response.info?.headers ?? {}
);
Expand Down

0 comments on commit d0c4955

Please sign in to comment.