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

Fixes GH-119 #193

Merged
merged 2 commits into from Feb 27, 2012
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 main.js
Expand Up @@ -362,7 +362,7 @@ Request.prototype.start = function () {


if (response.statusCode >= 300 && response.statusCode < 400 && if (response.statusCode >= 300 && response.statusCode < 400 &&
(self.followAllRedirects || (self.followAllRedirects ||
(self.followRedirect && (self.method !== 'PUT' && self.method !== 'POST'))) && (self.followRedirect && (self.method !== 'PUT' && self.method !== 'POST' && self.method !== 'DELETE'))) &&
response.headers.location) { response.headers.location) {
if (self._redirectsFollowed >= self.maxRedirects) { if (self._redirectsFollowed >= self.maxRedirects) {
self.emit('error', new Error("Exceeded maxRedirects. Probably stuck in a redirect loop.")) self.emit('error', new Error("Exceeded maxRedirects. Probably stuck in a redirect loop."))
Expand Down
38 changes: 37 additions & 1 deletion tests/test-redirect.js
Expand Up @@ -112,10 +112,46 @@ s.listen(s.port, function () {
} }
}) })


// Should not follow delete redirects by default
request.del(server+'/temp', { jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
try {
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(!hits.temp_landing, 'No chasing the redirect when delete')
assert.equal(res.statusCode, 301, 'Response is the bounce itself')
passed += 1
} finally {
done()
}
})

// Should not follow delete redirects even if followRedirect is set to true
request.del(server+'/temp', { followRedirect: true, jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
try {
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(!hits.temp_landing, 'No chasing the redirect when delete')
assert.equal(res.statusCode, 301, 'Response is the bounce itself')
passed += 1
} finally {
done()
}
})

// Should follow delete redirects when followAllRedirects true
request.del(server+'/temp', {followAllRedirects:true, jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
try {
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(hits.temp_landing, 'Forward to temporary landing URL')
assert.equal(body, 'temp_landing', 'Got temporary landing content')
passed += 1
} finally {
done()
}
})

var reqs_done = 0; var reqs_done = 0;
function done() { function done() {
reqs_done += 1; reqs_done += 1;
if(reqs_done == 6) { if(reqs_done == 9) {
console.log(passed + ' tests passed.') console.log(passed + ' tests passed.')
s.close() s.close()
} }
Expand Down