Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 28fc80b

Browse files
rafallotbosch
authored andcommitted
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.
1 parent b6c42d5 commit 28fc80b

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/ng/httpBackend.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
121121
}
122122

123123
function completeRequest(callback, status, response, headersString) {
124-
var protocol = urlResolve(url).protocol;
125-
126124
// cancel timeout and subsequent timeout promise resolution
127125
timeoutId && $browserDefer.cancel(timeoutId);
128126
jsonpDone = xhr = null;
129127

130-
// fix status code for file protocol (it's always 0)
131-
status = (protocol == 'file' && status === 0) ? (response ? 200 : 404) : status;
128+
// fix status code when it is 0 (0 status is undocumented).
129+
// Occurs when accessing file resources.
130+
// On Android 4.1 stock browser it occurs while retrieving files from application cache.
131+
status = (status === 0) ? (response ? 200 : 404) : status;
132132

133133
// normalize IE bug (http://bugs.jquery.com/ticket/1450)
134134
status = status == 1223 ? 204 : status;

test/ng/httpBackendSpec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ describe('$httpBackend', function() {
421421
// TODO(vojta): test whether it fires "async-end" on both success and error
422422
});
423423

424-
describe('file protocol', function() {
424+
describe('protocols that return 0 status code', function() {
425425

426426
function respond(status, content) {
427427
xhr = MockXhr.$$lastInstance;
@@ -435,7 +435,7 @@ describe('$httpBackend', function() {
435435
it('should convert 0 to 200 if content', function() {
436436
$backend = createHttpBackend($browser, createMockXhr);
437437

438-
$backend('GET', 'file:///whatever/index.html', null, callback);
438+
$backend('GET', 'someProtocol:///whatever/index.html', null, callback);
439439
respond(0, 'SOME CONTENT');
440440

441441
expect(callback).toHaveBeenCalled();
@@ -446,7 +446,7 @@ describe('$httpBackend', function() {
446446
it('should convert 0 to 404 if no content', function() {
447447
$backend = createHttpBackend($browser, createMockXhr);
448448

449-
$backend('GET', 'file:///whatever/index.html', null, callback);
449+
$backend('GET', 'someProtocol:///whatever/index.html', null, callback);
450450
respond(0, '');
451451

452452
expect(callback).toHaveBeenCalled();
@@ -462,10 +462,10 @@ describe('$httpBackend', function() {
462462
hash : "#/C:/",
463463
host : "",
464464
hostname : "",
465-
href : "file:///C:/base#!/C:/foo",
465+
href : "someProtocol:///C:/base#!/C:/foo",
466466
pathname : "/C:/foo",
467467
port : "",
468-
protocol : "file:",
468+
protocol : "someProtocol:",
469469
search : "",
470470
setAttribute: angular.noop
471471
};

0 commit comments

Comments
 (0)