added suggestCompression config

This commit is contained in:
Spencer Alger
2014-09-04 16:02:49 -07:00
parent a0ffe50745
commit 6e2c2a8417
2 changed files with 46 additions and 3 deletions

View File

@ -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;
});