Skip to content

Commit

Permalink
Merge pull request #1481 from burningtree/master
Browse files Browse the repository at this point in the history
Fix baseUrl and redirections.
  • Loading branch information
simov committed Mar 16, 2015
2 parents 9f844e2 + cb0173c commit 41984f9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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

0 comments on commit 41984f9

Please sign in to comment.