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 cookie parsing problem and location redirection with '//' at the beginning of location header #87

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ Browser.prototype.request = function(method, path, options, fn, saveHistory){

// Redirect
if (status >= 300 && status < 400) {
if (0 == res.headers.location.indexOf('//')) {
var isHttps = req.connection.server instanceof require('tls').Server || (req.headers && req.headers['x-forwarded-proto'] == 'https')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is mega-long, this should be fine this.connection.encrypted || forwardedstuffhere, break it into two vars so it's not so crazy.
var fwd = req.headers && req.... this.connection.encrypted || fwd == 'https'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for mention that, I committed a fix here.

res.headers.location = (isHttps ? 'https:' : 'http:') + res.headers.location
}
var location = res.headers.location
, uri = url.parse(location)
, path = uri.pathname + (uri.search || '');
Expand Down
2 changes: 1 addition & 1 deletion lib/cookie/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var Cookie = exports = module.exports = function Cookie(str, req) {
// Map the key/val pairs
str.split(/ *; */).reduce(function(obj, pair){
pair = pair.split(/ *= */);
obj[pair[0]] = pair[1] || true;
obj[pair[0].toLowerCase()] = pair[1] || true;
return obj;
}, this);

Expand Down