@crawly/superagent
Version:
elegant & feature rich browser / node HTTP with a fluent API
1,393 lines (1,097 loc) • 122 kB
JavaScript
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
/**
* Module dependencies.
*/
// eslint-disable-next-line node/no-deprecated-api
var _require = require('url'),
parse = _require.parse,
format = _require.format,
resolve = _require.resolve;
var Stream = require('stream');
var https = require('https');
var http = require('http');
var fs = require('fs');
var zlib = require('zlib');
var util = require('util');
var qs = require('qs');
var mime = require('mime');
var methods = require('methods');
var FormData = require('form-data');
var formidable = require('formidable');
var debug = require('debug')('superagent');
var CookieJar = require('cookiejar');
var semver = require('semver');
var safeStringify = require('fast-safe-stringify');
var utils = require('../utils');
var RequestBase = require('../request-base');
var _require2 = require('./unzip'),
unzip = _require2.unzip;
var Response = require('./response');
var http2;
if (semver.gte(process.version, 'v10.10.0')) http2 = require('./http2wrapper');
function request(method, url) {
// callback
if (typeof url === 'function') {
return new exports.Request('GET', method).end(url);
} // url first
if (arguments.length === 1) {
return new exports.Request('GET', method);
}
return new exports.Request(method, url);
}
module.exports = request;
exports = module.exports;
/**
* Expose `Request`.
*/
exports.Request = Request;
/**
* Expose the agent function
*/
exports.agent = require('./agent');
/**
* Noop.
*/
function noop() {}
/**
* Expose `Response`.
*/
exports.Response = Response;
/**
* Define "form" mime type.
*/
mime.define({
'application/x-www-form-urlencoded': ['form', 'urlencoded', 'form-data']
}, true);
/**
* Protocol map.
*/
exports.protocols = {
'http:': http,
'https:': https,
'http2:': http2
};
/**
* Default serialization map.
*
* superagent.serialize['application/xml'] = function(obj){
* return 'generated xml here';
* };
*
*/
exports.serialize = {
'application/x-www-form-urlencoded': qs.stringify,
'application/json': safeStringify
};
/**
* Default parsers.
*
* superagent.parse['application/xml'] = function(res, fn){
* fn(null, res);
* };
*
*/
exports.parse = require('./parsers');
/**
* Default buffering map. Can be used to set certain
* response types to buffer/not buffer.
*
* superagent.buffer['application/xml'] = true;
*/
exports.buffer = {};
/**
* Initialize internal header tracking properties on a request instance.
*
* @param {Object} req the instance
* @api private
*/
function _initHeaders(req) {
req._header = {// coerces header names to lowercase
};
req.header = {// preserves header name case
};
}
/**
* Initialize a new `Request` with the given `method` and `url`.
*
* @param {String} method
* @param {String|Object} url
* @api public
*/
function Request(method, url) {
Stream.call(this);
if (typeof url !== 'string') url = format(url);
this._enableHttp2 = Boolean(process.env.HTTP2_TEST); // internal only
this._agent = false;
this._formData = null;
this.method = method;
this.url = url;
_initHeaders(this);
this.writable = true;
this._redirects = 0;
this.redirects(method === 'HEAD' ? 0 : 5);
this.cookies = '';
this.qs = {};
this._query = [];
this.qsRaw = this._query; // Unused, for backwards compatibility only
this._redirectList = [];
this._streamRequest = false;
this.once('end', this.clearTimeout.bind(this));
}
/**
* Inherit from `Stream` (which inherits from `EventEmitter`).
* Mixin `RequestBase`.
*/
util.inherits(Request, Stream); // eslint-disable-next-line new-cap
RequestBase(Request.prototype);
/**
* Enable or Disable http2.
*
* Enable http2.
*
* ``` js
* request.get('http://localhost/')
* .http2()
* .end(callback);
*
* request.get('http://localhost/')
* .http2(true)
* .end(callback);
* ```
*
* Disable http2.
*
* ``` js
* request = request.http2();
* request.get('http://localhost/')
* .http2(false)
* .end(callback);
* ```
*
* @param {Boolean} enable
* @return {Request} for chaining
* @api public
*/
Request.prototype.http2 = function (bool) {
if (exports.protocols['http2:'] === undefined) {
throw new Error('superagent: this version of Node.js does not support http2');
}
this._enableHttp2 = bool === undefined ? true : bool;
return this;
};
/**
* Queue the given `file` as an attachment to the specified `field`,
* with optional `options` (or filename).
*
* ``` js
* request.post('http://localhost/upload')
* .attach('field', Buffer.from('<b>Hello world</b>'), 'hello.html')
* .end(callback);
* ```
*
* A filename may also be used:
*
* ``` js
* request.post('http://localhost/upload')
* .attach('files', 'image.jpg')
* .end(callback);
* ```
*
* @param {String} field
* @param {String|fs.ReadStream|Buffer} file
* @param {String|Object} options
* @return {Request} for chaining
* @api public
*/
Request.prototype.attach = function (field, file, options) {
if (file) {
if (this._data) {
throw new Error("superagent can't mix .send() and .attach()");
}
var o = options || {};
if (typeof options === 'string') {
o = {
filename: options
};
}
if (typeof file === 'string') {
if (!o.filename) o.filename = file;
debug('creating `fs.ReadStream` instance for file: %s', file);
file = fs.createReadStream(file);
} else if (!o.filename && file.path) {
o.filename = file.path;
}
this._getFormData().append(field, file, o);
}
return this;
};
Request.prototype._getFormData = function () {
var _this = this;
if (!this._formData) {
this._formData = new FormData();
this._formData.on('error', function (err) {
debug('FormData error', err);
if (_this.called) {
// The request has already finished and the callback was called.
// Silently ignore the error.
return;
}
_this.callback(err);
_this.abort();
});
}
return this._formData;
};
/**
* Gets/sets the `Agent` to use for this HTTP request. The default (if this
* function is not called) is to opt out of connection pooling (`agent: false`).
*
* @param {http.Agent} agent
* @return {http.Agent}
* @api public
*/
Request.prototype.agent = function (agent) {
if (arguments.length === 0) return this._agent;
this._agent = agent;
return this;
};
/**
* Set _Content-Type_ response header passed through `mime.getType()`.
*
* Examples:
*
* request.post('/')
* .type('xml')
* .send(xmlstring)
* .end(callback);
*
* request.post('/')
* .type('json')
* .send(jsonstring)
* .end(callback);
*
* request.post('/')
* .type('application/json')
* .send(jsonstring)
* .end(callback);
*
* @param {String} type
* @return {Request} for chaining
* @api public
*/
Request.prototype.type = function (type) {
return this.set('Content-Type', type.includes('/') ? type : mime.getType(type));
};
/**
* Set _Accept_ response header passed through `mime.getType()`.
*
* Examples:
*
* superagent.types.json = 'application/json';
*
* request.get('/agent')
* .accept('json')
* .end(callback);
*
* request.get('/agent')
* .accept('application/json')
* .end(callback);
*
* @param {String} accept
* @return {Request} for chaining
* @api public
*/
Request.prototype.accept = function (type) {
return this.set('Accept', type.includes('/') ? type : mime.getType(type));
};
/**
* Add query-string `val`.
*
* Examples:
*
* request.get('/shoes')
* .query('size=10')
* .query({ color: 'blue' })
*
* @param {Object|String} val
* @return {Request} for chaining
* @api public
*/
Request.prototype.query = function (val) {
if (typeof val === 'string') {
this._query.push(val);
} else {
Object.assign(this.qs, val);
}
return this;
};
/**
* Write raw `data` / `encoding` to the socket.
*
* @param {Buffer|String} data
* @param {String} encoding
* @return {Boolean}
* @api public
*/
Request.prototype.write = function (data, encoding) {
var req = this.request();
if (!this._streamRequest) {
this._streamRequest = true;
}
return req.write(data, encoding);
};
/**
* Pipe the request body to `stream`.
*
* @param {Stream} stream
* @param {Object} options
* @return {Stream}
* @api public
*/
Request.prototype.pipe = function (stream, options) {
this.piped = true; // HACK...
this.buffer(false);
this.end();
return this._pipeContinue(stream, options);
};
Request.prototype._pipeContinue = function (stream, options) {
var _this2 = this;
this.req.once('response', function (res) {
// redirect
if (isRedirect(res.statusCode) && _this2._redirects++ !== _this2._maxRedirects) {
return _this2._redirect(res) === _this2 ? _this2._pipeContinue(stream, options) : undefined;
}
_this2.res = res;
_this2._emitResponse();
if (_this2._aborted) return;
if (_this2._shouldUnzip(res)) {
var unzipObj = zlib.createUnzip();
unzipObj.on('error', function (err) {
if (err && err.code === 'Z_BUF_ERROR') {
// unexpected end of file is ignored by browsers and curl
stream.emit('end');
return;
}
stream.emit('error', err);
});
res.pipe(unzipObj).pipe(stream, options);
} else {
res.pipe(stream, options);
}
res.once('end', function () {
_this2.emit('end');
});
});
return stream;
};
/**
* Enable / disable buffering.
*
* @return {Boolean} [val]
* @return {Request} for chaining
* @api public
*/
Request.prototype.buffer = function (val) {
this._buffer = val !== false;
return this;
};
/**
* Redirect to `url
*
* @param {IncomingMessage} res
* @return {Request} for chaining
* @api private
*/
Request.prototype._redirect = function (res) {
var url = res.headers.location;
if (!url) {
return this.callback(new Error('No location header for redirect'), res);
}
debug('redirect %s -> %s', this.url, url); // location
url = resolve(this.url, url); // ensure the response is being consumed
// this is required for Node v0.10+
res.resume();
var headers = this.req.getHeaders ? this.req.getHeaders() : this.req._headers;
var changesOrigin = parse(url).host !== parse(this.url).host; // implementation of 302 following defacto standard
if (res.statusCode === 301 || res.statusCode === 302) {
// strip Content-* related fields
// in case of POST etc
headers = utils.cleanHeader(headers, changesOrigin); // force GET
this.method = this.method === 'HEAD' ? 'HEAD' : 'GET'; // clear data
this._data = null;
} // 303 is always GET
if (res.statusCode === 303) {
// strip Content-* related fields
// in case of POST etc
headers = utils.cleanHeader(headers, changesOrigin); // force method
this.method = 'GET'; // clear data
this._data = null;
} // 307 preserves method
// 308 preserves method
delete headers.host;
delete this.req;
delete this._formData; // remove all add header except User-Agent
_initHeaders(this); // redirect
this._endCalled = false;
this.url = url;
this.qs = {};
this._query.length = 0;
this.set(headers);
this.emit('redirect', res);
this._redirectList.push(this.url);
this.end(this._callback);
return this;
};
/**
* Set Authorization field value with `user` and `pass`.
*
* Examples:
*
* .auth('tobi', 'learnboost')
* .auth('tobi:learnboost')
* .auth('tobi')
* .auth(accessToken, { type: 'bearer' })
*
* @param {String} user
* @param {String} [pass]
* @param {Object} [options] options with authorization type 'basic' or 'bearer' ('basic' is default)
* @return {Request} for chaining
* @api public
*/
Request.prototype.auth = function (user, pass, options) {
if (arguments.length === 1) pass = '';
if (_typeof(pass) === 'object' && pass !== null) {
// pass is optional and can be replaced with options
options = pass;
pass = '';
}
if (!options) {
options = {
type: 'basic'
};
}
var encoder = function encoder(string) {
return Buffer.from(string).toString('base64');
};
return this._auth(user, pass, options, encoder);
};
/**
* Set the certificate authority option for https request.
*
* @param {Buffer | Array} cert
* @return {Request} for chaining
* @api public
*/
Request.prototype.ca = function (cert) {
this._ca = cert;
return this;
};
/**
* Set the client certificate key option for https request.
*
* @param {Buffer | String} cert
* @return {Request} for chaining
* @api public
*/
Request.prototype.key = function (cert) {
this._key = cert;
return this;
};
/**
* Set the key, certificate, and CA certs of the client in PFX or PKCS12 format.
*
* @param {Buffer | String} cert
* @return {Request} for chaining
* @api public
*/
Request.prototype.pfx = function (cert) {
if (_typeof(cert) === 'object' && !Buffer.isBuffer(cert)) {
this._pfx = cert.pfx;
this._passphrase = cert.passphrase;
} else {
this._pfx = cert;
}
return this;
};
/**
* Set the client certificate option for https request.
*
* @param {Buffer | String} cert
* @return {Request} for chaining
* @api public
*/
Request.prototype.cert = function (cert) {
this._cert = cert;
return this;
};
/**
* Do not reject expired or invalid TLS certs.
* sets `rejectUnauthorized=true`. Be warned that this allows MITM attacks.
*
* @return {Request} for chaining
* @api public
*/
Request.prototype.disableTLSCerts = function () {
this._disableTLSCerts = true;
return this;
};
/**
* Return an http[s] request.
*
* @return {OutgoingMessage}
* @api private
*/
// eslint-disable-next-line complexity
Request.prototype.request = function () {
var _this3 = this;
if (this.req) return this.req;
var options = {};
try {
var query = qs.stringify(this.qs, {
indices: false,
strictNullHandling: true
});
if (query) {
this.qs = {};
this._query.push(query);
}
this._finalizeQueryString();
} catch (err) {
return this.emit('error', err);
}
var url = this.url;
var retries = this._retries; // Capture backticks as-is from the final query string built above.
// Note: this'll only find backticks entered in req.query(String)
// calls, because qs.stringify unconditionally encodes backticks.
var queryStringBackticks;
if (url.includes('`')) {
var queryStartIndex = url.indexOf('?');
if (queryStartIndex !== -1) {
var queryString = url.slice(queryStartIndex + 1);
queryStringBackticks = queryString.match(/`|%60/g);
}
} // default to http://
if (url.indexOf('http') !== 0) url = "http://".concat(url);
url = parse(url); // See https://github.com/visionmedia/superagent/issues/1367
if (queryStringBackticks) {
var i = 0;
url.query = url.query.replace(/%60/g, function () {
return queryStringBackticks[i++];
});
url.search = "?".concat(url.query);
url.path = url.pathname + url.search;
} // support unix sockets
if (/^https?\+unix:/.test(url.protocol) === true) {
// get the protocol
url.protocol = "".concat(url.protocol.split('+')[0], ":"); // get the socket, path
var unixParts = url.path.match(/^([^/]+)(.+)$/);
options.socketPath = unixParts[1].replace(/%2F/g, '/');
url.path = unixParts[2];
} // Override IP address of a hostname
if (this._connectOverride) {
var _url = url,
hostname = _url.hostname;
var match = hostname in this._connectOverride ? this._connectOverride[hostname] : this._connectOverride['*'];
if (match) {
// backup the real host
if (!this._header.host) {
this.set('host', url.host);
}
var newHost;
var newPort;
if (_typeof(match) === 'object') {
newHost = match.host;
newPort = match.port;
} else {
newHost = match;
newPort = url.port;
} // wrap [ipv6]
url.host = /:/.test(newHost) ? "[".concat(newHost, "]") : newHost;
if (newPort) {
url.host += ":".concat(newPort);
url.port = newPort;
}
url.hostname = newHost;
}
} // options
options.method = this.method;
options.port = url.port;
options.path = url.path;
options.host = url.hostname;
options.ca = this._ca;
options.key = this._key;
options.pfx = this._pfx;
options.cert = this._cert;
options.passphrase = this._passphrase;
options.agent = this._agent;
options.rejectUnauthorized = typeof this._disableTLSCerts === 'boolean' ? !this._disableTLSCerts : process.env.NODE_TLS_REJECT_UNAUTHORIZED !== '0'; // Allows request.get('https://1.2.3.4/').set('Host', 'example.com')
if (this._header.host) {
options.servername = this._header.host.replace(/:\d+$/, '');
}
if (this._trustLocalhost && /^(?:localhost|127\.0\.0\.\d+|(0*:)+:0*1)$/.test(url.hostname)) {
options.rejectUnauthorized = false;
} // initiate request
var mod = this._enableHttp2 ? exports.protocols['http2:'].setProtocol(url.protocol) : exports.protocols[url.protocol]; // request
this.req = mod.request(options);
var req = this.req; // set tcp no delay
req.setNoDelay(true);
if (options.method !== 'HEAD') {
req.setHeader('Accept-Encoding', 'gzip, deflate');
}
this.protocol = url.protocol;
this.host = url.host; // expose events
req.once('drain', function () {
_this3.emit('drain');
});
req.on('error', function (err) {
// flag abortion here for out timeouts
// because node will emit a faux-error "socket hang up"
// when request is aborted before a connection is made
if (_this3._aborted) return; // if not the same, we are in the **old** (cancelled) request,
// so need to continue (same as for above)
if (_this3._retries !== retries) return; // if we've received a response then we don't want to let
// an error in the request blow up the response
if (_this3.response) return;
_this3.callback(err);
}); // auth
if (url.auth) {
var auth = url.auth.split(':');
this.auth(auth[0], auth[1]);
}
if (this.username && this.password) {
this.auth(this.username, this.password);
}
for (var key in this.header) {
if (Object.prototype.hasOwnProperty.call(this.header, key)) req.setHeader(key, this.header[key]);
} // add cookies
if (this.cookies) {
if (Object.prototype.hasOwnProperty.call(this._header, 'cookie')) {
// merge
var tmpJar = new CookieJar.CookieJar();
tmpJar.setCookies(this._header.cookie.split(';'));
tmpJar.setCookies(this.cookies.split(';'));
req.setHeader('Cookie', tmpJar.getCookies(CookieJar.CookieAccessInfo.All).toValueString());
} else {
req.setHeader('Cookie', this.cookies);
}
}
return req;
};
/**
* Invoke the callback with `err` and `res`
* and handle arity check.
*
* @param {Error} err
* @param {Response} res
* @api private
*/
Request.prototype.callback = function (err, res) {
var _this4 = this;
return new Promise(function (resolve) {
var fnShouldRetry = function fnShouldRetry(shouldRetry) {
if (shouldRetry) {
_this4._retry().then(resolve).catch(function (err_) {
err = err_;
fnShouldRetry(false);
});
return;
} // Avoid the error which is emitted from 'socket hang up' to cause the fn undefined error on JS runtime.
var fn = _this4._callback || noop;
_this4.clearTimeout();
if (_this4.called) return;
_this4.called = true;
if (!err) {
try {
if (!_this4._isResponseOK(res)) {
var msg = 'Unsuccessful HTTP response';
if (res) {
msg = http.STATUS_CODES[res.status] || msg;
}
err = new Error(msg);
err.status = res ? res.status : undefined;
}
} catch (err_) {
err = err_;
}
} // It's important that the callback is called outside try/catch
// to avoid double callback
if (!err) {
fn(null, res);
return resolve();
}
err.response = res;
if (_this4._maxRetries) err.retries = _this4._retries - 1; // only emit error event if there is a listener
// otherwise we assume the callback to `.end()` will get the error
if (err && _this4.listeners('error').length > 0) {
_this4.emit('error', err);
}
fn(err, res);
return resolve();
};
_this4._shouldRetry(err, res).then(fnShouldRetry);
});
};
/**
* Check if `obj` is a host object,
*
* @param {Object} obj host object
* @return {Boolean} is a host object
* @api private
*/
Request.prototype._isHost = function (obj) {
return Buffer.isBuffer(obj) || obj instanceof Stream || obj instanceof FormData;
};
/**
* Initiate request, invoking callback `fn(err, res)`
* with an instanceof `Response`.
*
* @param {Function} fn
* @return {Request} for chaining
* @api public
*/
Request.prototype._emitResponse = function (body, files) {
var response = new Response(this);
this.response = response;
response.redirects = this._redirectList;
if (undefined !== body) {
response.body = body;
}
response.files = files;
if (this._endCalled) {
response.pipe = function () {
throw new Error("end() has already been called, so it's too late to start piping");
};
}
this.emit('response', response);
return response;
};
Request.prototype.end = function (fn) {
this.request();
debug('%s %s', this.method, this.url);
if (this._endCalled) {
throw new Error('.end() was called twice. This is not supported in superagent');
}
this._endCalled = true; // store callback
this._callback = fn || noop;
this._end();
};
Request.prototype._end = function () {
var _this5 = this;
if (this._aborted) return this.callback(new Error('The request has been aborted even before .end() was called'));
var data = this._data;
var req = this.req;
var method = this.method;
this._setTimeouts(); // body
if (method !== 'HEAD' && !req._headerSent) {
// serialize stuff
if (typeof data !== 'string') {
var contentType = req.getHeader('Content-Type'); // Parse out just the content type from the header (ignore the charset)
if (contentType) contentType = contentType.split(';')[0];
var serialize = this._serializer || exports.serialize[contentType];
if (!serialize && isJSON(contentType)) {
serialize = exports.serialize['application/json'];
}
if (serialize) data = serialize(data);
} // content-length
if (data && !req.getHeader('Content-Length')) {
req.setHeader('Content-Length', Buffer.isBuffer(data) ? data.length : Buffer.byteLength(data));
}
} // response
// eslint-disable-next-line complexity
req.once('response', function (res) {
debug('%s %s -> %s', _this5.method, _this5.url, res.statusCode);
if (_this5._responseTimeoutTimer) {
clearTimeout(_this5._responseTimeoutTimer);
}
if (_this5.piped) {
return;
}
var max = _this5._maxRedirects;
var mime = utils.type(res.headers['content-type'] || '') || 'text/plain';
var type = mime.split('/')[0];
var multipart = type === 'multipart';
var redirect = isRedirect(res.statusCode);
var responseType = _this5._responseType;
_this5.res = res; // redirect
if (redirect && _this5._redirects++ !== max) {
return _this5._redirect(res);
}
if (_this5.method === 'HEAD') {
_this5.emit('end');
_this5.callback(null, _this5._emitResponse());
return;
} // zlib support
if (_this5._shouldUnzip(res)) {
unzip(req, res);
}
var buffer = _this5._buffer;
if (buffer === undefined && mime in exports.buffer) {
buffer = Boolean(exports.buffer[mime]);
}
var parser = _this5._parser;
if (undefined === buffer) {
if (parser) {
console.warn("A custom superagent parser has been set, but buffering strategy for the parser hasn't been configured. Call `req.buffer(true or false)` or set `superagent.buffer[mime] = true or false`");
buffer = true;
}
}
if (!parser) {
if (responseType) {
parser = exports.parse.image; // It's actually a generic Buffer
buffer = true;
} else if (multipart) {
var form = new formidable.IncomingForm();
parser = form.parse.bind(form);
buffer = true;
} else if (isImageOrVideo(mime)) {
parser = exports.parse.image;
buffer = true; // For backwards-compatibility buffering default is ad-hoc MIME-dependent
} else if (exports.parse[mime]) {
parser = exports.parse[mime];
} else if (type === 'text') {
parser = exports.parse.text;
buffer = buffer !== false; // everyone wants their own white-labeled json
} else if (isJSON(mime)) {
parser = exports.parse['application/json'];
buffer = buffer !== false;
} else if (buffer) {
parser = exports.parse.text;
} else if (undefined === buffer) {
parser = exports.parse.image; // It's actually a generic Buffer
buffer = true;
}
} // by default only buffer text/*, json and messed up thing from hell
if (undefined === buffer && isText(mime) || isJSON(mime)) {
buffer = true;
}
_this5._resBuffered = buffer;
var parserHandlesEnd = false;
if (buffer) {
// Protectiona against zip bombs and other nuisance
var responseBytesLeft = _this5._maxResponseSize || 200000000;
res.on('data', function (buf) {
responseBytesLeft -= buf.byteLength || buf.length;
if (responseBytesLeft < 0) {
// This will propagate through error event
var err = new Error('Maximum response size reached');
err.code = 'ETOOLARGE'; // Parsers aren't required to observe error event,
// so would incorrectly report success
parserHandlesEnd = false; // Will emit error event
res.destroy(err);
}
});
}
if (parser) {
try {
// Unbuffered parsers are supposed to emit response early,
// which is weird BTW, because response.body won't be there.
parserHandlesEnd = buffer;
parser(res, function (err, obj, files) {
if (_this5.timedout) {
// Timeout has already handled all callbacks
return;
} // Intentional (non-timeout) abort is supposed to preserve partial response,
// even if it doesn't parse.
if (err && !_this5._aborted) {
return _this5.callback(err);
}
if (parserHandlesEnd) {
_this5.emit('end');
_this5.callback(null, _this5._emitResponse(obj, files));
}
});
} catch (err) {
_this5.callback(err);
return;
}
}
_this5.res = res; // unbuffered
if (!buffer) {
debug('unbuffered %s %s', _this5.method, _this5.url);
_this5.callback(null, _this5._emitResponse());
if (multipart) return; // allow multipart to handle end event
res.once('end', function () {
debug('end %s %s', _this5.method, _this5.url);
_this5.emit('end');
});
return;
} // terminating events
res.once('error', function (err) {
parserHandlesEnd = false;
_this5.callback(err, null);
});
if (!parserHandlesEnd) res.once('end', function () {
debug('end %s %s', _this5.method, _this5.url); // TODO: unless buffering emit earlier to stream
_this5.emit('end');
_this5.callback(null, _this5._emitResponse());
});
});
this.emit('request', this);
var getProgressMonitor = function getProgressMonitor() {
var lengthComputable = true;
var total = req.getHeader('Content-Length');
var loaded = 0;
var progress = new Stream.Transform();
progress._transform = function (chunk, encoding, cb) {
loaded += chunk.length;
_this5.emit('progress', {
direction: 'upload',
lengthComputable: lengthComputable,
loaded: loaded,
total: total
});
cb(null, chunk);
};
return progress;
};
var bufferToChunks = function bufferToChunks(buffer) {
var chunkSize = 16 * 1024; // default highWaterMark value
var chunking = new Stream.Readable();
var totalLength = buffer.length;
var remainder = totalLength % chunkSize;
var cutoff = totalLength - remainder;
for (var i = 0; i < cutoff; i += chunkSize) {
var chunk = buffer.slice(i, i + chunkSize);
chunking.push(chunk);
}
if (remainder > 0) {
var remainderBuffer = buffer.slice(-remainder);
chunking.push(remainderBuffer);
}
chunking.push(null); // no more data
return chunking;
}; // if a FormData instance got created, then we send that as the request body
var formData = this._formData;
if (formData) {
// set headers
var headers = formData.getHeaders();
for (var i in headers) {
if (Object.prototype.hasOwnProperty.call(headers, i)) {
debug('setting FormData header: "%s: %s"', i, headers[i]);
req.setHeader(i, headers[i]);
}
} // attempt to get "Content-Length" header
// eslint-disable-next-line handle-callback-err
formData.getLength(function (err, length) {
// TODO: Add chunked encoding when no length (if err)
debug('got FormData Content-Length: %s', length);
if (typeof length === 'number') {
req.setHeader('Content-Length', length);
}
formData.pipe(getProgressMonitor()).pipe(req);
});
} else if (Buffer.isBuffer(data)) {
bufferToChunks(data).pipe(getProgressMonitor()).pipe(req);
} else {
req.end(data);
}
}; // Check whether response has a non-0-sized gzip-encoded body
Request.prototype._shouldUnzip = function (res) {
if (res.statusCode === 204 || res.statusCode === 304) {
// These aren't supposed to have any body
return false;
} // header content is a string, and distinction between 0 and no information is crucial
if (res.headers['content-length'] === '0') {
// We know that the body is empty (unfortunately, this check does not cover chunked encoding)
return false;
} // console.log(res);
return /^\s*(?:deflate|gzip)\s*$/.test(res.headers['content-encoding']);
};
/**
* Overrides DNS for selected hostnames. Takes object mapping hostnames to IP addresses.
*
* When making a request to a URL with a hostname exactly matching a key in the object,
* use the given IP address to connect, instead of using DNS to resolve the hostname.
*
* A special host `*` matches every hostname (keep redirects in mind!)
*
* request.connect({
* 'test.example.com': '127.0.0.1',
* 'ipv6.example.com': '::1',
* })
*/
Request.prototype.connect = function (connectOverride) {
if (typeof connectOverride === 'string') {
this._connectOverride = {
'*': connectOverride
};
} else if (_typeof(connectOverride) === 'object') {
this._connectOverride = connectOverride;
} else {
this._connectOverride = undefined;
}
return this;
};
Request.prototype.trustLocalhost = function (toggle) {
this._trustLocalhost = toggle === undefined ? true : toggle;
return this;
}; // generate HTTP verb methods
if (!methods.includes('del')) {
// create a copy so we don't cause conflicts with
// other packages using the methods package and
// npm 3.x
methods = methods.slice(0);
methods.push('del');
}
methods.forEach(function (method) {
var name = method;
method = method === 'del' ? 'delete' : method;
method = method.toUpperCase();
request[name] = function (url, data, fn) {
var req = request(method, url);
if (typeof data === 'function') {
fn = data;
data = null;
}
if (data) {
if (method === 'GET' || method === 'HEAD') {
req.query(data);
} else {
req.send(data);
}
}
if (fn) req.end(fn);
return req;
};
});
/**
* Check if `mime` is text and should be buffered.
*
* @param {String} mime
* @return {Boolean}
* @api public
*/
function isText(mime) {
var parts = mime.split('/');
var type = parts[0];
var subtype = parts[1];
return type === 'text' || subtype === 'x-www-form-urlencoded';
}
function isImageOrVideo(mime) {
var type = mime.split('/')[0];
return type === 'image' || type === 'video';
}
/**
* Check if `mime` is json or has +json structured syntax suffix.
*
* @param {String} mime
* @return {Boolean}
* @api private
*/
function isJSON(mime) {
// should match /json or +json
// but not /json-seq
return /[/+]json($|[^-\w])/.test(mime);
}
/**
* Check if we should follow the redirect `code`.
*
* @param {Number} code
* @return {Boolean}
* @api private
*/
function isRedirect(code) {
return [301, 302, 303, 305, 307, 308].includes(code);
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ub2RlL2luZGV4LmpzIl0sIm5hbWVzIjpbInJlcXVpcmUiLCJwYXJzZSIsImZvcm1hdCIsInJlc29sdmUiLCJTdHJlYW0iLCJodHRwcyIsImh0dHAiLCJmcyIsInpsaWIiLCJ1dGlsIiwicXMiLCJtaW1lIiwibWV0aG9kcyIsIkZvcm1EYXRhIiwiZm9ybWlkYWJsZSIsImRlYnVnIiwiQ29va2llSmFyIiwic2VtdmVyIiwic2FmZVN0cmluZ2lmeSIsInV0aWxzIiwiUmVxdWVzdEJhc2UiLCJ1bnppcCIsIlJlc3BvbnNlIiwiaHR0cDIiLCJndGUiLCJwcm9jZXNzIiwidmVyc2lvbiIsInJlcXVlc3QiLCJtZXRob2QiLCJ1cmwiLCJleHBvcnRzIiwiUmVxdWVzdCIsImVuZCIsImFyZ3VtZW50cyIsImxlbmd0aCIsIm1vZHVsZSIsImFnZW50Iiwibm9vcCIsImRlZmluZSIsInByb3RvY29scyIsInNlcmlhbGl6ZSIsInN0cmluZ2lmeSIsImJ1ZmZlciIsIl9pbml0SGVhZGVycyIsInJlcSIsIl9oZWFkZXIiLCJoZWFkZXIiLCJjYWxsIiwiX2VuYWJsZUh0dHAyIiwiQm9vbGVhbiIsImVudiIsIkhUVFAyX1RFU1QiLCJfYWdlbnQiLCJfZm9ybURhdGEiLCJ3cml0YWJsZSIsIl9yZWRpcmVjdHMiLCJyZWRpcmVjdHMiLCJjb29raWVzIiwiX3F1ZXJ5IiwicXNSYXciLCJfcmVkaXJlY3R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