Send an HTTP request with the given options

@param {Object} options
357781
function request(options) {
    // Prepare options
    var opts = extend({}, options);
    opts.method = opts.method.toUpperCase();
    opts.uri = opts.uri.toString();

    // Instantiate request
    var xhr = new XMLHttpRequest();

    // Request finished handler
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4 && xhr.status !== 0 && opts.onComplete) {
            var err = null;
            if (xhr.status >= 400) {
                err = new Error('HTTP ' + xhr.status + ' ' + xhr.statusText);
                err.statusCode = xhr.status;
            }

            opts.onComplete(
                err,
                normalizeResponse(xhr),
                opts.json ? JSON.parse(xhr.responseText) : xhr.responseText
            );
        }
    };

    // Request failure handler
    xhr.onerror = function() {
        opts.onComplete(new Error('XHR error - CORS denied?'), normalizeResponse(xhr));
    };

    // Request progress handler
    if (opts.onProgress) {
        xhr.upload.addEventListener('progress', opts.onProgress, false);
    }

    // Open the request
    xhr.open(opts.method, opts.uri, true);

    // Apply request headers
    for (var key in opts.headers) {
        // We're not allowed to set certain headers in browsers
        if (disallowedHeaders.indexOf(key) > -1) {
            continue;
        }

        xhr.setRequestHeader(key, opts.headers[key]);
    }

    // Is this a JSON-request?
    if (opts.json) {
        xhr.setRequestHeader('Accept', 'application/json');

        // Do we have a payload to deliver as JSON?
        if (typeof opts.json !== 'boolean') {
            xhr.setRequestHeader('Content-Type', 'application/json');
            opts.body = JSON.stringify(opts.json);
        }
    }

    // Send the request
    xhr.send(opts.body);
}
435776
function _execute(httpMethod, urlSuffix, options, errorMessage) {
        const opts = {
            headers: {
                'Content-Type': 'application/json',
                'ngapimockid': ngapimockid
            }
        };

        if (options !== undefined) {
            opts.json = options;
        }

        return _handleRequest(httpMethod, urlSuffix, opts, errorMessage);
    }
1154439
function request(method, address, body, options) {
  let timeout = null;
  return new Promise((resolve, reject) => {
    try {
      const opts = _.merge({}, this.options, options, url.parse(address), {
        method,
      });

      // handle optional timeout
      if (typeof opts.timeout === 'number') {
        setTimeout(() => {
          reject(new Error(`${method} "${address}" timed out`));
          timeout = null;
        }, Math.floor(opts.timeout));
      }

      // create some request middleware to potentially
      // add headers ahead of time for auth or set cors, etc.
      const before =
        typeof opts.before === 'function'
          ? opts.before.call(this.context, method, address, opts)
          : () => null;

      const proto = opts.protocol === 'https:' ? https : http;

      return Promise.resolve(before)
        .then(() => {
          clearTimeout(timeout);

          const req = proto.request(opts, res => {
            let data = '';
            res
              .on('data', d => {
                data += d;
              })
              .on('error', error => {
                clearTimeout(timeout);
                reject(error);
              })
              .on('end', () => {
                clearTimeout(timeout);
                const parsedData = processData(res, data, opts);
                return parsedData instanceof Error
                  ? reject(parsedData)
                  : resolve(parsedData);
              });
          });

          req.on('error', error => {
            clearTimeout(timeout);
            reject(error);
          });

          if (method === Method.PUT || method === Method.POST) {
            req.write(processBody(opts, body));
          }
          req.end();
        })
        .catch(error => {
          clearTimeout(timeout);
          return reject(error);
        });
    } catch (error) {
      clearTimeout(timeout);
      return reject(error);
    }
  });
}
1305476
function HTTPOptions(options) {
  if (!(this instanceof HTTPOptions))
    return new HTTPOptions(options);

  this.network = Network.primary;
  this.logger = null;
  this.node = null;
  this.apiKey = base58.encode(random.randomBytes(20));
  this.apiHash = digest.hash256(Buffer.from(this.apiKey, 'ascii'));
  this.noAuth = false;

  this.prefix = null;
  this.host = '127.0.0.1';
  this.port = 8080;
  this.ssl = false;
  this.keyFile = null;
  this.certFile = null;

  this.fromOptions(options);
}
117370
public function put($url, $params = array(), $options = array())
    {
        return $this->request($url, self::PUT, $params, $options);
    }
660765
function request(url, options, callback) {
	var debug = require('debug')('wayback:http');
	debug('req', url);

	callback = typeof callback === 'undefined' ? options : callback;

	// @see https://www.npmjs.com/package/fetch
	var stream = new fetch(url, typeof options === 'object' ? options : undefined);

	stream.on('error', function(err) {
		debug('error', err);
		callback(err, null);
	});

	stream.on('meta', function(meta) {
		debug('resp', 'HTTP ' + meta.status);
		debug('resp', meta.responseHeaders);
		callback(null, stream);
	});
}
489827
function request(url, options, callback)
{
  var connection;

  if (typeof options == 'function')
  {
    callback = options;
    options  = {};
  }

  connection = hyperquest(url, options, once(function(error, response)
  {
    if (error)
    {
      callback(error, response);
      return;
    }

    // set body
    response.body = '';

    // accumulate response body
    response.on('data', function(data)
    {
      response.body += data.toString();
    });

    response.on('end', function()
    {
      callback(null, response);
    });
  }));

  return connection;
}
668582
function request(requestOptions, callback) {
	var debug = require('debug')('analyze-css:http'),
		fetch = require('node-fetch');

	debug('GET %s', requestOptions.url);
	debug('Options: %j', requestOptions);

	fetch(requestOptions.url, requestOptions).
	then(function(resp) {
		debug('HTTP %d %s', resp.status, resp.statusText);
		debug('Headers: %j', resp.headers._headers);

		if (!resp.ok) {
			var err = new Error('HTTP request failed: ' + (err ? err.toString() : 'received HTTP ' + resp.status + ' ' + resp.statusText));
			callback(err);
		} else {
			return resp.text(); // a promise
		}
	}).
	then(function(body) {
		debug('Received %d bytes of CSS', body.length);
		callback(null, body);
	}).
	catch(function(err) {
		debug(err);
		callback(err);
	});
}
789591
public function sendRequest(array $options = [])
    {
        $this->autoInitialize();

        if ( ! empty($options))
        {
            if ( ! $this->setOptions($options))
            {
                return false;
            }
        }

        $this->response = curl_exec($this->curl);

        return $this->response;
    }
1193107
function executeRequest(opType, options) {
    if (token) {
        options.token = token;
    }

    // TODO: need to handle ETAG values
    var context = api.getOperationContext(opType, options);

    return new Promise((resolve, reject) => {
        request(context, (err, response, body) => {
            if (err || response.statusCode >= 400 || (context.method == 'GET' && !body)) {
                reject(new ApiError(response.statusCode, context, err));
            } else {
                resolve(body);
            }
        });
    });
}
1072733
function send(url, method, options, resourceName) {
            var deferred = $q.defer();
            var key, val, paramArray = [];

            url = config.apiBase + url;
            options = options || {};

            // separate out data if it exists
            var data = options.data;
            delete options.data;

            // attempt to add id to the url if it exists
            if (url.indexOf('{_id}') >= 0) {
                if (options._id) {
                    url = url.replace('{_id}', options._id);
                    delete options._id;
                }
                else if (data && data._id) {
                    url = url.replace('{_id}', data._id);
                }
            }
            else if (method === 'GET' && options._id) {
                url += '/' + options._id;
                delete options._id;
            }

            var showErr = options.showErr !== false;
            delete options.showErr;

            // add params to the URL
            options.lang = options.lang || config.lang;
            for (key in options) {
                if (options.hasOwnProperty(key) && options[key]) {
                    val = options[key];
                    val = angular.isObject(val) ? JSON.stringify(val) : val;

                    paramArray.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
                }
            }

            // add params to URL
            if (paramArray.length) {
                url += '?' + paramArray.join('&');
            }

            // set up the api options
            var apiOpts = {
                method:     method,
                url:        url
            };

            // if the jwt exists, add it to the request
            var jwt = storage.get('jwt');
            if (jwt && jwt !== 'null') {  // hack fix; someone setting localStorage to 'null'
                apiOpts.headers = {
                    Authorization: jwt
                };
            }

            // add data to api options if available
            if (data) {
                apiOpts.data = data;
            }

            // emit events for start and end so realtime services can stop syncing for post
            eventBus.emit(resourceName + '.' + method.toLowerCase() + '.start');

            // finally make the http call
            $http(apiOpts)
                .then(function (respData) {
                    respData = respData || {};
                    saveOpts(apiOpts);
                    deferred.resolve(respData.data); //deferred.resolve(respData.data || respData);
                })
                .catch(function (err) {

                    // if (status > 450 && status < 499) {
                    //     eventBus.emit('error.' + status, err);
                    //     return;
                    // }

                    saveOpts(apiOpts);
                    // var isTimeout = !status || status === -1;

                    // if (!err && isTimeout) {
                    //     err = new Error('Cannot access back end');
                    // }
                    if (!err) {
                        err = new Error('error httpCode ' + status + ' headers ' +
                            JSON.stringify(headers) + ' conf ' +
                            JSON.stringify(conf));
                    }

                    if (showErr) {
                        eventBus.emit('error.api', err);
                    }

                    log.error(err, {
                        apiOpts: apiOpts,
                        status: status,
                        headers: headers
                    });

                    deferred.reject(err);
                })
                .finally(function () {
                    eventBus.emit(resourceName + '.' + method.toLowerCase() + '.end');
                });

            return deferred.promise;
        }
985729
function HttpConfig(options) {
    underscore.extend(this, HttpConfig._DEFAULT)
    CommonConfig.call(this, options)
    this.type = serverTypes.HTTP
}
315613
function WebRequest (options, callback) {
    request(options, function (err, response, body) {
        if (err) {
            return callback(err);
        }

        callback(null, body);
    });
}
303009
function RequestBuilder(options) {
  this._sendTelemetry = options._sendTelemetry === false ? options._sendTelemetry : true;
  this._telemetryInfo = options._telemetryInfo || null;
  this._timesToRetryFailedRequests = options._timesToRetryFailedRequests;
  this.headers = options.headers || {};
  this._universalLoginPage = options.universalLoginPage;
}
18513
function HTTPBaseOptions(options) {
  if (!(this instanceof HTTPBaseOptions))
    return new HTTPBaseOptions(options);

  this.host = '127.0.0.1';
  this.port = 8080;
  this.sockets = true;

  this.ssl = false;
  this.keyFile = null;
  this.certFile = null;
  this.key = null;
  this.cert = null;
  this.ca = null;

  if (options)
    this.fromOptions(options);
}
1028850
function RequestOptions(opts) {
        if (opts === void 0) { opts = {}; }
        var method = opts.method, headers = opts.headers, body = opts.body, url = opts.url, search = opts.search, params = opts.params, withCredentials = opts.withCredentials, responseType = opts.responseType;
        this.method = method != null ? normalizeMethodName(method) : null;
        this.headers = headers != null ? headers : null;
        this.body = body != null ? body : null;
        this.url = url != null ? url : null;
        this.params = this._mergeSearchParams(params || search);
        this.withCredentials = withCredentials != null ? withCredentials : null;
        this.responseType = responseType != null ? responseType : null;
    }
41440
function getRequest(path, options, callback) {
  if (typeof options === 'function') {
    callback = options;
    options = {
      method: 'get'
    };
  } else {
    options.method = 'get';
  }

  if (options.params) {
    var uri = url.parse(path, true);
    uri.query = _.merge({}, uri.query, options.params);
    path = url.format(uri);
    delete options.params;
  }

  sendRequest(path, options, callback);
}