fix($httpBackend): Allow status code 0 from any protocol

Android 4.1 stock browser also returns status code 0 when
a template is loaded via `http` and the application is cached using
appcache.

Fixes #1356.
Closes #5547.
This commit is contained in:
Rafał Jagoda 2013-12-27 12:55:02 +01:00 committed by Tobias Bosch
parent b6c42d5e81
commit 28fc80bba0
2 changed files with 9 additions and 9 deletions

View file

@ -121,14 +121,14 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
} }
function completeRequest(callback, status, response, headersString) { function completeRequest(callback, status, response, headersString) {
var protocol = urlResolve(url).protocol;
// cancel timeout and subsequent timeout promise resolution // cancel timeout and subsequent timeout promise resolution
timeoutId && $browserDefer.cancel(timeoutId); timeoutId && $browserDefer.cancel(timeoutId);
jsonpDone = xhr = null; jsonpDone = xhr = null;
// fix status code for file protocol (it's always 0) // fix status code when it is 0 (0 status is undocumented).
status = (protocol == 'file' && status === 0) ? (response ? 200 : 404) : status; // Occurs when accessing file resources.
// On Android 4.1 stock browser it occurs while retrieving files from application cache.
status = (status === 0) ? (response ? 200 : 404) : status;
// normalize IE bug (http://bugs.jquery.com/ticket/1450) // normalize IE bug (http://bugs.jquery.com/ticket/1450)
status = status == 1223 ? 204 : status; status = status == 1223 ? 204 : status;

View file

@ -421,7 +421,7 @@ describe('$httpBackend', function() {
// TODO(vojta): test whether it fires "async-end" on both success and error // TODO(vojta): test whether it fires "async-end" on both success and error
}); });
describe('file protocol', function() { describe('protocols that return 0 status code', function() {
function respond(status, content) { function respond(status, content) {
xhr = MockXhr.$$lastInstance; xhr = MockXhr.$$lastInstance;
@ -435,7 +435,7 @@ describe('$httpBackend', function() {
it('should convert 0 to 200 if content', function() { it('should convert 0 to 200 if content', function() {
$backend = createHttpBackend($browser, createMockXhr); $backend = createHttpBackend($browser, createMockXhr);
$backend('GET', 'file:///whatever/index.html', null, callback); $backend('GET', 'someProtocol:///whatever/index.html', null, callback);
respond(0, 'SOME CONTENT'); respond(0, 'SOME CONTENT');
expect(callback).toHaveBeenCalled(); expect(callback).toHaveBeenCalled();
@ -446,7 +446,7 @@ describe('$httpBackend', function() {
it('should convert 0 to 404 if no content', function() { it('should convert 0 to 404 if no content', function() {
$backend = createHttpBackend($browser, createMockXhr); $backend = createHttpBackend($browser, createMockXhr);
$backend('GET', 'file:///whatever/index.html', null, callback); $backend('GET', 'someProtocol:///whatever/index.html', null, callback);
respond(0, ''); respond(0, '');
expect(callback).toHaveBeenCalled(); expect(callback).toHaveBeenCalled();
@ -462,10 +462,10 @@ describe('$httpBackend', function() {
hash : "#/C:/", hash : "#/C:/",
host : "", host : "",
hostname : "", hostname : "",
href : "file:///C:/base#!/C:/foo", href : "someProtocol:///C:/base#!/C:/foo",
pathname : "/C:/foo", pathname : "/C:/foo",
port : "", port : "",
protocol : "file:", protocol : "someProtocol:",
search : "", search : "",
setAttribute: angular.noop setAttribute: angular.noop
}; };