Changeset d34a7ca8 in vaadin


Ignore:
Timestamp:
Nov 9, 2011 8:48:21 AM (3 years ago)
Author:
Leif Åstrand <leif@…>
Branches:
master, 7.0, 7.1, 729110dbdbccbce7bd1e68b6b383a04b4747883d, 3aca4c731040c45664d2d8086ccc614692097f98
Children:
6d2cd8be
Parents:
3159f002
Message:

Moved setting cache time and date headers to WrappedResponse

Location:
src/com/vaadin/terminal
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/com/vaadin/terminal/WrappedResponse.java

    r14c7c17f rd34a7ca8  
    1313    public void setHeader(String name, String value); 
    1414 
     15    public void setDateHeader(String name, long timestamp); 
     16 
    1517    public OutputStream getOutputStream() throws IOException; 
    1618 
    1719    public PrintWriter getWriter() throws IOException; 
    1820 
     21    /** 
     22     * Sets time in milliseconds, -1 means no cache at all. All required headers 
     23     * related to caching in the response are set based on the time. 
     24     *  
     25     * @param milliseconds 
     26     *            Cache time in milliseconds 
     27     */ 
     28    public void setCacheTime(long milliseconds); 
     29 
    1930} 
  • src/com/vaadin/terminal/gwt/server/ApplicationResourceHandler.java

    r14c7c17f rd34a7ca8  
    44import java.io.InputStream; 
    55import java.io.OutputStream; 
    6 import java.text.DateFormat; 
    7 import java.text.SimpleDateFormat; 
    8 import java.util.Date; 
    96import java.util.Iterator; 
    10 import java.util.Locale; 
    11 import java.util.TimeZone; 
    127import java.util.regex.Matcher; 
    138import java.util.regex.Pattern; 
     
    2318 
    2419public class ApplicationResourceHandler implements RequestHandler { 
    25     private static final DateFormat HTTP_DATE_FORMAT = new SimpleDateFormat( 
    26             "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH); 
    27     static { 
    28         HTTP_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT")); 
    29     } 
    3020    private static final Pattern APP_RESOURCE_PATTERN = Pattern 
    3121            .compile("/APP/(\\d+)/.*"); 
     
    7262 
    7363                // Sets cache headers 
    74                 final long cacheTime = stream.getCacheTime(); 
    75                 if (cacheTime <= 0) { 
    76                     response.setHeader("Cache-Control", "no-cache"); 
    77                     response.setHeader("Pragma", "no-cache"); 
    78                     response.setHeader("Expires", 
    79                             HTTP_DATE_FORMAT.format(new Date(0))); 
    80                 } else { 
    81                     response.setHeader("Cache-Control", "max-age=" + cacheTime 
    82                             / 1000); 
    83                     response.setHeader( 
    84                             "Expires", 
    85                             HTTP_DATE_FORMAT.format(new Date(System 
    86                                     .currentTimeMillis() + cacheTime))); 
    87                     // Required to apply caching in some Tomcats 
    88                     response.setHeader("Pragma", "cache"); 
    89                 } 
     64                response.setCacheTime(stream.getCacheTime()); 
    9065 
    9166                // Copy download stream parameters directly 
  • src/com/vaadin/terminal/gwt/server/WrappedHttpServletResponse.java

    r427ca954 rd34a7ca8  
    4646    } 
    4747 
     48    public void setCacheTime(long milliseconds) { 
     49        doSetCacheTime(this, milliseconds); 
     50    } 
     51 
     52    // Implementation shared with WrappedPortletResponse 
     53    static void doSetCacheTime(WrappedResponse response, long milliseconds) { 
     54        if (milliseconds <= 0) { 
     55            response.setHeader("Cache-Control", "no-cache"); 
     56            response.setHeader("Pragma", "no-cache"); 
     57            response.setDateHeader("Expires", 0); 
     58        } else { 
     59            response.setHeader("Cache-Control", "max-age=" + milliseconds 
     60                    / 1000); 
     61            response.setDateHeader("Expires", System.currentTimeMillis() 
     62                    + milliseconds); 
     63            // Required to apply caching in some Tomcats 
     64            response.setHeader("Pragma", "cache"); 
     65        } 
     66    } 
     67 
     68    public void setDateHeader(String name, long timestamp) { 
     69        response.setDateHeader(name, timestamp); 
     70    } 
    4871} 
  • src/com/vaadin/terminal/gwt/server/WrappedPortletResponse.java

    r04b52d9b rd34a7ca8  
    44import java.io.OutputStream; 
    55import java.io.PrintWriter; 
     6import java.text.DateFormat; 
     7import java.text.SimpleDateFormat; 
     8import java.util.Date; 
     9import java.util.Locale; 
     10import java.util.TimeZone; 
    611 
    712import javax.portlet.MimeResponse; 
     
    1217 
    1318public class WrappedPortletResponse implements WrappedResponse { 
     19    private static final DateFormat HTTP_DATE_FORMAT = new SimpleDateFormat( 
     20            "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH); 
     21    static { 
     22        HTTP_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT")); 
     23    } 
    1424 
    1525    private final PortletResponse response; 
     
    4353        response.setProperty(name, value); 
    4454    } 
     55 
     56    public void setDateHeader(String name, long timestamp) { 
     57        response.setProperty(name, HTTP_DATE_FORMAT.format(new Date(timestamp))); 
     58    } 
     59 
     60    public void setCacheTime(long milliseconds) { 
     61        WrappedHttpServletResponse.doSetCacheTime(this, milliseconds); 
     62    } 
    4563} 
Note: See TracChangeset for help on using the changeset viewer.