request: refactor mime types.
This commit is contained in:
parent
5375f8bf19
commit
cc2d49ea10
@ -268,7 +268,7 @@ function Request(options) {
|
||||
this.response = null;
|
||||
this.statusCode = 0;
|
||||
this.headers = null;
|
||||
this.type = 'binary';
|
||||
this.type = 'bin';
|
||||
this.redirects = 0;
|
||||
this.timeout = null;
|
||||
this.finished = false;
|
||||
@ -384,7 +384,7 @@ Request.prototype.finish = function finish(err) {
|
||||
|
||||
if (this.options.buffer && this.body) {
|
||||
switch (this.type) {
|
||||
case 'binary':
|
||||
case 'bin':
|
||||
this.body = Buffer.concat(this.body);
|
||||
break;
|
||||
case 'json':
|
||||
@ -453,7 +453,7 @@ Request.prototype._onResponse = function _onResponse(response) {
|
||||
this.emit('response', response);
|
||||
|
||||
if (this.options.buffer) {
|
||||
if (this.type !== 'binary') {
|
||||
if (this.type !== 'bin') {
|
||||
this.decoder = new StringDecoder('utf8');
|
||||
this.body = '';
|
||||
} else {
|
||||
@ -495,7 +495,7 @@ Request.prototype._onEnd = function _onEnd(err) {
|
||||
* @param {Object?} options.json
|
||||
* @param {Object?} options.form
|
||||
* @param {String?} options.type - One of `"json"`,
|
||||
* `"form"`, `"text"`, or `"binary"`.
|
||||
* `"form"`, `"text"`, or `"bin"`.
|
||||
* @param {String?} options.agent - User agent string.
|
||||
* @param {Object?} [options.strictSSL=true] - Whether to accept bad certs.
|
||||
* @param {Object?} options.method - HTTP method.
|
||||
@ -575,11 +575,11 @@ function parseType(type) {
|
||||
case 'text/css':
|
||||
return 'css';
|
||||
case 'text/plain':
|
||||
return 'text';
|
||||
return 'txt';
|
||||
case 'application/octet-stream':
|
||||
return 'binary';
|
||||
return 'bin';
|
||||
default:
|
||||
return 'binary';
|
||||
return 'bin';
|
||||
}
|
||||
}
|
||||
|
||||
@ -595,9 +595,9 @@ function getType(type) {
|
||||
return 'application/javascript; charset=utf-8';
|
||||
case 'css':
|
||||
return 'text/css; charset=utf-8';
|
||||
case 'text':
|
||||
case 'txt':
|
||||
return 'text/plain; charset=utf-8';
|
||||
case 'binary':
|
||||
case 'bin':
|
||||
return 'application/octet-stream';
|
||||
default:
|
||||
throw new Error('Unknown type: ' + type);
|
||||
|
||||
@ -2012,7 +2012,7 @@ Pool.prototype.getIP = co(function* getIP() {
|
||||
res = yield request.promise({
|
||||
method: 'GET',
|
||||
uri: 'http://icanhazip.com',
|
||||
expect: 'text',
|
||||
expect: 'txt',
|
||||
timeout: 3000
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user