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
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ http.request = function (params, cb) {
params.host = params.host.split(':')[0];
}
if (!params.port) params.port = params.scheme == 'https' ? 443 : 80;

var req = new Request(new xhrHttp, params);

var xhrParams = params.xhrParams || {};

var req = new Request(new xhrHttp(xhrParams), params);
if (cb) req.on('response', cb);
return req;
};
Expand Down
22 changes: 21 additions & 1 deletion test/request_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ global.window = {
};

var noop = function() {};
global.window.XMLHttpRequest = function() {
global.window.XMLHttpRequest = function(xhrParams) {
this.open = noop;
this.send = noop;

if(!xhrParams) return;

Object.keys(xhrParams).forEach(function(key) {
this[key] = xhrParams[key];
}.bind(this));
};

var test = require('tape').test;
Expand Down Expand Up @@ -72,3 +78,17 @@ test('Test withCredentials param', function(t) {

t.end();
});

test('Test additional xhr params', function(t) {
var request = http.request({
url: '/api/foo',
xhrParams: {
mozSystem: true,
mozAnon: true
}
});

t.equal( request.xhr.mozSystem, true, 'xhr.mozSystem should be true');
t.equal( request.xhr.mozAnon, true, 'mozAnon should be true');
t.end();
});