HADOO-8998. set Cache-Control no-cache header on all dynamic content. (tucu)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1409095 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a780f0ac33
commit
ec8ed4e951
|
@ -364,6 +364,8 @@ Release 2.0.3-alpha - Unreleased
|
||||||
HADOOP-9021. Enforce configured SASL method on the server (daryn via
|
HADOOP-9021. Enforce configured SASL method on the server (daryn via
|
||||||
bobby)
|
bobby)
|
||||||
|
|
||||||
|
HADOO-8998. set Cache-Control no-cache header on all dynamic content. (tucu)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HADOOP-8866. SampleQuantiles#query is O(N^2) instead of O(N). (Andrew Wang
|
HADOOP-8866. SampleQuantiles#query is O(N^2) instead of O(N). (Andrew Wang
|
||||||
|
|
|
@ -25,11 +25,7 @@ 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.ArrayList;
|
import java.util.*;
|
||||||
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;
|
||||||
|
@ -103,6 +99,7 @@ public class HttpServer implements FilterContainer {
|
||||||
public static final String CONF_CONTEXT_ATTRIBUTE = "hadoop.conf";
|
public static final String CONF_CONTEXT_ATTRIBUTE = "hadoop.conf";
|
||||||
public static final String ADMINS_ACL = "admins.acl";
|
public static final String ADMINS_ACL = "admins.acl";
|
||||||
public static final String SPNEGO_FILTER = "SpnegoFilter";
|
public static final String SPNEGO_FILTER = "SpnegoFilter";
|
||||||
|
public static final String NO_CACHE_FILTER = "NoCacheFilter";
|
||||||
|
|
||||||
public static final String BIND_ADDRESS = "bind.address";
|
public static final String BIND_ADDRESS = "bind.address";
|
||||||
|
|
||||||
|
@ -255,6 +252,7 @@ public class HttpServer implements FilterContainer {
|
||||||
webAppContext.setWar(appDir + "/" + name);
|
webAppContext.setWar(appDir + "/" + name);
|
||||||
webAppContext.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, conf);
|
webAppContext.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, conf);
|
||||||
webAppContext.getServletContext().setAttribute(ADMINS_ACL, adminsAcl);
|
webAppContext.getServletContext().setAttribute(ADMINS_ACL, adminsAcl);
|
||||||
|
addNoCacheFilter(webAppContext);
|
||||||
webServer.addHandler(webAppContext);
|
webServer.addHandler(webAppContext);
|
||||||
|
|
||||||
addDefaultApps(contexts, appDir, conf);
|
addDefaultApps(contexts, appDir, conf);
|
||||||
|
@ -279,6 +277,12 @@ public class HttpServer implements FilterContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private void addNoCacheFilter(WebAppContext ctxt) {
|
||||||
|
defineFilter(ctxt, NO_CACHE_FILTER,
|
||||||
|
NoCacheFilter.class.getName(), Collections.EMPTY_MAP, new String[] { "/*"});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a required listener for the Jetty instance listening on the port
|
* Create a required listener for the Jetty instance listening on the port
|
||||||
* provided. This wrapper and all subclasses must create at least one
|
* provided. This wrapper and all subclasses must create at least one
|
||||||
|
@ -338,6 +342,7 @@ public class HttpServer implements FilterContainer {
|
||||||
}
|
}
|
||||||
logContext.setDisplayName("logs");
|
logContext.setDisplayName("logs");
|
||||||
setContextAttributes(logContext, conf);
|
setContextAttributes(logContext, conf);
|
||||||
|
addNoCacheFilter(webAppContext);
|
||||||
defaultContexts.put(logContext, true);
|
defaultContexts.put(logContext, true);
|
||||||
}
|
}
|
||||||
// set up the context for "/static/*"
|
// set up the context for "/static/*"
|
||||||
|
@ -369,6 +374,7 @@ public class HttpServer implements FilterContainer {
|
||||||
public void addContext(Context ctxt, boolean isFiltered)
|
public void addContext(Context ctxt, boolean isFiltered)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
webServer.addHandler(ctxt);
|
webServer.addHandler(ctxt);
|
||||||
|
addNoCacheFilter(webAppContext);
|
||||||
defaultContexts.put(ctxt, isFiltered);
|
defaultContexts.put(ctxt, isFiltered);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.hadoop.http;
|
||||||
|
|
||||||
|
import javax.servlet.Filter;
|
||||||
|
import javax.servlet.FilterChain;
|
||||||
|
import javax.servlet.FilterConfig;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.ServletResponse;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class NoCacheFilter implements Filter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(FilterConfig filterConfig) throws ServletException {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doFilter(ServletRequest req, ServletResponse res,
|
||||||
|
FilterChain chain)
|
||||||
|
throws IOException, ServletException {
|
||||||
|
HttpServletResponse httpRes = (HttpServletResponse) res;
|
||||||
|
httpRes.setHeader("Cache-Control", "no-cache");
|
||||||
|
chain.doFilter(req, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -539,4 +539,13 @@ public class TestHttpServer extends HttpServerFunctionalTest {
|
||||||
}
|
}
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoCacheHeader() throws Exception {
|
||||||
|
URL url = new URL(baseUrl, "/echo?a=b&c=d");
|
||||||
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
|
assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
|
||||||
|
assertEquals("no-cache", conn.getHeaderField("Cache-Control"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue