diff --git a/index.js b/index.js index dd75d4c..06cd9cc 100644 --- a/index.js +++ b/index.js @@ -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; }; diff --git a/test/request_url.js b/test/request_url.js index e622419..c46930d 100644 --- a/test/request_url.js +++ b/test/request_url.js @@ -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; @@ -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(); +});