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

Fix baseUrl and redirections. #1481

merged 1 commit into from Mar 16, 2015

Conversation

burningtree
Copy link
Contributor

I found a bug in new baseUrl feature, when used in combination with redirection.

This script produce absurdly error [Error: options.uri must be a string when using options.baseUrl]:

var request = require('./node_modules/request');
var http = require('http');

var s = http.createServer(function(req, res) {
  if(req.url === '/redirect/') {
    res.writeHead(302, {
      location : '/'
    })
  } else  {
    res.statusCode = 200
  }
  res.end()
}).listen(6767);

request({
  url: '/',
  baseUrl: 'http://localhost:6767/redirect'

}, function (err, resp, body) {
  console.log(err);
  s.close();
});

This is due to the fact that first call changes URI to an object, and therefore in the second iteration (to redirected page) can be seen as a string. The solution is delete baseUrl immediately after use, because certainly no longer needed.

This pull request fixes this bug. Test included.

@burningtree burningtree mentioned this pull request Mar 14, 2015
@simov
Copy link
Member

simov commented Mar 14, 2015

Good catch @burningtree 👍

@requestbot requestbot mentioned this pull request Mar 16, 2015
simov added a commit that referenced this pull request Mar 16, 2015
Fix baseUrl and redirections.
@simov simov merged commit 41984f9 into request:master Mar 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants