- Set default cache-control for webapps and eepsite
    - Disable dir listing for console webapps
  * WebAppStarter: Remove static log
This commit is contained in:
zzz
2012-03-14 12:04:20 +00:00
parent 326b9998fd
commit 17f9280b3f
5 changed files with 23 additions and 17 deletions

View File

@ -101,8 +101,7 @@ public class I2PSnarkServlet extends DefaultServlet {
public Resource getResource(String pathInContext) public Resource getResource(String pathInContext)
{ {
if (pathInContext == null || pathInContext.equals("/") || pathInContext.equals("/index.jsp") || if (pathInContext == null || pathInContext.equals("/") || pathInContext.equals("/index.jsp") ||
pathInContext.equals("/index.html") || pathInContext.startsWith("/.icons/") || pathInContext.equals("/index.html") || pathInContext.startsWith("/.icons/"))
pathInContext.startsWith("/.js/") || pathInContext.startsWith("/.ajax/"))
return super.getResource(pathInContext); return super.getResource(pathInContext);
// files in the i2psnark/ directory // files in the i2psnark/ directory
try { try {
@ -118,9 +117,6 @@ public class I2PSnarkServlet extends DefaultServlet {
*/ */
@Override @Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
////////////////////////////////////
//if (resource.getName().startsWith("jar:file:"))
// response.setHeader("Cache-Control", "max-age=86400"); // cache for a day
super.doGet(request, response); super.doGet(request, response);
} }

View File

@ -28,6 +28,7 @@ public class LocaleWebAppHandler extends WebAppContext
public LocaleWebAppHandler(I2PAppContext ctx, String path, String warPath) { public LocaleWebAppHandler(I2PAppContext ctx, String path, String warPath) {
super(warPath, path); super(warPath, path);
_context = ctx; _context = ctx;
setInitParams(WebAppStarter.INIT_PARAMS);
} }
/** /**

View File

@ -2,15 +2,12 @@ package net.i2p.router.web;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
import net.i2p.util.FileUtil; import net.i2p.util.FileUtil;
import net.i2p.util.Log;
import net.i2p.util.SecureDirectory; import net.i2p.util.SecureDirectory;
import net.i2p.util.PortMapper; import net.i2p.util.PortMapper;
@ -39,11 +36,16 @@ import org.mortbay.jetty.handler.ContextHandlerCollection;
*/ */
public class WebAppStarter { public class WebAppStarter {
static final Map<String, Long> warModTimes = new ConcurrentHashMap(); private static final Map<String, Long> warModTimes = new ConcurrentHashMap();
static private Log _log; static final Map INIT_PARAMS = new HashMap(4);
//static private Log _log;
static { static {
_log = ContextHelper.getContext(null).logManager().getLog(WebAppStarter.class); ; //_log = ContextHelper.getContext(null).logManager().getLog(WebAppStarter.class); ;
// see DefaultServlet javadocs
String pfx = "org.mortbay.jetty.servlet.Default.";
INIT_PARAMS.put(pfx + "cacheControl", "max-age=86400");
INIT_PARAMS.put(pfx + "dirAllowed", "false");
} }
@ -55,7 +57,8 @@ public class WebAppStarter {
String appName, String warPath) throws Exception { String appName, String warPath) throws Exception {
File tmpdir = new SecureDirectory(ctx.getTempDir(), "jetty-work-" + appName + ctx.random().nextInt()); File tmpdir = new SecureDirectory(ctx.getTempDir(), "jetty-work-" + appName + ctx.random().nextInt());
WebAppContext wac = addWebApp(ctx, server, appName, warPath, tmpdir); WebAppContext wac = addWebApp(ctx, server, appName, warPath, tmpdir);
_log.debug("Loading war from: " + warPath); //_log.debug("Loading war from: " + warPath);
wac.setInitParams(INIT_PARAMS);
wac.start(); wac.start();
} }
@ -102,8 +105,6 @@ public class WebAppStarter {
// this does the passwords... // this does the passwords...
RouterConsoleRunner.initialize(wac); RouterConsoleRunner.initialize(wac);
// see WebAppConfiguration for info // see WebAppConfiguration for info
String[] classNames = wac.getConfigurationClasses(); String[] classNames = wac.getConfigurationClasses();
String[] newClassNames = new String[classNames.length + 1]; String[] newClassNames = new String[classNames.length + 1];

View File

@ -11,6 +11,16 @@ to serve static html files and images.
<Configure class="org.mortbay.jetty.servlet.Context"> <Configure class="org.mortbay.jetty.servlet.Context">
<Set name="contextPath">/</Set> <Set name="contextPath">/</Set>
<Set name="resourceBase">./eepsite/docroot/</Set> <Set name="resourceBase">./eepsite/docroot/</Set>
<Call name="setInitParams">
<Arg>
<Map>
<Entry>
<Item>orb.mortbay.jetty.servlet.Default.cacheControl</Item>
<Item>max-age=3600,public</Item>
</Entry>
</Map>
</Arg>
</Call>
<Call name="addServlet"> <Call name="addServlet">
<Arg>org.mortbay.jetty.servlet.DefaultServlet</Arg> <Arg>org.mortbay.jetty.servlet.DefaultServlet</Arg>
<Arg>/</Arg> <Arg>/</Arg>

View File

@ -153,12 +153,10 @@
<param-name>useFileMappedBuffer</param-name> <param-name>useFileMappedBuffer</param-name>
<param-value>true</param-value> <param-value>true</param-value>
</init-param> </init-param>
<!--
<init-param> <init-param>
<param-name>cacheControl</param-name> <param-name>cacheControl</param-name>
<param-value>max-age=3600,public</param-value> <param-value>max-age=3600,public</param-value>
</init-param> </init-param>
-->
<load-on-startup>0</load-on-startup> <load-on-startup>0</load-on-startup>
</servlet> </servlet>