Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few minor fixes: #1591

Merged
merged 1 commit into from May 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -761,6 +761,7 @@ The first argument can be either a `url` or an `options` object. The only requir
- `followRedirect` - follow HTTP 3xx responses as redirects (default: `true`). This property can also be implemented as function which gets `response` object as a single argument and should return `true` if redirects should continue or `false` otherwise.
- `followAllRedirects` - follow non-GET HTTP 3xx responses as redirects (default: `false`)
- `maxRedirects` - the maximum number of redirects to follow (default: `10`)
- `removeRefererHeader` - removes the referer header when a redirect happens (default: `false`).

---

Expand Down Expand Up @@ -797,7 +798,6 @@ The first argument can be either a `url` or an `options` object. The only requir
tunneling proxy.
- `proxyHeaderExclusiveList` - A whitelist of headers to send
exclusively to a tunneling proxy and not to destination.
- `removeRefererHeader` - removes the referer header when a redirect happens (default: `false`).

---

Expand Down
2 changes: 1 addition & 1 deletion lib/auth.js
Expand Up @@ -136,7 +136,7 @@ Auth.prototype.onResponse = function (response) {

var authHeader = c.get('www-authenticate')
var authVerb = authHeader && authHeader.split(' ')[0].toLowerCase()
// debug('reauth', authVerb)
request.debug('reauth', authVerb)

switch (authVerb) {
case 'basic':
Expand Down
28 changes: 13 additions & 15 deletions lib/redirect.js
Expand Up @@ -15,27 +15,26 @@ function Redirect (request) {
this.removeRefererHeader = false
}

Redirect.prototype.onRequest = function () {
Redirect.prototype.onRequest = function (options) {
var self = this
, request = self.request

if (request.maxRedirects !== undefined) {
self.maxRedirects = request.maxRedirects
if (options.maxRedirects !== undefined) {
self.maxRedirects = options.maxRedirects
}
if (typeof request.followRedirect === 'function') {
self.allowRedirect = request.followRedirect
if (typeof options.followRedirect === 'function') {
self.allowRedirect = options.followRedirect
}
if (request.followRedirect !== undefined) {
self.followRedirects = !!request.followRedirect
if (options.followRedirect !== undefined) {
self.followRedirects = !!options.followRedirect
}
if (request.followAllRedirects !== undefined) {
self.followAllRedirects = request.followAllRedirects
if (options.followAllRedirects !== undefined) {
self.followAllRedirects = options.followAllRedirects
}
if (self.followRedirects || self.followAllRedirects) {
self.redirects = self.redirects || []
}
if (request.removeRefererHeader !== undefined) {
self.removeRefererHeader = request.removeRefererHeader
if (options.removeRefererHeader !== undefined) {
self.removeRefererHeader = options.removeRefererHeader
}
}

Expand All @@ -46,7 +45,7 @@ Redirect.prototype.redirectTo = function (response) {
var redirectTo = null
if (response.statusCode >= 300 && response.statusCode < 400 && response.caseless.has('location')) {
var location = response.caseless.get('location')
// debug('redirect', location)
request.debug('redirect', location)

if (self.followAllRedirects) {
redirectTo = location
Expand Down Expand Up @@ -82,8 +81,7 @@ Redirect.prototype.onResponse = function (response) {
return false
}


// debug('redirect to', redirectTo)
request.debug('redirect to', redirectTo)

// ignore any potential response body. it cannot possibly be useful
// to us at this point.
Expand Down
3 changes: 2 additions & 1 deletion request.js
Expand Up @@ -281,6 +281,7 @@ function debug() {
console.error('REQUEST %s', util.format.apply(util, arguments))
}
}
Request.prototype.debug = debug

Request.prototype.setupTunnel = function () {
var self = this
Expand Down Expand Up @@ -469,7 +470,7 @@ Request.prototype.init = function (options) {
return self.emit('error', new Error(message))
}

self._redirect.onRequest()
self._redirect.onRequest(options)

self.setHost = false
if (!self.hasHeader('host')) {
Expand Down