From e0a54f6b206dc2b6595f2bc3a17c5932e7477545 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Sat, 4 Aug 2012 12:11:00 -0700 Subject: feat($http): support reponseType Closes #1013 --- src/ng/http.js | 4 +++- src/ng/httpBackend.js | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ng/http.js b/src/ng/http.js index deeb6cbb..ef55f878 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -381,6 +381,8 @@ function $HttpProvider() { * - **withCredentials** - `{boolean}` - whether to to set the `withCredentials` flag on the * XHR object. See {@link https://developer.mozilla.org/en/http_access_control#section_5 * requests with credentials} for more information. + * - **responseType** - `{string}` - see {@link + * https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType requestType}. * * @returns {HttpPromise} Returns a {@link ng.$q promise} object with the * standard `then` method and two http specific methods: `success` and `error`. The `then` @@ -697,7 +699,7 @@ function $HttpProvider() { // if we won't have the response in cache, send the request to the backend if (!cachedResp) { $httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout, - config.withCredentials); + config.withCredentials, config.responseType); } return promise; diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index 0a12aa23..bca46ee1 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -32,7 +32,7 @@ function $HttpBackendProvider() { function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument, locationProtocol) { // TODO(vojta): fix the signature - return function(method, url, post, callback, headers, timeout, withCredentials) { + return function(method, url, post, callback, headers, timeout, withCredentials, responseType) { $browser.$$incOutstandingRequestCount(); url = url || $browser.url(); @@ -65,8 +65,8 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument, // always async xhr.onreadystatechange = function() { if (xhr.readyState == 4) { - completeRequest( - callback, status || xhr.status, xhr.responseText, xhr.getAllResponseHeaders()); + completeRequest(callback, status || xhr.status, xhr.response || xhr.responseText, + xhr.getAllResponseHeaders()); } }; @@ -74,6 +74,10 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument, xhr.withCredentials = true; } + if (responseType) { + xhr.responseType = responseType; + } + xhr.send(post || ''); if (timeout > 0) { -- cgit v1.2.3