Ticket #2726 (new bug)

Opened 3 years ago

Last modified 3 years ago

HTTP data fails to load when web page uses file:// protocol

Reported by: Hooman Owned by:
Priority: minor Milestone: 2.13 Release
Component: Protocol.HTTP Version: 2.8
Keywords: HTTP, response status, file url Cc:
State:

Description

When using FireFox on WinXP, data loaded through Protocol.HTTP has a response status of 0 when the web page is loaded using the "file" protocol. This fails the 200...300 response status check, causing the data to be rejected, which otherwise would have loaded successfully. Adding a response status of 0 to the success check would allow this to work.

Technically, this would pollute the HTTP protocol object with code to check for a case when HTTP isn't actually be used. However, there is no alternate protocol that is suitable in this case, and 0 isn't a valid HTTP response status that the check would interfere with. Essentially this would allow fetching of data from the same place as the web page without worrying if it actually uses HTTP or was simply a file on disk.

The issue was discovered when a static HTML file was loading a static GML file using a relative URL (i.e. 'Test.gml'). The GML data was being loaded into a Vector layer, with visibility initially set to false, using a Fixed strategy (set to preload), and using an HTTP protocol object. The setup follows the recommendation in the deprecation warning in the API docs for the OpenLayers.Layer.GML class. Data loads as expected when served through a web server, but fails to load when opened locally. The same behavior was expected in both cases.

A possible fix would be to use the following check:

if(request.status >= 200 && request.status < 300 || request.status == 0) {

This is in HTTP.js on line 345 (OpenLayers 2.8) or line 459 (OpenLayers 2.9.1). This fix has been verified to solve the problem.

Change History

Changed 3 years ago by Herm

  • type changed from feature to bug

I can verify that the patch mentioned in the above bugreport works. I've also run into this problem.

The same check is already present in Request.js (line 215, Openlayers 2.9.1), so it should be included in HTTP.js as well.

if (!request.status || (request.status >= 200 && request.status < 300)) {
Note: See TracTickets for help on using tickets.