Skip to content
Permalink
Browse files

Fix: Ignore certain HTTP methods

Close #3412
  • Loading branch information
sarvaje authored and molant committed Dec 4, 2019
1 parent 50ffbf3 commit 68f78788aa7554ee0070b53e93e6a19a4495b06e
Showing with 15 additions and 0 deletions.
  1. +15 −0 packages/connector-puppeteer/src/connector.ts
@@ -50,6 +50,7 @@ export default class PuppeteerConnector implements IConnector {
private _engine: Engine;
private _finalHref = '';
private _headers: HttpHeaders = {};
private _ignoredMethods: puppeteer.HttpMethod[] = ['OPTIONS'];
private _listeners: Map<EventName, Function> = new Map();
private _originalDocument: HTMLDocument | undefined;
private _page!: puppeteer.Page;
@@ -92,6 +93,10 @@ export default class PuppeteerConnector implements IConnector {
}
}

private isIgnoredMethod(method: puppeteer.HttpMethod) {
return this._ignoredMethods.includes(method);
}

/** Transform general options to more specific `puppeteer` ones if applicable. */
private toPuppeteerOptions(options: ConnectorOptions = {}): LifecycleLaunchOptions {
const headless = 'headless' in options ?
@@ -146,6 +151,11 @@ export default class PuppeteerConnector implements IConnector {
}

private async onRequest(request: puppeteer.Request) {
/* istanbul ignore next */
if (this.isIgnoredMethod(request.method())) {
return;
}

if (request.isNavigationRequest()) {
this._headers = normalizeHeaders(request.headers())!;
}
@@ -180,6 +190,11 @@ export default class PuppeteerConnector implements IConnector {
}

private async onResponse(response: puppeteer.Response) {
/* istanbul ignore next */
if (this.isIgnoredMethod(response.request().method())) {
return;
}

const resource = response.url();
const isTarget = response.request().isNavigationRequest();
const status = response.status();

0 comments on commit 68f7878

Please sign in to comment.
You can’t perform that action at this time.