added suggestCompression config
This commit is contained in:
@ -34,6 +34,7 @@ function Host(config) {
|
||||
this.auth = null;
|
||||
this.query = null;
|
||||
this.headers = null;
|
||||
this.suggestCompression = false;
|
||||
|
||||
if (typeof config === 'string') {
|
||||
if (!startsWithProtocolRE.test(config)) {
|
||||
@ -137,7 +138,7 @@ Host.prototype.makeUrl = function (params) {
|
||||
function objectPropertyGetter(prop, preOverride) {
|
||||
return function (overrides) {
|
||||
if (preOverride) {
|
||||
overrides = preOverride(overrides);
|
||||
overrides = preOverride.call(this, overrides);
|
||||
}
|
||||
|
||||
var obj = this[prop];
|
||||
@ -153,7 +154,16 @@ function objectPropertyGetter(prop, preOverride) {
|
||||
};
|
||||
}
|
||||
|
||||
Host.prototype.getHeaders = objectPropertyGetter('headers');
|
||||
Host.prototype.getHeaders = objectPropertyGetter('headers', function (overrides) {
|
||||
if (!this.suggestCompression) {
|
||||
return overrides;
|
||||
}
|
||||
|
||||
return _.defaults(overrides || {}, {
|
||||
'Accept-Encoding': 'gzip,deflate'
|
||||
});
|
||||
});
|
||||
|
||||
Host.prototype.getQuery = objectPropertyGetter('query', function (query) {
|
||||
return typeof query === 'string' ? qs.parse(query) : query;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user