Skip to content

Commit

Permalink
Use res.getHeaders() to avoid deprecation warning (#1503)
Browse files Browse the repository at this point in the history
* Use `res.getHeaders()` to avoid depr-warning

* Reflect @thw0rted comments

* Throw on deprecation in tests
  • Loading branch information
ad-m authored and niftylettuce committed Dec 1, 2019
1 parent 158d759 commit 8dc8b91
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test-node:
@NODE_ENV=test ./node_modules/.bin/mocha \
--require should \
--trace-warnings \
--throw-deprecation \
--reporter $(REPORTER) \
--timeout 5000 \
$(NODETESTS)
Expand All @@ -18,6 +19,7 @@ test-node-http2:
@NODE_ENV=test HTTP2_TEST=1 node ./node_modules/.bin/mocha \
--require should \
--trace-warnings \
--throw-deprecation \
--reporter $(REPORTER) \
--timeout 5000 \
$(NODETESTS)
Expand Down
6 changes: 3 additions & 3 deletions src/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,15 +492,15 @@ Request.prototype._redirect = function(res) {
// this is required for Node v0.10+
res.resume();

let headers = this.req._headers;
let headers = this.req.getHeaders ? this.req.getHeaders() : this.req._headers;

const changesOrigin = parse(url).host !== parse(this.url).host;

// implementation of 302 following defacto standard
if (res.statusCode === 301 || res.statusCode === 302) {
// strip Content-* related fields
// in case of POST etc
headers = utils.cleanHeader(this.req._headers, changesOrigin);
headers = utils.cleanHeader(headers, changesOrigin);

// force GET
this.method = this.method === 'HEAD' ? 'HEAD' : 'GET';
Expand All @@ -513,7 +513,7 @@ Request.prototype._redirect = function(res) {
if (res.statusCode === 303) {
// strip Content-* related fields
// in case of POST etc
headers = utils.cleanHeader(this.req._headers, changesOrigin);
headers = utils.cleanHeader(headers, changesOrigin);

// force method
this.method = 'GET';
Expand Down

0 comments on commit 8dc8b91

Please sign in to comment.