Enhance default Http resource handling to support "conditional GET"
-------------------------------------------------------------------

                 Key: FELIX-407
                 URL: https://issues.apache.org/jira/browse/FELIX-407
             Project: Felix
          Issue Type: Improvement
          Components: HTTP Service
            Reporter: Rob Walker
            Priority: Minor


Whilst creating a generic "file serving" servlet, I realised our default HTTP 
resource serving in org.apache.felix.http.jetty.OsgiResourceHandler does not 
actually support "conditional GET" functionalty.

A few, relatively simple, mods could be made to support this:

(1) - enhance default handler to include last modified time in responses  e.g.

        response.setDateHeader("Last-Modified", urlConn.lastModified());

Note however, that Sun in their JNLP servlet document a bug where "file:" URL 
resources do not return last modified correctly, so an extra test is needed for 
file URLs. Following is from Sun JnlpDownloadServlet:

<code>
        try {
            // Get last modified time
            conn = resource.openConnection();
            lastModified = conn.getLastModified();
        } catch (Exception e) {
            // do nothing
        }
        
        if (lastModified == 0) {
            // Arguably a bug in the JRE will not set the lastModified for file 
URLs, and
            // always return 0. This is a workaround for that problem.
            String filepath = context.getRealPath(path); 
            if (filepath != null) {
                File f = new File(filepath);        
                if (f.exists()) {
                    lastModified = f.lastModified();
                }
            }
<code>


(2) check incoming requests for a "If-Modified-Since" header, and if present 
check against the file timestamp. If server file has not change since this 
time, return a 304 (SC_NOT_MODIFIED) status

Found a useful summary from which I based the above here:

(3) for extra robustness on "file" resources the above can be extended to also 
use a combination of an "ETag" header e.g. made up of file timestamp + file 
size & a check against the "If-None-Match" request header

http://fishbowl.pastiche.org/2002/10/21/http_conditional_get_for_rss_hackers



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to