Skip to content

Commit b411b66

Browse files
committed
Revert "fix: allow unset to prevent some defaults (#1560)"
This reverts commit afd20c1.
1 parent 993b764 commit b411b66

File tree

3 files changed

+7
-44
lines changed

3 files changed

+7
-44
lines changed

src/node/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ exports.buffer = {};
131131
* @api private
132132
*/
133133
function _initHeaders(req) {
134-
req._unset = {
135-
// lowercase headers that were unset; this is used to suppress some default
136-
// headers, such as Accept-Encoding and Content-Type
137-
};
138134
req._header = {
139135
// coerces header names to lowercase
140136
};
@@ -792,7 +788,7 @@ Request.prototype.request = function() {
792788
// set tcp no delay
793789
req.setNoDelay(true);
794790

795-
if (options.method !== 'HEAD' && !('accept-encoding' in this._unset)) {
791+
if (options.method !== 'HEAD') {
796792
req.setHeader('Accept-Encoding', 'gzip, deflate');
797793
}
798794

src/request-base.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ RequestBase.prototype.set = function(field, val) {
364364

365365
this._header[field.toLowerCase()] = val;
366366
this.header[field] = val;
367-
delete this._unset[field.toLowerCase()];
368367
return this;
369368
};
370369

@@ -375,15 +374,14 @@ RequestBase.prototype.set = function(field, val) {
375374
* Example:
376375
*
377376
* req.get('/')
378-
* .unset('Accept-Encoding')
377+
* .unset('User-Agent')
379378
* .end(callback);
380379
*
381380
* @param {String} field field name
382381
*/
383382
RequestBase.prototype.unset = function(field) {
384383
delete this._header[field.toLowerCase()];
385384
delete this.header[field];
386-
this._unset[field.toLowerCase()] = true;
387385
return this;
388386
};
389387

@@ -623,7 +621,7 @@ RequestBase.prototype.send = function(data) {
623621
}
624622
} else if (typeof data === 'string') {
625623
// default to x-www-form-urlencoded
626-
if (!type && !('content-type' in this._unset)) this.type('form');
624+
if (!type) this.type('form');
627625
type = this._header['content-type'];
628626
if (type === 'application/x-www-form-urlencoded') {
629627
this._data = this._data ? `${this._data}&${data}` : data;
@@ -639,7 +637,7 @@ RequestBase.prototype.send = function(data) {
639637
}
640638

641639
// default to json
642-
if (!type && !('content-type' in this._unset)) this.type('json');
640+
if (!type) this.type('json');
643641
return this;
644642
};
645643

test/node/basic.js

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -67,43 +67,12 @@ describe('[node] request', () => {
6767
});
6868

6969
describe('req.unset(field)', () => {
70-
it('should remove a header added using set', done => {
70+
it('should remove the header field', done => {
7171
request
7272
.post(`${base}/echo`)
73-
.set('X-Header', 'value')
74-
.unset('X-Header')
73+
.unset('User-Agent')
7574
.end((err, res) => {
76-
assert.equal(void 0, res.header['x-header']);
77-
done();
78-
});
79-
});
80-
it('should not prevent set from being used after to set the header again', done => {
81-
request
82-
.post(`${base}/echo`)
83-
.set('X-Header', 'value 1')
84-
.unset('X-Header')
85-
.set('X-Header', 'value')
86-
.end((err, res) => {
87-
assert.equal('value', res.header['x-header']);
88-
done();
89-
});
90-
});
91-
it('should prevent the Accept-Encoding header from being added automatically', done => {
92-
request
93-
.post(`${base}/echo`)
94-
.unset('Accept-Encoding')
95-
.end((err, res) => {
96-
assert.equal(void 0, res.header['accept-encoding']);
97-
done();
98-
});
99-
});
100-
it('should prevent the Content-Type field from being added automatically', done => {
101-
request
102-
.post(`${base}/echo`)
103-
.send('hello=world')
104-
.unset('Content-Type')
105-
.end((err, res) => {
106-
assert.equal(void 0, res.header['content-type']);
75+
assert.equal(void 0, res.header['user-agent']);
10776
done();
10877
});
10978
});

0 commit comments

Comments
 (0)