Browse Source

use `is-redirect` module

http2
Sindre Sorhus 10 years ago
parent
commit
550c63fcbe
  1. 3
      index.js
  2. 1
      package.json

3
index.js

@ -14,6 +14,7 @@ var timedOut = require('timed-out');
var prependHttp = require('prepend-http');
var lowercaseKeys = require('lowercase-keys');
var statuses = require('statuses');
var isRedirect = require('is-redirect');
var NestedErrorStacks = require('nested-error-stacks');
function GotError(message, nested) {
@ -117,7 +118,7 @@ function got(url, opts, cb) {
proxy.emit('response', res);
}
// auto-redirect only for GET and HEAD methods
if (statuses.redirect[statusCode] && 'location' in res.headers && (opts.method === 'GET' || opts.method === 'HEAD')) {
if (isRedirect(statusCode) && 'location' in res.headers && (opts.method === 'GET' || opts.method === 'HEAD')) {
res.resume(); // discard response
if (++redirectCount > 10) {

1
package.json

@ -44,6 +44,7 @@
"dependencies": {
"duplexify": "^3.2.0",
"infinity-agent": "^2.0.0",
"is-redirect": "^1.0.0",
"is-stream": "^1.0.0",
"lowercase-keys": "^1.0.0",
"nested-error-stacks": "^1.0.0",

Loading…
Cancel
Save