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

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1409923 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Alejandro Abdelnur 2012-11-15 18:47:29 +00:00
parent 210941550a
commit 5ce643babe
4 changed files with 17 additions and 2 deletions

View File

@ -145,6 +145,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

@ -24,7 +24,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;
@ -956,7 +961,7 @@ public class HttpServer implements FilterContainer {
@Override @Override
public Enumeration<String> getParameterNames() { public Enumeration<String> getParameterNames() {
return new Enumeration<String>() { return new Enumeration<String>() {
private Enumeration<String> rawIterator = private Enumeration<String> rawIterator =
rawRequest.getParameterNames(); rawRequest.getParameterNames();
@Override @Override
public boolean hasMoreElements() { public boolean hasMoreElements() {

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"));
} }
} }