/*!
Internal function to send a request. Must be called in the context of
the Fortune instance.

@param {Object} options
@return {Promise}
973834
function internalRequest (options) {
  var Promise = promise.Promise
  var flows = this.flows
  var recordTypes = this.recordTypes
  var adapter = this.adapter

  var context = setDefaults(options)
  var method = context.request.method
  var hasTransaction = 'transaction' in options

  // Start a promise chain.
  return Promise.resolve(context)

    .then(function (context) {
      var type = context.request.type
      var ids = context.request.ids
      var language = context.request.meta.language
      var error

      // Make sure that IDs are an array of unique values.
      if (ids) context.request.ids = unique(ids)

      // If a type is unspecified, block the request.
      if (type === null) {
        error = new BadRequestError(message('UnspecifiedType', language))
        error.isTypeUnspecified = true
        throw error
      }

      // If a type is specified and it doesn't exist, block the request.
      if (!recordTypes.hasOwnProperty(type))
        throw new NotFoundError(
          message('InvalidType', language, { type: type }))

      // Block invalid method.
      if (!(method in flows))
        throw new MethodError(
          message('InvalidMethod', language, { method: method }))

      return hasTransaction ?
        Promise.resolve(options.transaction) :
        adapter.beginTransaction()
    })

    .then(function (transaction) {
      var chain, flow, i, j

      context.transaction = transaction
      chain = Promise.resolve(context)
      flow = flows[method]

      for (i = 0, j = flow.length; i < j; i++)
        chain = chain.then(flow[i])

      return chain
    })

    .then(function (context) {
      return hasTransaction ?
        Promise.resolve() : context.transaction.endTransaction()
          .then(function () {
            var method = context.request.method
            var response = context.response
            var payload = response.payload

            if (!payload) return new Empty(response)
            if (method === createMethod) return new Created(response)

            return new OK(response)
          })
    })

  // This makes sure to call `endTransaction` before re-throwing the error.
    .catch(function (error) {
      return 'transaction' in context && !hasTransaction ?
        context.transaction.endTransaction(error)
          .then(throwError, throwError) :
        throwError()

      function throwError () {
        throw assign(error, context.response)
      }
    })
}
91481
function http(url, options) {
  return request(url, extend({}, this.options.http, options))
    .then(function(response) {
      if (!response.ok) throw response.status + '' + response.statusText;
      return response.text();
    });
}
1129965
async function buildRequest(method, url, params, options) {
  let param = {};
  let config = {};
  if (noneBodyMethod.indexOf(method) >= 0) {
    param = { params: { ...params }, ...reqConfig, ...options };
  } else {
    param = JSON.stringify(params);
    config = {
      ...reqConfig,
      headers: {
        'Content-Type': 'application/json',
        ...csrfConfig,
      },
    };
    config = Object.assign({}, config, options);
  }
  return axios[method](url, param, config);
}
380958
function send() {
		// Check form for errors
		if(!$("#transaction").val()) return alert('Missing parameter !');

		// Send
		nem.com.requests.transaction.announce(endpoint, $("#transaction").val()).then(function(res) {
			// If code >= 2, it's an error
			if (res.code >= 2) {
				alert(res.message);
			} else {
				alert(res.message);
			}
		}, function(err) {
			alert(err);
		})
	}
515666
function sendJson(data, options, callback) {
  var jsonData = JSON.stringify(data);
  return this.send(jsonData, options, callback);
}
1041838
function request( opts, clbk ) {
	var body;
	var req;
	var res;
	var err;
	var r;

	// debug( 'Query options: %s', JSON.stringify( opts ) );

	if ( RE.test( opts.protocol ) ) {
		req = https.request;
	} else {
		req = http.request;
	}
	body = '';
	r = req( opts, onResponse );
	r.on( 'error', onError );
	r.end();

	/**
	* FUNCTION: onError( error )
	*	Event listener invoked after encountering an error.
	*
	* @private
	* @param {Error} error - error object
	* @returns {Void}
	*/
	function onError( error ) {
		debug( 'Error encountered while querying endpoint: %s', error.message );
		if ( error instanceof Error ) {
			err = {
				'status': 500,
				'message': 'Request error: ' + error.message
			};
			return clbk( err );
		}
		return clbk( error, res, body );
	} // end FUNCTION onError()

	/**
	* FUNCTION: onResponse( response )
	*	Callback invoked after receiving an HTTP response.
	*
	* @private
	* @param {Object} response - HTTP response object
	* @returns {Void}
	*/
	function onResponse( response ) {
		res = response;
		if ( res.statusCode !== 200 ) {
			err = {
				'status': res.statusCode,
				'message': ''
			};
		}
		debug( 'Received a response from query endpoint.' );
		debug( 'Response status: %s.', res.statusCode );

		debug( 'Response headers: %s', JSON.stringify( res.headers ) );

		res.setEncoding( 'utf8' );
		res.on( 'data', onData );
		res.on( 'end', onEnd );
	} // end FUNCTION onResponse()

	/**
	* FUNCTION: onData( chunk )
	*	Event listener invoked upon receiving response data.
	*
	* @private
	* @param {String} chunk - data chunk
	* @returns {Void}
	*/
	function onData( chunk ) {
		body += chunk;
	} // end FUNCTION onData()

	/**
	* FUNCTION: onEnd()
	*	Event listener invoked upon a response end.
	*
	* @private
	* @returns {Void}
	*/
	function onEnd() {
		var data;
		if ( err ) {
			err.message = body;
			return onError( err );
		}
		// debug( 'Response body: %s', body );

		data = parse( body );
		if ( data instanceof Error ) {
			err = {
				'status': 502,
				'message': 'unable to parse endpoint response data as JSON: ' + data.message
			};
			return onError( err );
		}
		clbk( null, res, data );
	} // end FUNCTION onEnd()
}
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;
}
693872
async function request(url, options) {
  const response = await fetch(url, options);

  checkStatus(response);

  const data = await response.json();

  const ret = {
    data,
    headers: {},
  };

  if (response.headers.get('x-total-count')) {
    ret.headers['x-total-count'] = response.headers.get('x-total-count');
  }

  return ret;
}
1144252
function get(options, endCallback) {

      var reqOptions = initRequestOptions(options);

      var start = new Date();

      //console.log("ops", ops);
      //console.log("options get", options);
      request.get(reqOptions, function(error,response) {

          var end = new Date() - start;
          if (error) {
              return endCallback({code: error.code}, options);
          }

          var result = {};

          result.url = response.request.href;
          result.statusCode = response.statusCode;
          result.responseTime = end;

          // can be usefull to add the proxy into the response to log
          result.proxy = options.proxy;
          result.headers = response.headers;
          result.body = response.body;
          result.method = options.method;

          if (response.headers['content-encoding'] &&
              response.headers['content-encoding'].toLowerCase().indexOf('gzip') >= 0 ) {
              zlib.gunzip(response.body, function (error, body) {
                  if (error) {
                      result = null;
                      return onContent(error, endCallback, options);
                  }

                  result.body = body;

                  onContent(error, endCallback, options,result);
              });
          }
          else {
              onContent(error, endCallback, options,result);
          }

      }).setMaxListeners(0);
  }
118819
function makeRequest(apiKey, path, opts, callback) {
    var 
        key,
        req,
        dataStr = '';
        
    if(callback === undefined) {
        throw 'No callback defined';
        return;
    }

    path = '/plus/v1/' + path + '?key=' + apiKey;
    for(key in opts) {
        path += '&' + key + '=' + opts[key];
    }

    req = https.request({
        host: 'www.googleapis.com',
        port: 443,
        path: path,
        method: 'GET'
    }, function(res) {
        res.on('data', function(data) {
            dataStr += data;
        });
        
        res.on('end', function() {
            if(opts.alt === undefined || opts.alt.toLowerCase() == 'json') {
                try {
                    callback(null, JSON.parse(dataStr));
                } catch(err) {
                    callback(null, dataStr);
                }
            }
            else {
                callback(null, dataStr);
            }
        });
        
        res.on('close', function () {
            res.emit('end');
        });
    });
    req.end();
    
    req.on('error', function(err) {
        callback(err);
    });

    return req;
}
419021
function requestWithTokenCheck (defOptions, credentials, token, options, callback) {
  var returnedPromise;
  
  options.headers = options.headers || {};
  extend(true, options, defOptions);
  
  if (Date.now() - token.Timestamp > tokenUpdateTime) {
    returnedPromise = signIn(defOptions, credentials).then(function (data) {
      if (data[0].statusCode !== 200) {
        throw new Error(`${data[0].statusCode}: ${data[0].body.Message}`);
      } else {
        token.AuthenticationToken = data[0].body.AuthenticationToken;
        token.Timestamp = Date.now();
        options.headers.Authorization = `Basic ${token.AuthenticationToken}`;
        return request(options);
      }
    });
  } else {
    options.headers.Authorization = `Basic ${token.AuthenticationToken}`;
    returnedPromise = request(options);
  }
  
  returnedPromise.nodeify(callback);
  return returnedPromise;
}
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);
            }
        });
    });
}
1212669
function makeRequest(url) {
    return new Promise(function (resolve, reject) {
      request.get(url).responseType('json').type('application/json').accept('application/json').end(function (err, res) {
        if (err) {
          reject(err);
        } else {
          resolve(res.body);
        }
      });
    });
  }
1102470
function(options, callback) { // eslint-disable-line camelcase
      return nano.request({ path: encodeURIComponent(db) + '/_bulk_get',
        method: 'post',
        body: options }, callback);
    }
530314
function getRequire(context, options, tag, type, resource) {
    const loaders = normalizeLoaders(options.map[type]);
    const selectLoader = require.resolve('./loader.js');
    const request = {
        tag,
        type,
        options
    };
    const url = loaderUtils.stringifyRequest(context, `!${loaders}!${selectLoader}?${JSON.stringify(request)}!${resource}`)
    const prefix = tag === 'script' ? 'module.exports = ' : 'const $style = ';
    return `${prefix}require(${url});\r\n`;
}
692100
function Request(opts){
  this.method = opts.method || 'GET';
  this.uri = opts.uri;
  this.xd = !!opts.xd;
  this.async = false !== opts.async;
  this.data = undefined != opts.data ? opts.data : null;
  this.create();
}
51033
function get(options) {
    request({url: options.url, jar : true},
            function (error, response, body) {
        if (!error && response.statusCode == 200) {
            if( options.json ) {
                try {
                    var data = JSON.parse(body);
                    options.callback(null, data);
                } catch(e) {
                    e.response = body;
                    options.callback(e);
                }
            } else {
                options.callback(null, body);
            }
        } else {
            if( !error ) error = {status:response.statusCode};
            options.callback(error);
        }
    }
    );
}