I am trying to provide a secured file serving feature for a site. I have considered a couple of options that fit with my current model:
- Using XMLHttpRequest to retrieve the contents of a file, and then offering either display or Save As features based on file type and user preference.
I understand how to use binary Ajax features (blob, arraybuffer) to retrieve binary files and I have seen this shim for implementing the HTML5 Save As feature, but I am concerned about performance with this technique re: large files. I have not tested yet but I don't expect good performance downloading a 1GB+ file using this technique.
- setting an HTTP header on a link (see below) so I can pass an authentication token in the header but still have the file served directly to the browser like a normal download rather than going through the trouble of retrieving the contents with XMLHttpRequest.
I would prefer this method because it fits nicely with the current authentication framework and would require very little extra code, but as far as I can tell only Firefox supports what I want to do.
Firefox has the ability to set http headers in network calls not initiated explicitly by JavaScript code using httpChannel: Firefox HTTP channels. Does anyone know whether this functionality is supported in other browsers? I want to be able to set a link, e.g. :
window.location.href = 'blah';
and have code observing network traffic that sets a custom HTTP header:
httpChannel.setRequestHeader("X-Hello", "World", false);
While it is very cool that Firefox can do this, I need a cross-browser solution. I have seen this question:
Setting request header, in a URL
which is basically what I want to do, but the only recommended solution there is setting session cookies, which I am not using.