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

fix($http): don't covert 0 status codes to 404 for non-file protocols #6504

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/ng/httpBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
jsonpDone = xhr = null;

// fix status code when it is 0 (0 status is undocumented).
// 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;
// Occurs when accessing file resources or n Android 4.1 stock browser
// while retrieving files from application cache.
if (status === 0) {
status = response ? 200 : urlResolve(url).protocol == 'file' ? 404 : 0;
}

// normalize IE bug (http://bugs.jquery.com/ticket/1450)
status = status == 1223 ? 204 : status;
Expand Down
30 changes: 24 additions & 6 deletions test/ng/httpBackendSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,27 +456,45 @@ describe('$httpBackend', function() {
}


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

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

expect(callback).toHaveBeenCalled();
expect(callback.mostRecentCall.args[0]).toBe(200);
});


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

$backend('GET', 'someProtocol:///whatever/index.html', null, callback);
respond(0, 'SOME CONTENT');

expect(callback).toHaveBeenCalled();
expect(callback.mostRecentCall.args[0]).toBe(200);
});

it('should convert 0 to 404 if no content and file protocol', function() {
$backend = createHttpBackend($browser, createMockXhr);

$backend('GET', 'file:///whatever/index.html', null, callback);
respond(0, '');

expect(callback).toHaveBeenCalled();
expect(callback.mostRecentCall.args[0]).toBe(404);
});

it('should not convert 0 to 404 if no content for protocols other than file', function() {
$backend = createHttpBackend($browser, createMockXhr);

$backend('GET', 'someProtocol:///whatever/index.html', null, callback);
respond(0, '');

expect(callback).toHaveBeenCalled();
expect(callback.mostRecentCall.args[0]).toBe(0);
});

it('should convert 0 to 404 if no content - relative url', function() {
var originalUrlParsingNode = urlParsingNode;
Expand All @@ -486,10 +504,10 @@ describe('$httpBackend', function() {
hash : "#/C:/",
host : "",
hostname : "",
href : "someProtocol:///C:/base#!/C:/foo",
href : "file:///C:/base#!/C:/foo",
pathname : "/C:/foo",
port : "",
protocol : "someProtocol:",
protocol : "file:",
search : "",
setAttribute: angular.noop
};
Expand Down