Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 25 additions & 0 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '');
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions 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 All @@ -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 : '/');
};

/**
Expand Down