Created
October 22, 2019 07:20
-
-
Save greenlaw110/bd7016eb54b07194b9155619cbcdfb61 to your computer and use it in GitHub Desktop.
Intercepter to disable client cache for all endpoints - ActFramework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import act.util.Global; | |
import org.joda.time.DateTimeZone; | |
import org.joda.time.LocalDateTime; | |
import org.joda.time.format.DateTimeFormat; | |
import org.joda.time.format.DateTimeFormatter; | |
import org.osgl.$; | |
import org.osgl.aaa.NoAuthentication; | |
import org.osgl.http.H; | |
import org.osgl.mvc.annotation.After; | |
import org.osgl.util.S; | |
import org.osgl.web.util.UserAgent; | |
import java.util.Locale; | |
import static org.osgl.http.H.Header.Names.*; | |
public class DisableClientCacheInterceptor { | |
@After | |
@Global | |
@NoAuthentication | |
public void disableClientCache(H.Response response, UserAgent userAgent) { | |
response.header(CACHE_CONTROL, "no-cache, no-store, must-revalidate, proxy-revalidate, post-check=0, pre-check=0, max-age=0"); | |
if (userAgent.isSafari()) { | |
response.header(EXPIRES, "Sun, 19 Nov 1978 05:00:00 GMT"); | |
response.header(LAST_MODIFIED, lastModified($.ms())); | |
response.header(ETAG, S.string($.ms())); | |
} | |
} | |
private static String lastModified(long expirationInMillis) { | |
LocalDateTime localDateTime = new LocalDateTime(expirationInMillis, DateTimeZone.UTC); | |
DateTimeFormatter format = DateTimeFormat.forPattern("E, dd MMM Y HH:mm:ss").withLocale(Locale.ENGLISH); | |
return format.print(localDateTime) + " GMT"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment