HADOOP-6607. Add different variants of non caching HTTP headers. (tucu)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1409921 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Alejandro Abdelnur 2012-11-15 18:45:58 +00:00
parent 8a2de21315
commit ce2067fb15
4 changed files with 17 additions and 2 deletions

View File

@ -431,6 +431,8 @@ Release 2.0.3-alpha - Unreleased
HADOOP-8999. SASL negotiation is flawed (daryn) HADOOP-8999. SASL negotiation is flawed (daryn)
HADOOP-6607. Add different variants of non caching HTTP headers. (tucu)
Release 2.0.2-alpha - 2012-09-07 Release 2.0.2-alpha - 2012-09-07
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -25,7 +25,12 @@ import java.net.BindException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.URL; import java.net.URL;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.net.ssl.SSLServerSocketFactory; import javax.net.ssl.SSLServerSocketFactory;
import javax.servlet.Filter; import javax.servlet.Filter;

View File

@ -38,6 +38,10 @@ public class NoCacheFilter implements Filter {
throws IOException, ServletException { throws IOException, ServletException {
HttpServletResponse httpRes = (HttpServletResponse) res; HttpServletResponse httpRes = (HttpServletResponse) res;
httpRes.setHeader("Cache-Control", "no-cache"); httpRes.setHeader("Cache-Control", "no-cache");
long now = System.currentTimeMillis();
httpRes.addDateHeader("Expires", now);
httpRes.addDateHeader("Date", now);
httpRes.addHeader("Pragma", "no-cache");
chain.doFilter(req, res); chain.doFilter(req, res);
} }

View File

@ -546,6 +546,10 @@ public class TestHttpServer extends HttpServerFunctionalTest {
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); HttpURLConnection conn = (HttpURLConnection) url.openConnection();
assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode()); assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
assertEquals("no-cache", conn.getHeaderField("Cache-Control")); assertEquals("no-cache", conn.getHeaderField("Cache-Control"));
assertEquals("no-cache", conn.getHeaderField("Pragma"));
assertNotNull(conn.getHeaderField("Expires"));
assertNotNull(conn.getHeaderField("Date"));
assertEquals(conn.getHeaderField("Expires"), conn.getHeaderField("Date"));
} }
} }