Skip to content

Commit f30218f

Browse files
committed
feat($http): add option for unsafe xhr requests in FirefoxOS
Previously, it was not possible to pass settings to the constructor of the XMLHttpRequest. This adds an optional config property `xhrConfig` to the $http constructor, allowing us to do so. This is required for use of the mozAnon and mozSystem options for FirefoxOS. See https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#XMLHttpRequest() for details. Closes angular#2318
1 parent 307e72e commit f30218f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/ng/http.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@ function $HttpProvider() {
485485
* for more information.
486486
* - **responseType** - `{string}` - see
487487
* [requestType](https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType).
488+
* - **xhrConfig** - `{Object}` - config pass to XMLHttpRequest. See
489+
* [XMLHttpRequest()](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#XMLHttpRequest())
488490
*
489491
* @returns {HttpPromise} Returns a {@link ng.$q promise} object with the
490492
* standard `then` method and two http specific methods: `success` and `error`. The `then`
@@ -889,7 +891,7 @@ function $HttpProvider() {
889891
}
890892

891893
$httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout,
892-
config.withCredentials, config.responseType);
894+
config.withCredentials, config.responseType, config.xhrConfig);
893895
}
894896

895897
return promise;

src/ng/httpBackend.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
'use strict';
22

3-
function createXhr(method) {
3+
function createXhr(method, config) {
44
//if IE and the method is not RFC2616 compliant, or if XMLHttpRequest
55
//is not available, try getting an ActiveXObject. Otherwise, use XMLHttpRequest
66
//if it is available
77
if (msie <= 8 && (!method.match(/^(get|post|head|put|delete|options)$/i) ||
88
!window.XMLHttpRequest)) {
99
return new window.ActiveXObject("Microsoft.XMLHTTP");
1010
} else if (window.XMLHttpRequest) {
11+
if (isObject(config)) {
12+
return new window.XMLHttpRequest(config);
13+
}
1114
return new window.XMLHttpRequest();
1215
}
1316

@@ -40,7 +43,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
4043
var ABORTED = -1;
4144

4245
// TODO(vojta): fix the signature
43-
return function(method, url, post, callback, headers, timeout, withCredentials, responseType) {
46+
return function(method, url, post, callback, headers, timeout, withCredentials, responseType, xhrConfig) {
4447
var status;
4548
$browser.$$incOutstandingRequestCount();
4649
url = url || $browser.url();
@@ -59,7 +62,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
5962
});
6063
} else {
6164

62-
var xhr = createXhr(method);
65+
var xhr = createXhr(method, xhrConfig);
6366

6467
xhr.open(method, url, true);
6568
forEach(headers, function(value, key) {

0 commit comments

Comments
 (0)