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

Fix baseUrl and redirections. #1481

Merged
merged 1 commit into from Mar 16, 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
1 change: 1 addition & 0 deletions request.js
Expand Up @@ -386,6 +386,7 @@ Request.prototype.init = function (options) {
} else {
self.uri = self.baseUrl + '/' + self.uri
}
delete self.baseUrl
}

// A URI is needed by this point, throw if we haven't been able to get one
Expand Down
21 changes: 19 additions & 2 deletions tests/test-baseUrl.js
Expand Up @@ -6,8 +6,14 @@ var http = require('http')
, url = require('url')

var s = http.createServer(function(req, res) {
res.statusCode = 200
res.setHeader('X-PATH', req.url)
if(req.url === '/redirect/') {
res.writeHead(302, {
location : '/'
})
} else {
res.statusCode = 200
res.setHeader('X-PATH', req.url)
}
res.end('ok')
})

Expand Down Expand Up @@ -38,6 +44,17 @@ tape('baseUrl defaults', function(t) {
})
})

tape('baseUrl and redirects', function(t) {
request('/', {
baseUrl: 'http://localhost:6767/redirect'
}, function(err, resp, body) {
t.equal(err, null)
t.equal(body, 'ok')
t.equal(resp.headers['x-path'], '/')
t.end()
})
})

function addTest(baseUrl, uri, expected) {
tape('test baseurl="' + baseUrl + '" uri="' + uri + '"', function(t) {
request(uri, { baseUrl: baseUrl }, function(err, resp, body) {
Expand Down