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
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ http.request = function (params, cb) {
}
if (!params) params = {};
if (!params.host && !params.port) {
params.port = parseInt(window.location.port, 10);
params.port = parseInt(global.location.port, 10);
}
if (!params.host && params.hostname) {
params.host = params.hostname;
}

if (!params.scheme) params.scheme = window.location.protocol.split(':')[0];
if (!params.scheme) params.scheme = global.location.protocol.split(':')[0];
if (!params.host) {
params.host = window.location.hostname || window.location.host;
params.host = global.location.hostname || global.location.host;
}
if (/:/.test(params.host)) {
if (!params.port) {
Expand All @@ -43,29 +43,29 @@ http.Agent = function () {};
http.Agent.defaultMaxSockets = 4;

var xhrHttp = (function () {
if (typeof window === 'undefined') {
throw new Error('no window object present');
if (typeof global === 'undefined') {
throw new Error('no global object present');
}
else if (window.XMLHttpRequest) {
return window.XMLHttpRequest;
else if (global.XMLHttpRequest) {
return global.XMLHttpRequest;
}
else if (window.ActiveXObject) {
else if (global.ActiveXObject) {
var axs = [
'Msxml2.XMLHTTP.6.0',
'Msxml2.XMLHTTP.3.0',
'Microsoft.XMLHTTP'
];
for (var i = 0; i < axs.length; i++) {
try {
var ax = new(window.ActiveXObject)(axs[i]);
var ax = new(global.ActiveXObject)(axs[i]);
return function () {
if (ax) {
var ax_ = ax;
ax = null;
return ax_;
}
else {
return new(window.ActiveXObject)(axs[i]);
return new(global.ActiveXObject)(axs[i]);
}
};
}
Expand Down
12 changes: 5 additions & 7 deletions test/request_url.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
global.window = {
location: {
host: 'localhost:8081',
port: 8081,
protocol: 'http:'
}
global.location = {
host: 'localhost:8081',
port: 8081,
protocol: 'http:'
};

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