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