annotate src/org/eclipse/jetty/server/handler/ResourceHandler.java @ 838:3afa8da69187

remove PatternMatcher
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 16 Sep 2016 13:24:20 -0600
parents f89abbfb3a8f
children 688c39c50ee3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 // ------------------------------------------------------------------------
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 // All rights reserved. This program and the accompanying materials
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 // are made available under the terms of the Eclipse Public License v1.0
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 // and Apache License v2.0 which accompanies this distribution.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 // The Eclipse Public License is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 // http://www.eclipse.org/legal/epl-v10.html
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 // The Apache License v2.0 is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 // http://www.opensource.org/licenses/apache2.0.php
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 // You may elect to redistribute this code under either of these licenses.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 package org.eclipse.jetty.server.handler;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 import java.io.IOException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 import java.io.OutputStream;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 import java.net.MalformedURLException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 import javax.servlet.ServletException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 import javax.servlet.http.HttpServletRequest;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 import javax.servlet.http.HttpServletResponse;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 import org.eclipse.jetty.http.HttpFields;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 import org.eclipse.jetty.http.HttpHeaders;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 import org.eclipse.jetty.http.HttpMethods;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 import org.eclipse.jetty.http.HttpStatus;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 import org.eclipse.jetty.http.MimeTypes;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 import org.eclipse.jetty.io.Buffer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 import org.eclipse.jetty.io.ByteArrayBuffer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 import org.eclipse.jetty.io.WriterOutputStream;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 import org.eclipse.jetty.server.AbstractHttpConnection;
822
0048a843297a remove Dispatcher
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
38 import javax.servlet.RequestDispatcher;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 import org.eclipse.jetty.server.Request;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 import org.eclipse.jetty.server.Response;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 import org.eclipse.jetty.server.handler.ContextHandler.Context;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 import org.eclipse.jetty.util.URIUtil;
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 805
diff changeset
43 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 805
diff changeset
44 import org.slf4j.LoggerFactory;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 import org.eclipse.jetty.util.resource.FileResource;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 import org.eclipse.jetty.util.resource.Resource;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 /* ------------------------------------------------------------ */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 /** Resource Handler.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 * This handle will serve static content and handle If-Modified-Since headers.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 * No caching is done.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 * Requests for resources that do not exist are let pass (Eg no 404's).
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 * @org.apache.xbean.XBean
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 public class ResourceHandler extends HandlerWrapper
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 {
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 805
diff changeset
61 private static final Logger LOG = LoggerFactory.getLogger(ResourceHandler.class);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
63 ContextHandler _context;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
64 Resource _baseResource;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
65 Resource _defaultStylesheet;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
66 Resource _stylesheet;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
67 String[] _welcomeFiles={"index.html"};
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
68 MimeTypes _mimeTypes = new MimeTypes();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
69 ByteArrayBuffer _cacheControl;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
70 boolean _aliases;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
71 boolean _directory;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
73 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
74 public ResourceHandler()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
75 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
76
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
77 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
79 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
80 public MimeTypes getMimeTypes()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
81 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
82 return _mimeTypes;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
83 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
84
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
85 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
86 public void setMimeTypes(MimeTypes mimeTypes)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
87 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
88 _mimeTypes = mimeTypes;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
89 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
91 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
92 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
93 * @return True if resource aliases are allowed.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
94 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
95 public boolean isAliases()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
96 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
97 return _aliases;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
98 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
100 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
101 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
102 * Set if resource aliases (eg symlink, 8.3 names, case insensitivity) are allowed.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
103 * Allowing aliases can significantly increase security vulnerabilities.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
104 * If this handler is deployed inside a ContextHandler, then the
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
105 * {@link ContextHandler#isAliases()} takes precedent.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
106 * @param aliases True if aliases are supported.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
107 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
108 public void setAliases(boolean aliases)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
109 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
110 _aliases = aliases;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
111 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
112
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
113 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
114 /** Get the directory option.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
115 * @return true if directories are listed.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
116 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
117 public boolean isDirectoriesListed()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
118 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
119 return _directory;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
120 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
122 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
123 /** Set the directory.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
124 * @param directory true if directories are listed.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
125 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
126 public void setDirectoriesListed(boolean directory)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
127 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
128 _directory = directory;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
129 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
130
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
131 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
132 @Override
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
133 public void doStart()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
134 throws Exception
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
135 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
136 Context scontext = ContextHandler.getCurrentContext();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
137 _context = (scontext==null?null:scontext.getContextHandler());
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
138
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
139 if (_context!=null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
140 _aliases=_context.isAliases();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
142 if (!_aliases && !FileResource.getCheckAliases())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
143 throw new IllegalStateException("Alias checking disabled");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
145 super.doStart();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
146 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
147
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
148 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
149 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
150 * @return Returns the resourceBase.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
151 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
152 public Resource getBaseResource()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
153 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
154 if (_baseResource==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
155 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
156 return _baseResource;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
157 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
159 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
160 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
161 * @return Returns the base resource as a string.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
162 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
163 public String getResourceBase()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
164 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
165 if (_baseResource==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
166 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
167 return _baseResource.toString();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
168 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
169
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
170
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
171 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
172 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
173 * @param base The resourceBase to set.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
174 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
175 public void setBaseResource(Resource base)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
176 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
177 _baseResource=base;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
178 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
179
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
180 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
181 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
182 * @param resourceBase The base resource as a string.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
183 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
184 public void setResourceBase(String resourceBase)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
185 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
186 try
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
187 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
188 setBaseResource(Resource.newResource(resourceBase));
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
189 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
190 catch (Exception e)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
191 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
192 LOG.warn(e.toString());
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 805
diff changeset
193 LOG.debug("",e);
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
194 throw new IllegalArgumentException(resourceBase);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
195 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
196 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
197
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
198 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
199 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
200 * @return Returns the stylesheet as a Resource.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
201 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
202 public Resource getStylesheet()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
203 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
204 if(_stylesheet != null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
205 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
206 return _stylesheet;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
207 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
208 else
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
209 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
210 if(_defaultStylesheet == null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
211 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
212 try
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
213 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
214 _defaultStylesheet = Resource.newResource(this.getClass().getResource("/org/eclipse/jetty/jetty-dir.css"));
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
215 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
216 catch(IOException e)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
217 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
218 LOG.warn(e.toString());
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 805
diff changeset
219 LOG.debug("",e);
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
220 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
221 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
222 return _defaultStylesheet;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
223 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
224 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
225
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
226 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
227 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
228 * @param stylesheet The location of the stylesheet to be used as a String.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
229 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
230 public void setStylesheet(String stylesheet)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
231 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
232 try
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
233 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
234 _stylesheet = Resource.newResource(stylesheet);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
235 if(!_stylesheet.exists())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
236 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
237 LOG.warn("unable to find custom stylesheet: " + stylesheet);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
238 _stylesheet = null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
239 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
240 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
241 catch(Exception e)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
242 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
243 LOG.warn(e.toString());
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 805
diff changeset
244 LOG.debug("",e);
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
245 throw new IllegalArgumentException(stylesheet.toString());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
246 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
247 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
248
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
249 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
250 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
251 * @return the cacheControl header to set on all static content.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
252 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
253 public String getCacheControl()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
254 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
255 return _cacheControl.toString();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
256 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
257
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
258 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
259 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
260 * @param cacheControl the cacheControl header to set on all static content.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
261 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
262 public void setCacheControl(String cacheControl)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
263 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
264 _cacheControl=cacheControl==null?null:new ByteArrayBuffer(cacheControl);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
265 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
266
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
267 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
268 /*
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
269 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
270 public Resource getResource(String path) throws MalformedURLException
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
271 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
272 if (path==null || !path.startsWith("/"))
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
273 throw new MalformedURLException(path);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
274
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
275 Resource base = _baseResource;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
276 if (base==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
277 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
278 if (_context==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
279 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
280 base=_context.getBaseResource();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
281 if (base==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
282 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
283 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
284
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
285 try
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
286 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
287 path=URIUtil.canonicalPath(path);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
288 return base.addPath(path);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
289 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
290 catch(Exception e)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
291 {
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 805
diff changeset
292 LOG.trace("",e);
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
293 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
294
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
295 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
296 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
297
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
298 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
299 protected Resource getResource(HttpServletRequest request) throws MalformedURLException
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
300 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
301 String servletPath;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
302 String pathInfo;
822
0048a843297a remove Dispatcher
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303 Boolean included = request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null;
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
304 if (included != null && included.booleanValue())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
305 {
822
0048a843297a remove Dispatcher
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
306 servletPath = (String)request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
0048a843297a remove Dispatcher
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
307 pathInfo = (String)request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
308
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
309 if (servletPath == null && pathInfo == null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
310 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
311 servletPath = request.getServletPath();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
312 pathInfo = request.getPathInfo();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
313 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
314 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
315 else
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
316 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
317 servletPath = request.getServletPath();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
318 pathInfo = request.getPathInfo();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
319 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
320
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
321 String pathInContext=URIUtil.addPaths(servletPath,pathInfo);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
322 return getResource(pathInContext);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
323 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
324
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
325
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
326 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
327 public String[] getWelcomeFiles()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
328 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
329 return _welcomeFiles;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
330 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
331
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
332 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
333 public void setWelcomeFiles(String[] welcomeFiles)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
334 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
335 _welcomeFiles=welcomeFiles;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
336 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
337
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
338 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
339 protected Resource getWelcome(Resource directory) throws MalformedURLException, IOException
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
340 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
341 for (int i=0;i<_welcomeFiles.length;i++)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
342 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
343 Resource welcome=directory.addPath(_welcomeFiles[i]);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
344 if (welcome.exists() && !welcome.isDirectory())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
345 return welcome;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
346 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
347
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
348 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
349 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
350
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
351 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
352 /*
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
353 * @see org.eclipse.jetty.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
354 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
355 public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
356 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
357 if (baseRequest.isHandled())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
358 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
359
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
360 boolean skipContentBody = false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
361
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
362 if(!HttpMethods.GET.equals(request.getMethod()))
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
363 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
364 if(!HttpMethods.HEAD.equals(request.getMethod()))
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
365 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
366 //try another handler
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
367 super.handle(target, baseRequest, request, response);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
368 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
369 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
370 skipContentBody = true;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
371 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
372
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
373 Resource resource = getResource(request);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
374
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
375 if (resource==null || !resource.exists())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
376 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
377 if (target.endsWith("/jetty-dir.css"))
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
378 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
379 resource = getStylesheet();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
380 if (resource==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
381 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
382 response.setContentType("text/css");
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
383 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
384 else
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
385 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
386 //no resource - try other handlers
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
387 super.handle(target, baseRequest, request, response);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
388 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
389 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
390 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
391
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
392 if (!_aliases && resource.getAlias()!=null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
393 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
394 LOG.info(resource+" aliased to "+resource.getAlias());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
395 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
396 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
397
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
398 // We are going to serve something
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
399 baseRequest.setHandled(true);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
400
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
401 if (resource.isDirectory())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
402 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
403 if (!request.getPathInfo().endsWith(URIUtil.SLASH))
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
404 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
405 response.sendRedirect(response.encodeRedirectURL(URIUtil.addPaths(request.getRequestURI(),URIUtil.SLASH)));
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
406 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
407 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
408
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
409 Resource welcome=getWelcome(resource);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
410 if (welcome!=null && welcome.exists())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
411 resource=welcome;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
412 else
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
413 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
414 doDirectory(request,response,resource);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
415 baseRequest.setHandled(true);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
416 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
417 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
418 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
419
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
420 // set some headers
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
421 long last_modified=resource.lastModified();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
422 if (last_modified>0)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
423 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
424 long if_modified=request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
425 if (if_modified>0 && last_modified/1000<=if_modified/1000)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
426 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
427 response.setStatus(HttpStatus.NOT_MODIFIED_304);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
428 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
429 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
430 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
431
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
432 Buffer mime=_mimeTypes.getMimeByExtension(resource.toString());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
433 if (mime==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
434 mime=_mimeTypes.getMimeByExtension(request.getPathInfo());
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
435
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
436 // set the headers
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
437 doResponseHeaders(response,resource,mime!=null?mime.toString():null);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
438 response.setDateHeader(HttpHeaders.LAST_MODIFIED,last_modified);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
439
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
440 if(skipContentBody)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
441 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
442 // Send the content
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
443 OutputStream out =null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
444 try {out = response.getOutputStream();}
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
445 catch(IllegalStateException e) {out = new WriterOutputStream(response.getWriter());}
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
446
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
447 // See if a short direct method can be used?
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
448 if (out instanceof AbstractHttpConnection.Output)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
449 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
450 // TODO file mapped buffers
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
451 ((AbstractHttpConnection.Output)out).sendContent(resource.getInputStream());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
452 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
453 else
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
454 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
455 // Write content normally
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
456 resource.writeTo(out,0,resource.length());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
457 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
458 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
459
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
460 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
461 protected void doDirectory(HttpServletRequest request,HttpServletResponse response, Resource resource)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
462 throws IOException
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
463 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
464 if (_directory)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
465 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
466 String listing = resource.getListHTML(request.getRequestURI(),request.getPathInfo().lastIndexOf("/") > 0);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
467 response.setContentType("text/html; charset=UTF-8");
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
468 response.getWriter().println(listing);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
469 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
470 else
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
471 response.sendError(HttpStatus.FORBIDDEN_403);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
472 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
473
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
474 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
475 /** Set the response headers.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
476 * This method is called to set the response headers such as content type and content length.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
477 * May be extended to add additional headers.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
478 * @param response
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
479 * @param resource
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
480 * @param mimeType
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
481 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
482 protected void doResponseHeaders(HttpServletResponse response, Resource resource, String mimeType)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
483 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
484 if (mimeType!=null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
485 response.setContentType(mimeType);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
486
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
487 long length=resource.length();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
488
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
489 if (response instanceof Response)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
490 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
491 HttpFields fields = ((Response)response).getHttpFields();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
492
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
493 if (length>0)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
494 fields.putLongField(HttpHeaders.CONTENT_LENGTH_BUFFER,length);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
495
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
496 if (_cacheControl!=null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
497 fields.put(HttpHeaders.CACHE_CONTROL_BUFFER,_cacheControl);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
498 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
499 else
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
500 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
501 if (length>0)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
502 response.setHeader(HttpHeaders.CONTENT_LENGTH,Long.toString(length));
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
503
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
504 if (_cacheControl!=null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
505 response.setHeader(HttpHeaders.CACHE_CONTROL,_cacheControl.toString());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
506 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
507
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
508 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
509 }