Skip to content

Commit

Permalink
fix header conversion (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirdarckcat authored Dec 30, 2020
1 parent 9e7f719 commit 44c235f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
7 changes: 6 additions & 1 deletion v2/background/src/debuggee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ export class Debuggee {
}): Promise<never>;
async sendCommand(method: 'Fetch.enable', params: { patterns: Debugger_Fetch_RequestPattern[] }): Promise<never>;
async sendCommand(method: 'Fetch.getResponseBody', params: { requestId: string }): Promise<Debugger_Network_ResponseBody>;
async sendCommand(method: 'Fetch.continueRequest', params: { requestId: string } & Partial<Debugger_Network_Request>): Promise<never>;
async sendCommand(method: 'Fetch.continueRequest', params: { requestId: string} & Partial<{
url: string,
method: string,
postData: string,
headers: Debugger_Fetch_HeaderEntry[]
}>): Promise<never>;
async sendCommand(method: 'Fetch.fulfillRequest', params: {
requestId: string,
responseCode: number,
Expand Down
21 changes: 17 additions & 4 deletions v2/background/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export abstract class Intercepted implements InterceptedData {
id: string;
method: string;
url: string;
requestHeaders: { name: string, value: string }[];
requestHeaders: Debugger_Fetch_HeaderEntry[];
requestBody?: string | null;
status?: number;
responseHeaders?: { name: string, value: string }[];
responseHeaders?: Debugger_Fetch_HeaderEntry[];
responseBody?: string | null = null;

protected constructor(dbg: Debuggee, { id, method, url, requestHeaders, requestBody, status, responseHeaders }: InterceptedData) {
Expand Down Expand Up @@ -105,20 +105,33 @@ export class FetchIntercepted extends Intercepted {
id: requestId,
method: request.method,
url: request.url,
requestHeaders: Object.entries(request.headers).map(e => ({ name: e[0], value: e[1] })),
requestHeaders: FetchIntercepted.convertHeaders(request.headers),
requestBody: request.hasPostData ? request.postData : null,
status: responseStatusCode,
responseHeaders: responseHeaders,
});
}

private static convertHeaders(headers: Record<string, string>|undefined): Debugger_Fetch_HeaderEntry[] {
return Object.entries(headers||{}).map(e => ({ name: e[0], value: e[1] }));
}

async getResponseBodyInternal() {
return this.debuggee.sendCommand('Fetch.getResponseBody', { requestId: this.id });
}

async continueRequestInternal(request: Partial<Debugger_Network_Request>) {
if (JSON.stringify(request) == '{}') {
return this.debuggee.sendCommand(
'Fetch.continueRequest', { requestId: this.id });
}
return this.debuggee.sendCommand(
'Fetch.continueRequest', Object.assign({ requestId: this.id }, request));
'Fetch.continueRequest', {
requestId: this.id,
method: request.method,
url: request.url,
headers: FetchIntercepted.convertHeaders(request.headers)
});
}

async continueResponseInternal(response: Partial<InterceptedData>) {
Expand Down

0 comments on commit 44c235f

Please sign in to comment.