diff --git a/lib/browser.js b/lib/browser.js index 15c3a34..4107888 100644 --- a/lib/browser.js +++ b/lib/browser.js @@ -232,6 +232,11 @@ Browser.prototype.request = function(method, path, options, fn, saveHistory){ // Redirect if (status >= 300 && status < 400) { + if (0 == res.headers.location.indexOf('//')) { + var fwd = this.headers && this.headers['x-forwarded-proto'] == 'https'; + var isHttps = this.connection.encrypted || fwd; + res.headers.location = (isHttps ? 'https:' : 'http:') + res.headers.location + } var location = res.headers.location , uri = url.parse(location) , path = uri.pathname + (uri.search || ''); @@ -313,6 +318,10 @@ Browser.prototype.request = function(method, path, options, fn, saveHistory){ Browser.prototype.get = Browser.prototype.visit = Browser.prototype.open = function(path, options, fn, saveHistory){ + // relative path + if (0 == path.indexOf('?')) { + path = url.parse(this.history[this.history.length - 1]).pathname + path; + } if ('function' == typeof options) { saveHistory = fn; fn = options; @@ -332,6 +341,10 @@ Browser.prototype.open = function(path, options, fn, saveHistory){ */ Browser.prototype.head = function(path, options, fn, saveHistory){ + // relative path + if (0 == path.indexOf('?')) { + path = url.parse(this.history[this.history.length - 1]).pathname + path; + } if ('function' == typeof options) { saveHistory = fn; fn = options; @@ -351,6 +364,10 @@ Browser.prototype.head = function(path, options, fn, saveHistory){ */ Browser.prototype.post = function(path, options, fn, saveHistory){ + // relative path + if (0 == path.indexOf('?')) { + path = url.parse(this.history[this.history.length - 1]).pathname + path; + } if ('function' == typeof options) { saveHistory = fn; fn = options; @@ -370,6 +387,10 @@ Browser.prototype.post = function(path, options, fn, saveHistory){ */ Browser.prototype.put = function(path, options, fn, saveHistory){ + // relative path + if (0 == path.indexOf('?')) { + path = url.parse(this.history[this.history.length - 1]).pathname + path; + } if ('function' == typeof options) { saveHistory = fn; fn = options; @@ -389,6 +410,10 @@ Browser.prototype.put = function(path, options, fn, saveHistory){ */ Browser.prototype.delete = function(path, options, fn, saveHistory){ + // relative path + if (0 == path.indexOf('?')) { + path = url.parse(this.history[this.history.length - 1]).pathname + path; + } if ('function' == typeof options) { saveHistory = fn; fn = options; diff --git a/lib/cookie/index.js b/lib/cookie/index.js index 2fe9907..17a3ef0 100644 --- a/lib/cookie/index.js +++ b/lib/cookie/index.js @@ -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); @@ -43,7 +43,7 @@ var Cookie = exports = module.exports = function Cookie(str, req) { // Default or trim path this.path = this.path ? this.path.trim() - : url.parse(req.url).pathname; + : (req ? url.parse(req.url).pathname : '/'); }; /**