1 package org.apache.turbine.util; 2 3 18 19 import java.text.SimpleDateFormat ; 20 21 import java.util.Date ; 22 import java.util.Locale ; 23 import java.util.TimeZone ; 24 25 32 public class HttpUtils 33 { 34 37 private static SimpleDateFormat httpDateFormat; 38 39 static 40 { 41 httpDateFormat = new SimpleDateFormat ( 42 "EEE, dd MMM yyyy HH:mm:ss z", Locale.US); 43 httpDateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); 44 } 45 46 53 public static String formatHttpDate(Date date) 54 { 55 synchronized (httpDateFormat) 56 { 57 return httpDateFormat.format(date); 58 } 59 } 60 61 70 public static void setCacheHeaders(RunData data, int expiry) 71 { 72 if (0 == expiry) 73 { 74 data.getResponse().setHeader("Pragma", "no-cache"); 75 data.getResponse().setHeader("Cache-Control", "no-cache"); 76 data.getResponse().setHeader("Expires", 77 formatHttpDate(new Date ())); 78 } 79 else 80 { 81 Date expiryDate = new Date (System.currentTimeMillis() + expiry); 82 data.getResponse().setHeader("Expires", 83 formatHttpDate(expiryDate)); 84 } 85 } 86 87 } 88 | Popular Tags |