Skip to content

Commit 84b1d1f

Browse files
committedJun 19, 2014
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 84b1d1f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
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-
return new window.XMLHttpRequest();
11+
return new window.XMLHttpRequest(config);
1212
}
1313

1414
throw minErr('$httpBackend')('noxhr', "This browser does not support XMLHttpRequest.");
@@ -40,7 +40,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
4040
var ABORTED = -1;
4141

4242
// TODO(vojta): fix the signature
43-
return function(method, url, post, callback, headers, timeout, withCredentials, responseType) {
43+
return function(method, url, post, callback, headers, timeout, withCredentials, responseType, xhrConfig) {
4444
var status;
4545
$browser.$$incOutstandingRequestCount();
4646
url = url || $browser.url();
@@ -59,7 +59,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
5959
});
6060
} else {
6161

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

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

0 commit comments

Comments
 (0)