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

Commit f108a2a

Browse files
pkozlowski-opensourcevojtajina
authored andcommitted
fix($http): don't covert 0 status codes to 404 for non-file protocols
PR #5547 introduced conversion of all 0 status codes to 404 for cases where no response was recieved (previously this was done for the file:// protocol only). But this mechanism is too eager and masks legitimate cases where status 0 should be returned. This commits reverts to the previous mechanism of handling 0 status code for the file:// protocol (converting 0 to 404) while retaining the returned status code 0 for all the protocols other than file:// Fixes #6074 Fixes #6155
1 parent 7cbf61c commit f108a2a

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/ng/httpBackend.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,11 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
144144
jsonpDone = xhr = null;
145145

146146
// fix status code when it is 0 (0 status is undocumented).
147-
// Occurs when accessing file resources.
148-
// On Android 4.1 stock browser it occurs while retrieving files from application cache.
149-
status = (status === 0) ? (response ? 200 : 404) : status;
147+
// Occurs when accessing file resources or on Android 4.1 stock browser
148+
// while retrieving files from application cache.
149+
if (status === 0) {
150+
status = response ? 200 : urlResolve(url).protocol == 'file' ? 404 : 0;
151+
}
150152

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

test/ng/httpBackendSpec.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -456,27 +456,45 @@ describe('$httpBackend', function() {
456456
}
457457

458458

459-
it('should convert 0 to 200 if content', function() {
459+
it('should convert 0 to 200 if content and file protocol', function() {
460460
$backend = createHttpBackend($browser, createMockXhr);
461461

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

465465
expect(callback).toHaveBeenCalled();
466466
expect(callback.mostRecentCall.args[0]).toBe(200);
467467
});
468468

469-
470-
it('should convert 0 to 404 if no content', function() {
469+
it('should convert 0 to 200 if content for protocols other than file', function() {
471470
$backend = createHttpBackend($browser, createMockXhr);
472471

473472
$backend('GET', 'someProtocol:///whatever/index.html', null, callback);
473+
respond(0, 'SOME CONTENT');
474+
475+
expect(callback).toHaveBeenCalled();
476+
expect(callback.mostRecentCall.args[0]).toBe(200);
477+
});
478+
479+
it('should convert 0 to 404 if no content and file protocol', function() {
480+
$backend = createHttpBackend($browser, createMockXhr);
481+
482+
$backend('GET', 'file:///whatever/index.html', null, callback);
474483
respond(0, '');
475484

476485
expect(callback).toHaveBeenCalled();
477486
expect(callback.mostRecentCall.args[0]).toBe(404);
478487
});
479488

489+
it('should not convert 0 to 404 if no content for protocols other than file', function() {
490+
$backend = createHttpBackend($browser, createMockXhr);
491+
492+
$backend('GET', 'someProtocol:///whatever/index.html', null, callback);
493+
respond(0, '');
494+
495+
expect(callback).toHaveBeenCalled();
496+
expect(callback.mostRecentCall.args[0]).toBe(0);
497+
});
480498

481499
it('should convert 0 to 404 if no content - relative url', function() {
482500
var originalUrlParsingNode = urlParsingNode;
@@ -486,10 +504,10 @@ describe('$httpBackend', function() {
486504
hash : "#/C:/",
487505
host : "",
488506
hostname : "",
489-
href : "someProtocol:///C:/base#!/C:/foo",
507+
href : "file:///C:/base#!/C:/foo",
490508
pathname : "/C:/foo",
491509
port : "",
492-
protocol : "someProtocol:",
510+
protocol : "file:",
493511
search : "",
494512
setAttribute: angular.noop
495513
};

0 commit comments

Comments
 (0)