Revision: 4495
Author: [email protected]
Date: Mon Jun 6 16:07:54 2011
Log: neuter appengine http proxy cache
http://codereview.appspot.com/4530056
appengine has an http proxy cache that makes it annoying to use
the caja playground there. if you modify the contents at a url,
it can take several minutes before the change is visible to the
playground, and which version the playground gets can vary depending
on which instance of the proxy cache happens to answer the request.
this change reduces the annoyance by sending a Cache-Control header
with the playground's url fetches, which is honored by the proxy cache.
I tested this by manually uploading before/after versions to a
test app at appengine, and manually fiddling with them, verifying
that the "before" version notices changes slowly and inconsistently,
but the "after" version notices changes quickly and consistently.
[email protected]
http://code.google.com/p/google-caja/source/detail?r=4495
Modified:
/trunk/src/com/google/caja/demos/playground/server/GWTCajolingServiceImpl.java
=======================================
---
/trunk/src/com/google/caja/demos/playground/server/GWTCajolingServiceImpl.java
Thu May 12 13:11:27 2011
+++
/trunk/src/com/google/caja/demos/playground/server/GWTCajolingServiceImpl.java
Mon Jun 6 16:07:54 2011
@@ -16,8 +16,10 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URLConnection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -80,8 +82,13 @@
public FetchedData fetch(ExternalReference ref, String mimeType)
throws UriFetchException {
try {
- return FetchedData.fromConnection(
- ref.getUri().toURL().openConnection());
+ HttpURLConnection conn = (HttpURLConnection)
+ ref.getUri().toURL().openConnection();
+ // appengine has a caching http proxy; this limits it
+ conn.setRequestProperty("Cache-Control", "max-age=10");
+ return FetchedData.fromConnection(conn);
+ } catch (ClassCastException ex) {
+ throw new UriFetchException(ref, mimeType, ex);
} catch (IOException ex) {
throw new UriFetchException(ref, mimeType, ex);
}