Sha256: c2c59e04f08804b56c354458395ac3986a6d608f0f5b022864b165c11b85f970

Contents?: true

Size: 1011 Bytes

Versions: 1

Compression:

Stored size: 1011 Bytes

Contents

'use strict';

const { MongoCryptKMSRequestNetworkTimeoutError } = require('../errors');
const http = require('http');

/**
 * @param {URL | string} url
 * @param {http.RequestOptions} options
 *
 * @returns { Promise<{ body: string, status: number }> }
 * @ignore
 */
function get(url, options = {}) {
  return new Promise((resolve, reject) => {
    let timeoutId;
    const request = http
      .get(url, options, response => {
        response.setEncoding('utf8');
        let body = '';
        response.on('data', chunk => (body += chunk));
        response.on('end', () => {
          clearTimeout(timeoutId);
          resolve({ status: response.statusCode, body });
        });
      })
      .on('error', error => {
        clearTimeout(timeoutId);
        reject(error);
      })
      .end();
    timeoutId = setTimeout(() => {
      request.destroy(
        new MongoCryptKMSRequestNetworkTimeoutError(`request timed out after 10 seconds`)
      );
    }, 10000);
  });
}

module.exports = { get };

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
libmongocrypt-helper-1.8.0.0.1001 ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js