Comparing version 1.13.0 to 1.14.0
19
index.js
@@ -11,4 +11,3 @@ var window = require("global/window") | ||
var XHR = window.XMLHttpRequest || noop | ||
var XDR = "withCredentials" in (new XHR()) ? | ||
window.XMLHttpRequest : window.XDomainRequest | ||
var XDR = "withCredentials" in (new XHR()) ? XHR : window.XDomainRequest | ||
@@ -27,6 +26,8 @@ module.exports = createXHR | ||
if (!xhr && options.cors) { | ||
xhr = new XDR() | ||
} else if (!xhr) { | ||
xhr = new XHR() | ||
if (!xhr) { | ||
if (options.cors || options.useXDR) { | ||
xhr = new XDR() | ||
}else{ | ||
xhr = new XHR() | ||
} | ||
} | ||
@@ -61,4 +62,4 @@ | ||
xhr.open(method, uri, !sync) | ||
if (options.cors && options.withCredentials !== false) { | ||
//backward compatibility | ||
if (options.withCredentials || (options.cors && options.withCredentials !== false)) { | ||
xhr.withCredentials = true | ||
@@ -78,2 +79,4 @@ } | ||
} | ||
} else { | ||
options.headers || throw new Error("Headers cannot be set on an XDomainRequest object"); | ||
} | ||
@@ -80,0 +83,0 @@ |
{ | ||
"name": "xhr", | ||
"version": "1.13.0", | ||
"version": "1.14.0", | ||
"description": "small xhr abstraction", | ||
@@ -30,3 +30,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"run-browser": "git://github.com/Raynos/run-browser", | ||
"run-browser": "^1.3.1", | ||
"tap-spec": "^0.1.8", | ||
@@ -33,0 +33,0 @@ "tape": "^2.12.2" |
@@ -28,3 +28,3 @@ # xhr | ||
type XhrOptions = String | { | ||
cors: Boolean?, | ||
useXDR: Boolean?, | ||
sync: Boolean?, | ||
@@ -45,3 +45,3 @@ uri: String, | ||
or an [`XDomainRequest`][4] instance (if on IE8/IE9 && | ||
`options.cors` is set to `true`) | ||
`options.useXDR` is set to `true`) | ||
@@ -66,6 +66,9 @@ Your callback will be called once with the arguments | ||
### `options.cors` | ||
### `options.useXDR` | ||
Specify whether this is a cross domain request. Used in IE<10 | ||
to use `XDomainRequest` instead of `XMLHttpRequest`. | ||
Specify whether this is a cross origin (CORS) request for IE<10. | ||
Switches IE to use [`XDomainRequest`][4] instead of `XMLHttpRequest`. | ||
Ignored in other browsers. | ||
Note that headers cannot be set on an XDomainRequest instance. | ||
@@ -110,5 +113,10 @@ ### `options.sync` | ||
Specify whether user credentials are to be included in a cross-origin | ||
request. Sets [`xhr.withCredentials`][10]. Defaults to true | ||
when `options.cors` is true. | ||
request. Sets [`xhr.withCredentials`][10]. Defaults to false. | ||
For backward-compatibility defaults to true | ||
when deprecated `options.cors` is also true. | ||
A wildcard `*` cannot be used in the `Access-Control-Allow-Origin` header when `withCredentials` is true. | ||
The header needs to specify your origin explicitly or browser will abort the request. | ||
@@ -115,0 +123,0 @@ ## MIT Licenced |
@@ -46,1 +46,25 @@ var window = require("global/window") | ||
}) | ||
test("XDR usage (run on IE8 or 9)", function(assert) { | ||
var req = xhr({ | ||
useXDR: true, | ||
uri: window.location.href, | ||
}, function () {}) | ||
assert.ok( | ||
!window.XDomainRequest || window.XDomainRequest === req.constructor, | ||
"Uses XDR when told to" | ||
) | ||
req = xhr({ | ||
cors: true, | ||
uri: window.location.href, | ||
}, function () {}) | ||
assert.ok( | ||
!window.XDomainRequest || window.XDomainRequest === req.constructor, | ||
"Uses XDR with deprecated option cors" | ||
) | ||
assert.end() | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12948
7
173
131