diff --git a/src/node/index.js b/src/node/index.js index cdd5b8d9b..62b3c13c1 100644 --- a/src/node/index.js +++ b/src/node/index.js @@ -131,10 +131,6 @@ exports.buffer = {}; * @api private */ function _initHeaders(req) { - req._unset = { - // lowercase headers that were unset; this is used to suppress some default - // headers, such as Accept-Encoding and Content-Type - }; req._header = { // coerces header names to lowercase }; @@ -792,7 +788,7 @@ Request.prototype.request = function() { // set tcp no delay req.setNoDelay(true); - if (options.method !== 'HEAD' && !('accept-encoding' in this._unset)) { + if (options.method !== 'HEAD') { req.setHeader('Accept-Encoding', 'gzip, deflate'); } diff --git a/src/request-base.js b/src/request-base.js index ff519477a..b88e27cb5 100644 --- a/src/request-base.js +++ b/src/request-base.js @@ -364,7 +364,6 @@ RequestBase.prototype.set = function(field, val) { this._header[field.toLowerCase()] = val; this.header[field] = val; - delete this._unset[field.toLowerCase()]; return this; }; @@ -375,7 +374,7 @@ RequestBase.prototype.set = function(field, val) { * Example: * * req.get('/') - * .unset('Accept-Encoding') + * .unset('User-Agent') * .end(callback); * * @param {String} field field name @@ -383,7 +382,6 @@ RequestBase.prototype.set = function(field, val) { RequestBase.prototype.unset = function(field) { delete this._header[field.toLowerCase()]; delete this.header[field]; - this._unset[field.toLowerCase()] = true; return this; }; @@ -623,7 +621,7 @@ RequestBase.prototype.send = function(data) { } } else if (typeof data === 'string') { // default to x-www-form-urlencoded - if (!type && !('content-type' in this._unset)) this.type('form'); + if (!type) this.type('form'); type = this._header['content-type']; if (type === 'application/x-www-form-urlencoded') { this._data = this._data ? `${this._data}&${data}` : data; @@ -639,7 +637,7 @@ RequestBase.prototype.send = function(data) { } // default to json - if (!type && !('content-type' in this._unset)) this.type('json'); + if (!type) this.type('json'); return this; }; diff --git a/test/node/basic.js b/test/node/basic.js index 54bbcaf10..16448f120 100644 --- a/test/node/basic.js +++ b/test/node/basic.js @@ -67,43 +67,12 @@ describe('[node] request', () => { }); describe('req.unset(field)', () => { - it('should remove a header added using set', done => { + it('should remove the header field', done => { request .post(`${base}/echo`) - .set('X-Header', 'value') - .unset('X-Header') + .unset('User-Agent') .end((err, res) => { - assert.equal(void 0, res.header['x-header']); - done(); - }); - }); - it('should not prevent set from being used after to set the header again', done => { - request - .post(`${base}/echo`) - .set('X-Header', 'value 1') - .unset('X-Header') - .set('X-Header', 'value') - .end((err, res) => { - assert.equal('value', res.header['x-header']); - done(); - }); - }); - it('should prevent the Accept-Encoding header from being added automatically', done => { - request - .post(`${base}/echo`) - .unset('Accept-Encoding') - .end((err, res) => { - assert.equal(void 0, res.header['accept-encoding']); - done(); - }); - }); - it('should prevent the Content-Type field from being added automatically', done => { - request - .post(`${base}/echo`) - .send('hello=world') - .unset('Content-Type') - .end((err, res) => { - assert.equal(void 0, res.header['content-type']); + assert.equal(void 0, res.header['user-agent']); done(); }); });