How to use the @hint/utils-connector-tools.normalizeHeaders function in @hint/utils-connector-tools

To help you get started, we’ve selected a few @hint/utils-connector-tools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webhintio / hint / packages / connector-puppeteer / src / connector.ts View on Github external
private async onRequest(request: puppeteer.Request) {
        /* istanbul ignore next */
        if (this.isIgnoredMethod(request.method())) {
            return;
        }

        if (request.isNavigationRequest()) {
            this._headers = normalizeHeaders(request.headers())!;
        }

        const { name, payload } = onRequestHandler(request);

        await this._engine.emitAsync(name, payload);
    }
github webhintio / hint / packages / utils-debugging-protocol-common / src / debugging-protocol-connector.ts View on Github external
debug(`Error finding element for request ${requestResponse.requestId}. element will be null`);
            }
        }

        const response: Response = requestResponse.getResponse(element);

        // Doing a check so TypeScript is happy during `normalizeHeaders` later on
        if (!requestResponse.responseReceived) {

            const message = `Trying to emit "fetch::end" but no responseReceived for ${requestResponse.requestId} found`;

            throw new Error(message);
        }

        const request: Request = {
            headers: normalizeHeaders(requestResponse.responseReceived.response.requestHeaders) as HttpHeaders,
            url: originalUrl
        };

        const data: FetchEnd = {
            element,
            request,
            resource: resourceUrl,
            response
        };

        if (isTarget) {
            this._targetNetworkData = {
                request,
                response
            };
github webhintio / hint / packages / connector-puppeteer / src / lib / create-fetchend-payload.ts View on Github external
return async function (this: any) {

        const that = this; // eslint-disable-line

        if (that._rawResponse) {
            return that._rawResponse;
        }

        const rawContent = await response.buffer();
        const responseHeaders = normalizeHeaders(response.headers())!;

        if (rawContent && rawContent.length.toString() === responseHeaders['content-length']) {
            // Response wasn't compressed so both buffers are the same
            return rawContent;
        }

        const requestHeaders = response.request().headers();
        const responseUrl = response.url();

        /*
         * Real browser connectors automatically request using HTTP2. This spec has
         * [`Pseudo-Header Fields`](https://tools.ietf.org/html/rfc7540#section-8.1.2.3):
         * `:authority`, `:method`, `:path` and `:scheme`.
         *
         * An example of request with those `Pseudo-Header Fields` to google.com:
         *
github webhintio / hint / packages / utils-debugging-protocol-common / src / request-response.ts View on Github external
public getResponse(element: HTMLElement | null): Response {
        if (!this._response) {

            const { headers, status } = this.responseReceived!.response;
            const normalizedHeaders = normalizeHeaders(headers);
            const that = this;

            let rawContent = Buffer.alloc(0);
            let rBody = {
                content: '',
                rawContent,
                rawResponse: () => {
                    return Promise.resolve(Buffer.alloc(0));
                }
            };

            if (this._responseBody) {
                const { body, base64Encoded } = this._responseBody;
                const encoding = base64Encoded ? 'base64' : 'utf-8';
                const content = base64Encoded ? atob(body) : body; // There are some JS responses that are base64 encoded for some reason
github webhintio / hint / packages / connector-puppeteer / src / connector.ts View on Github external
public get headers() {
        return this._targetNetworkData &&
            this._targetNetworkData.response &&
            normalizeHeaders(this._targetNetworkData.response.headers) ||
            undefined;
    }
}
github webhintio / hint / packages / utils-debugging-protocol-common / src / debugging-protocol-connector.ts View on Github external
public get headers() {
        return this._targetNetworkData &&
            this._targetNetworkData.response &&
            normalizeHeaders(this._targetNetworkData.response.headers) ||
            undefined;
    }