Sha256: 2169080b41795cfc99c0c08d5f2e246f583012a0e8d894611ef31c4c0bc6b413

Contents?: true

Size: 1.29 KB

Versions: 12

Compression:

Stored size: 1.29 KB

Contents

'use strict';

const dns = require('dns');
const util = require('util');

const REQUEST_TIMEOUT = 10000;

// callback(err, data)
async function externalRequest(transport, options, callback) {
    // perform the DNS lookup manually so that the HTTP host header generated by
    // http.get will contain the IP address, this is needed because since Chrome
    // 66 the host header cannot contain an host name different than localhost
    // (see https://github.com/cyrus-and/chrome-remote-interface/issues/340)
    if (!options.useHostName) {
        try {
            const {address} = await util.promisify(dns.lookup)(options.host);
            options.host = address;
        } catch (err) {
            callback(err);
            return;
        }
    }
    // perform the actual request
    const request = transport.get(options, (response) => {
        let data = '';
        response.on('data', (chunk) => {
            data += chunk;
        });
        response.on('end', () => {
            if (response.statusCode === 200) {
                callback(null, data);
            } else {
                callback(new Error(data));
            }
        });
    });
    request.setTimeout(REQUEST_TIMEOUT, () => {
        request.abort();
    });
    request.on('error', callback);
}

module.exports = externalRequest;

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/external-request.js
opal-1.8.2 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/external-request.js
opal-1.8.1 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/external-request.js
opal-1.8.0 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/external-request.js
opal-1.8.0.beta1 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/external-request.js
opal-1.7.4 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/external-request.js
opal-1.8.0.alpha1 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/external-request.js
opal-1.7.3 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/external-request.js
opal-1.7.2 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/external-request.js
opal-1.7.1 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/external-request.js
opal-1.7.0 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/external-request.js
opal-1.7.0.rc1 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/external-request.js