Add Resource Headers and allow EL Expressions only on css files
---------------------------------------------------------------

                 Key: MYFACES-2460
                 URL: https://issues.apache.org/jira/browse/MYFACES-2460
             Project: MyFaces Core
          Issue Type: Task
          Components: JSR-314
    Affects Versions: 2.0.0-alpha
            Reporter: Leonardo Uribe


Actually, we have two methods in ResourceImpl with TODO'S:

ResourceImpl.getResponseHeaders()
ResourceImpl.userAgentNeedsUpdate()

This two were let without implementation, because it was not clear how it 
should behave. If EL Expressions were allowed, to allow add cache headers the 
value returned must be 

"application scope", but nothing on the spec says something about that.

This issue should be solved before start TOMAHAWK-1472 Add Support for new 
Resource API in tomahawk 2.0 module, because we need to define if a 
ResourceHandlerWrapper is required to provide some features and how it should 
behave.

There was some discussion on [email protected] around this two topic under 
the subject:

  [jsr-314-open] Evaluating EL in resource files

Fortunately, it seems some conclusion arise from this discussion, but there are 
not details about it, so we are forced to make a black box test on the latest 
release (2.0.1) to 

know what happened and decide what should we do on our side.

Doing some test with ri and firebug, these were the results:

RI
    GET teststyle.css.jsf
    Header Request:
    
        Host    localhost:8080
        User-Agent  Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.9.1.5) 
Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)
        Accept  text/css,*/*;q=0.1
        Accept-Language es-es,es;q=0.8,en-us;q=0.5,en;q=0.3
        Accept-Encoding gzip,deflate
        Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
        Keep-Alive  300
        Connection  keep-alive
        Referer http://localhost:8080/test-webapp/resourceHeaders.jsf
        Cookie  JSESSIONID=1pkha2z8zhgvu
        If-Modified-Since   Fri, 11 Dec 2009 21:34:07 GMT
        If-None-Match   W/"153-1260567247625"
    
    Header Response:
    
        X-Powered-By    JSF/2.0
        Content-Type    text/css
        Expires Fri, 11 Dec 2009 22:00:33 GMT
        Etag    W/"153-1260567247625"
        Last-Modified   Fri, 11 Dec 2009 21:34:07 GMT
        Content-Length  121
        Server  Jetty(6.1.16)

RI 
    GET testjs.js.jsf
    Header Request:

        Host    localhost:8080
        User-Agent  Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.9.1.5) 
Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)
        Accept  */*
        Accept-Language es-es,es;q=0.8,en-us;q=0.5,en;q=0.3
        Accept-Encoding gzip,deflate
        Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
        Keep-Alive  300
        Connection  keep-alive
        Referer http://localhost:8080/test-webapp/resourceHeaders.jsf
        Cookie  JSESSIONID=1pkha2z8zhgvu
        If-Modified-Since   Fri, 11 Dec 2009 21:34:13 GMT
        If-None-Match   W/"102-1260567253406"
    
    Header Response:
    
        X-Powered-By    JSF/2.0
        Expires Fri, 11 Dec 2009 22:00:33 GMT
        Content-Type    application/x-javascript
        Etag    W/"102-1260567253406"
        Last-Modified   Fri, 11 Dec 2009 21:34:13 GMT
        Content-Length  102
        Server  Jetty(6.1.16)

RI
    GET button.gif.jsf
    Header Request:

        Host    localhost:8080
        User-Agent  Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.9.1.5) 
Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)
        Accept  image/png,image/*;q=0.8,*/*;q=0.5
        Accept-Language es-es,es;q=0.8,en-us;q=0.5,en;q=0.3
        Accept-Encoding gzip,deflate
        Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
        Keep-Alive  300
        Connection  keep-alive
        Referer http://localhost:8080/test-webapp/resourceHeaders.jsf
        Cookie  JSESSIONID=1pkha2z8zhgvu
        If-Modified-Since   Wed, 02 Dec 2009 04:52:45 GMT
        If-None-Match   W/"61-1259729565078"

    Header Response:

        X-Powered-By    JSF/2.0
        Content-Type    image/gif
        Expires Fri, 11 Dec 2009 22:07:47 GMT
        Etag    W/"61-1259729565078"
        Last-Modified   Wed, 02 Dec 2009 04:52:45 GMT
        Content-Length  61
        Server  Jetty(6.1.16)

MYFACES

    GET testjs.js.jsf
    Header Request:

        Host    localhost:8080
        User-Agent  Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.9.1.5) 
Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)
        Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
        Accept-Language es-es,es;q=0.8,en-us;q=0.5,en;q=0.3
        Accept-Encoding gzip,deflate
        Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
        Keep-Alive  300
        Connection  keep-alive
        Cookie  JSESSIONID=1pkha2z8zhgvu

    Header Response:

        Content-Type    application/x-javascript
        Content-Length  72
        Server  Jetty(6.1.16)

Also, a 304 Not Modified response was returned by the server for all resources.

It was tested too if EL expressions are allowed on javascript or css files, but 
now it is only allowed on css files. 

The problem with ProjectStage in jsf javascript api was solved adding a param 
called "stage" on the rendered javascript url. If we are on Production stage, 
no param is written, 

but if we are on other stage, the javascript code must extract it in some way 
from its base url.

Since cache headers are present when request for resources, EL Expressions has 
application scope.

Note all three component libraries: Tobago, Trinidad and Tomahawk add cache 
headers, so we need to review what we do on all three:

Tomahawk:

    MyFacesResourceLoader read and set the following headers:
    
        If-Modified-Since (read)
        Last-Modified (set)
        Expires (set one week later)
        Cache-Control (set max-age=43200 or 12 hours)
    
        It also has an algorithm to correct contentType.
    
    StreamingResourceLoader set the following headers:
    
        pragma (set no-cache)
        Cache-control (no-cache, must-revalidate)
        
    CAPTCHARenderer does not set renderers.

    In theory, for jsf 2.0 we can replace MyfacesResourceLoader with the 
default impl and use a ResourceHandlerWrapper for StreamingResourceLoader and 
CAPTCHARenderer instead.

Trinidad:

   ResourceServlet has a method _setHeaders that set the following:

Last-Modified (Depends if is file or jar)
Cache-Control (set Public)
Expires (set to one year later)

Tobago:
   
   When no cache is required it sets:

      response.setHeader("Cache-Control", 
"no-cache,no-store,max-age=0,must-revalidate");
      response.setHeader("Pragma", "no-cache");
      response.setDateHeader("Expires", 0);
      response.setDateHeader("max-age", 0);

   Otherwise on ResourceServlet

      response.setHeader("Cache-Control", "max-age=" + expires);
      response.setDateHeader("Expires", new Date().getTime() + (expires * 
1000));

We have to keep into account css files have application scope for define cache 
headers.

That's all info required and pointers to code we can use for add cache headers 
on myfaces. 


-- 
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