forked from cujojs/rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxhr.js
68 lines (55 loc) · 1.39 KB
/
xhr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright 2013 the original author or authors
* @license MIT, see LICENSE.txt for details
*
* @author Scott Andrews
*/
(function (define, global) {
'use strict';
define(function (require) {
var interceptor, XMLHttpRequest;
interceptor = require('../../interceptor');
XMLHttpRequest = (function () {
// derived from https://github.com/cujojs/poly/blob/0.5.1/xhr.js
if (global.XMLHttpRequest) {
return global.XMLHttpRequest;
}
var progIds, xhr;
progIds = [
'Msxml2.XMLHTTP',
'Microsoft.XMLHTTP',
'Msxml2.XMLHTTP.4.0'
];
function tryCtor(progId) {
try {
/*jshint nonew:false */
new global.ActiveXObject(progId);
xhr = function () { return new global.ActiveXObject(progId); };
}
catch (ex) {}
}
while (!xhr && progIds.length) {
tryCtor(progIds.shift());
}
return xhr;
}());
/**
* Defaults request.engine to XMLHttpRequest, or an appropriate ActiveX fall
* back
*
* @param {Client} [client] client to wrap
*
* @returns {Client}
*/
return interceptor({
request: function handleRequest(request) {
request.engine = request.engine || XMLHttpRequest;
return request;
}
});
});
}(
typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); },
typeof window !== 'undefined' ? window : void 0
// Boilerplate for AMD and Node
));