diff options
| author | Vojta Jina | 2011-11-03 17:14:03 -0700 | 
|---|---|---|
| committer | Igor Minar | 2011-11-30 11:17:24 -0500 | 
| commit | caeb1bf899bfcc10b5860ad1b6632a3fe7b0b85f (patch) | |
| tree | 3c3a34be238f3cbcd68905b6558b309747e57749 /src | |
| parent | 9b4efa73f9eef7c22895ca269760eb11ecb54b30 (diff) | |
| download | angular.js-caeb1bf899bfcc10b5860ad1b6632a3fe7b0b85f.tar.bz2 | |
feat($httpBackend): fix 0 status code when "file" protocol
Browsers return always 0 status code for "file" protocol, so we convert them into 200/404.
Diffstat (limited to 'src')
| -rw-r--r-- | src/service/httpBackend.js | 25 | 
1 files changed, 17 insertions, 8 deletions
| diff --git a/src/service/httpBackend.js b/src/service/httpBackend.js index 28700940..7443347f 100644 --- a/src/service/httpBackend.js +++ b/src/service/httpBackend.js @@ -17,19 +17,14 @@ var XHR = window.XMLHttpRequest || function() {   */  function $HttpBackendProvider() {    this.$get = ['$browser', '$window', '$document', function($browser, $window, $document) { -    return createHttpBackend($browser, XHR, $browser.defer, $window, $document[0].body); +    return createHttpBackend($browser, XHR, $browser.defer, $window, $document[0].body, +        $window.location.href.replace(':', ''));    }];  } -function createHttpBackend($browser, XHR, $browserDefer, $window, body) { +function createHttpBackend($browser, XHR, $browserDefer, $window, body, locationProtocol) {    var idCounter = 0; -  function completeRequest(callback, status, response) { -    // normalize IE bug (http://bugs.jquery.com/ticket/1450) -    callback(status == 1223 ? 204 : status, response); -    $browser.$$completeOutstandingRequest(noop); -  } -    // TODO(vojta): fix the signature    return function(method, url, post, callback, headers, timeout) {      $browser.$$incOutstandingRequestCount(); @@ -81,6 +76,20 @@ function createHttpBackend($browser, XHR, $browserDefer, $window, body) {        return xhr;      } + +    function completeRequest(callback, status, response) { +      // URL_MATCH is defined in src/service/location.js +      var protocol = (url.match(URL_MATCH) || ['', locationProtocol])[1]; + +      // fix status code for file protocol (it's always 0) +      status = protocol == 'file' ? (response ? 200 : 404) : status; + +      // normalize IE bug (http://bugs.jquery.com/ticket/1450) +      status = status == 1223 ? 204 : status; + +      callback(status, response); +      $browser.$$completeOutstandingRequest(noop); +    }    };  } | 
