annotate src/org/eclipse/jetty/server/handler/ResourceHandler.java @ 808:b3176fd168bf

replace use of jetty.util.B64Code with java.util.Base64
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 08 Sep 2016 16:13:27 -0600
parents fc3e366caa51
children 8e9db0bbf4f9
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;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 import org.eclipse.jetty.server.Dispatcher;
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;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 import org.eclipse.jetty.util.log.Log;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 import org.eclipse.jetty.util.log.Logger;
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 {
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
61 private static final Logger LOG = Log.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;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
72 boolean _etags;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
74 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
75 public ResourceHandler()
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
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
78 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
79
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
80 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
81 public MimeTypes getMimeTypes()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
82 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
83 return _mimeTypes;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
84 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
85
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
86 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
87 public void setMimeTypes(MimeTypes mimeTypes)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
88 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
89 _mimeTypes = mimeTypes;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
90 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91
805
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 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
94 * @return True if resource aliases are allowed.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
95 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
96 public boolean isAliases()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
97 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
98 return _aliases;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
99 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
100
805
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 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
103 * 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
104 * Allowing aliases can significantly increase security vulnerabilities.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
105 * If this handler is deployed inside a ContextHandler, then the
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
106 * {@link ContextHandler#isAliases()} takes precedent.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
107 * @param aliases True if aliases are supported.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
108 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
109 public void setAliases(boolean aliases)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
110 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
111 _aliases = aliases;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
112 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
113
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
114 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
115 /** Get the directory option.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
116 * @return true if directories are listed.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
117 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
118 public boolean isDirectoriesListed()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
119 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
120 return _directory;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
121 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
123 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
124 /** Set the directory.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
125 * @param directory true if directories are listed.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
126 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
127 public void setDirectoriesListed(boolean directory)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
128 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
129 _directory = directory;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
130 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
132 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
133 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
134 * @return True if ETag processing is done
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 public boolean isEtags()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
137 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
138 return _etags;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
139 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
141 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
142 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
143 * @param etags True if ETag processing is done
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
144 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
145 public void setEtags(boolean etags)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
146 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
147 _etags = etags;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
148 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
149
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
150 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
151 @Override
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
152 public void doStart()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
153 throws Exception
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
154 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
155 Context scontext = ContextHandler.getCurrentContext();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
156 _context = (scontext==null?null:scontext.getContextHandler());
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
157
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
158 if (_context!=null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
159 _aliases=_context.isAliases();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
160
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
161 if (!_aliases && !FileResource.getCheckAliases())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
162 throw new IllegalStateException("Alias checking disabled");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
163
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
164 super.doStart();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
165 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
166
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
167 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
168 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
169 * @return Returns the resourceBase.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
170 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
171 public Resource getBaseResource()
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 if (_baseResource==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
174 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
175 return _baseResource;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
176 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
178 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
179 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
180 * @return Returns the base resource as a string.
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 public String getResourceBase()
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 if (_baseResource==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
185 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
186 return _baseResource.toString();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
187 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
188
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
189
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
190 /* ------------------------------------------------------------ */
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 * @param base The resourceBase to set.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
193 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
194 public void setBaseResource(Resource base)
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 _baseResource=base;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
197 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
198
805
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 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
201 * @param resourceBase The base resource as a string.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
202 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
203 public void setResourceBase(String resourceBase)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
204 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
205 try
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
206 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
207 setBaseResource(Resource.newResource(resourceBase));
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
208 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
209 catch (Exception e)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
210 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
211 LOG.warn(e.toString());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
212 LOG.debug(e);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
213 throw new IllegalArgumentException(resourceBase);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
214 }
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
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 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
219 * @return Returns the stylesheet as a Resource.
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 public Resource getStylesheet()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
222 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
223 if(_stylesheet != null)
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 return _stylesheet;
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 else
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
228 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
229 if(_defaultStylesheet == null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
230 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
231 try
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
232 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
233 _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
234 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
235 catch(IOException e)
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(e.toString());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
238 LOG.debug(e);
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 return _defaultStylesheet;
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 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
244
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
245 /* ------------------------------------------------------------ */
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 * @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
248 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
249 public void setStylesheet(String stylesheet)
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 try
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 _stylesheet = Resource.newResource(stylesheet);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
254 if(!_stylesheet.exists())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
255 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
256 LOG.warn("unable to find custom stylesheet: " + stylesheet);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
257 _stylesheet = null;
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 catch(Exception e)
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 LOG.warn(e.toString());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
263 LOG.debug(e);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
264 throw new IllegalArgumentException(stylesheet.toString());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
265 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
266 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
267
805
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 * @return the cacheControl header to set on all static content.
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 public String getCacheControl()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
273 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
274 return _cacheControl.toString();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
275 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
276
805
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 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
279 * @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
280 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
281 public void setCacheControl(String cacheControl)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
282 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
283 _cacheControl=cacheControl==null?null:new ByteArrayBuffer(cacheControl);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
284 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
285
805
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 /*
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
288 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
289 public Resource getResource(String path) throws MalformedURLException
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
290 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
291 if (path==null || !path.startsWith("/"))
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
292 throw new MalformedURLException(path);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
293
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
294 Resource base = _baseResource;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
295 if (base==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
296 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
297 if (_context==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
298 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
299 base=_context.getBaseResource();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
300 if (base==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
301 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
302 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
303
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
304 try
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
305 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
306 path=URIUtil.canonicalPath(path);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
307 return base.addPath(path);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
308 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
309 catch(Exception e)
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 LOG.ignore(e);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
312 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
313
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
314 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
315 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
316
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
317 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
318 protected Resource getResource(HttpServletRequest request) throws MalformedURLException
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 String servletPath;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
321 String pathInfo;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
322 Boolean included = request.getAttribute(Dispatcher.INCLUDE_REQUEST_URI) != null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
323 if (included != null && included.booleanValue())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
324 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
325 servletPath = (String)request.getAttribute(Dispatcher.INCLUDE_SERVLET_PATH);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
326 pathInfo = (String)request.getAttribute(Dispatcher.INCLUDE_PATH_INFO);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
327
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
328 if (servletPath == null && pathInfo == null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
329 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
330 servletPath = request.getServletPath();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
331 pathInfo = request.getPathInfo();
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 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
334 else
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
335 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
336 servletPath = request.getServletPath();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
337 pathInfo = request.getPathInfo();
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
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
340 String pathInContext=URIUtil.addPaths(servletPath,pathInfo);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
341 return getResource(pathInContext);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
342 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
343
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
344
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
345 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
346 public String[] getWelcomeFiles()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
347 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
348 return _welcomeFiles;
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 public void setWelcomeFiles(String[] welcomeFiles)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
353 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
354 _welcomeFiles=welcomeFiles;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
355 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
356
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
357 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
358 protected Resource getWelcome(Resource directory) throws MalformedURLException, IOException
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
359 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
360 for (int i=0;i<_welcomeFiles.length;i++)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
361 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
362 Resource welcome=directory.addPath(_welcomeFiles[i]);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
363 if (welcome.exists() && !welcome.isDirectory())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
364 return welcome;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
365 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
366
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
367 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
368 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
369
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
370 /* ------------------------------------------------------------ */
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 * @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
373 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
374 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
375 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
376 if (baseRequest.isHandled())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
377 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
378
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
379 boolean skipContentBody = false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
380
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
381 if(!HttpMethods.GET.equals(request.getMethod()))
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
382 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
383 if(!HttpMethods.HEAD.equals(request.getMethod()))
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
384 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
385 //try another handler
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
386 super.handle(target, baseRequest, request, response);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
387 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
388 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
389 skipContentBody = true;
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 Resource resource = getResource(request);
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 if (resource==null || !resource.exists())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
395 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
396 if (target.endsWith("/jetty-dir.css"))
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
397 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
398 resource = getStylesheet();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
399 if (resource==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
400 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
401 response.setContentType("text/css");
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 else
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 //no resource - try other handlers
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
406 super.handle(target, baseRequest, request, response);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
407 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
408 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
409 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
410
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
411 if (!_aliases && resource.getAlias()!=null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
412 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
413 LOG.info(resource+" aliased to "+resource.getAlias());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
414 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
415 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
416
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
417 // We are going to serve something
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
418 baseRequest.setHandled(true);
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 if (resource.isDirectory())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
421 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
422 if (!request.getPathInfo().endsWith(URIUtil.SLASH))
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 response.sendRedirect(response.encodeRedirectURL(URIUtil.addPaths(request.getRequestURI(),URIUtil.SLASH)));
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
425 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
426 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
427
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
428 Resource welcome=getWelcome(resource);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
429 if (welcome!=null && welcome.exists())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
430 resource=welcome;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
431 else
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
432 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
433 doDirectory(request,response,resource);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
434 baseRequest.setHandled(true);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
435 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
436 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
437 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
438
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
439 // set some headers
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
440 long last_modified=resource.lastModified();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
441 String etag=null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
442 if (_etags)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
443 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
444 // simple handling of only a single etag
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
445 String ifnm = request.getHeader(HttpHeaders.IF_NONE_MATCH);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
446 etag=resource.getWeakETag();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
447 if (ifnm!=null && resource!=null && ifnm.equals(etag))
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
448 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
449 response.setStatus(HttpStatus.NOT_MODIFIED_304);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
450 baseRequest.getResponse().getHttpFields().put(HttpHeaders.ETAG_BUFFER,etag);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
451 return;
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 }
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
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
456 if (last_modified>0)
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 long if_modified=request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
459 if (if_modified>0 && last_modified/1000<=if_modified/1000)
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 response.setStatus(HttpStatus.NOT_MODIFIED_304);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
462 return;
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
465
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
466 Buffer mime=_mimeTypes.getMimeByExtension(resource.toString());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
467 if (mime==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
468 mime=_mimeTypes.getMimeByExtension(request.getPathInfo());
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
469
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
470 // set the headers
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
471 doResponseHeaders(response,resource,mime!=null?mime.toString():null);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
472 response.setDateHeader(HttpHeaders.LAST_MODIFIED,last_modified);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
473 if (_etags)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
474 baseRequest.getResponse().getHttpFields().put(HttpHeaders.ETAG_BUFFER,etag);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
475
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
476 if(skipContentBody)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
477 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
478 // Send the content
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
479 OutputStream out =null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
480 try {out = response.getOutputStream();}
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
481 catch(IllegalStateException e) {out = new WriterOutputStream(response.getWriter());}
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
482
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
483 // See if a short direct method can be used?
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
484 if (out instanceof AbstractHttpConnection.Output)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
485 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
486 // TODO file mapped buffers
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
487 ((AbstractHttpConnection.Output)out).sendContent(resource.getInputStream());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
488 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
489 else
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 // Write content normally
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
492 resource.writeTo(out,0,resource.length());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
493 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
494 }
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 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
497 protected void doDirectory(HttpServletRequest request,HttpServletResponse response, Resource resource)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
498 throws IOException
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
499 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
500 if (_directory)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
501 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
502 String listing = resource.getListHTML(request.getRequestURI(),request.getPathInfo().lastIndexOf("/") > 0);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
503 response.setContentType("text/html; charset=UTF-8");
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
504 response.getWriter().println(listing);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
505 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
506 else
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
507 response.sendError(HttpStatus.FORBIDDEN_403);
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
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
510 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
511 /** Set the response headers.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
512 * 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
513 * May be extended to add additional headers.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
514 * @param response
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
515 * @param resource
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
516 * @param mimeType
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
517 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
518 protected void doResponseHeaders(HttpServletResponse response, Resource resource, String mimeType)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
519 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
520 if (mimeType!=null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
521 response.setContentType(mimeType);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
522
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
523 long length=resource.length();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
524
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
525 if (response instanceof Response)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
526 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
527 HttpFields fields = ((Response)response).getHttpFields();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
528
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
529 if (length>0)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
530 fields.putLongField(HttpHeaders.CONTENT_LENGTH_BUFFER,length);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
531
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
532 if (_cacheControl!=null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
533 fields.put(HttpHeaders.CACHE_CONTROL_BUFFER,_cacheControl);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
534 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
535 else
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
536 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
537 if (length>0)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
538 response.setHeader(HttpHeaders.CONTENT_LENGTH,Long.toString(length));
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
539
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
540 if (_cacheControl!=null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
541 response.setHeader(HttpHeaders.CACHE_CONTROL,_cacheControl.toString());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
542 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
543
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
544 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
545 }