annotate src/org/eclipse/jetty/server/handler/ResourceHandler.java @ 1044:dd71a59fcf72

remove buffer marking
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 04 Nov 2016 02:26:54 -0600
parents 921c25a05eaa
children
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.HttpServletResponse;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 import org.eclipse.jetty.http.HttpFields;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 import org.eclipse.jetty.http.HttpHeaders;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 import org.eclipse.jetty.http.HttpMethods;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 import org.eclipse.jetty.http.HttpStatus;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 import org.eclipse.jetty.http.MimeTypes;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 import org.eclipse.jetty.io.WriterOutputStream;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 import org.eclipse.jetty.server.AbstractHttpConnection;
822
0048a843297a remove Dispatcher
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
35 import javax.servlet.RequestDispatcher;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 import org.eclipse.jetty.server.Request;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 import org.eclipse.jetty.server.Response;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 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
39 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 805
diff changeset
40 import org.slf4j.LoggerFactory;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 import org.eclipse.jetty.util.resource.FileResource;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 import org.eclipse.jetty.util.resource.Resource;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 /* ------------------------------------------------------------ */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 /** Resource Handler.
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 * 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
49 * No caching is done.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 * 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
51 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 * @org.apache.xbean.XBean
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 */
992
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
55 public final class ResourceHandler extends HandlerWrapper
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 {
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 805
diff changeset
57 private static final Logger LOG = LoggerFactory.getLogger(ResourceHandler.class);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
59 Resource _baseResource;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
60 Resource _defaultStylesheet;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
61 Resource _stylesheet;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
62 String[] _welcomeFiles={"index.html"};
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
63 MimeTypes _mimeTypes = new MimeTypes();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
64 boolean _aliases;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
65 boolean _directory;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
67 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
68 public ResourceHandler()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
69 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
70
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
71 }
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 MimeTypes getMimeTypes()
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 return _mimeTypes;
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 void setMimeTypes(MimeTypes mimeTypes)
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 _mimeTypes = 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 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
87 * @return True if resource aliases are allowed.
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 public boolean isAliases()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
90 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
91 return _aliases;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
92 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93
805
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 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
96 * 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
97 * Allowing aliases can significantly increase security vulnerabilities.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
98 * If this handler is deployed inside a ContextHandler, then the
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
99 * {@link ContextHandler#isAliases()} takes precedent.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
100 * @param aliases True if aliases are supported.
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 public void setAliases(boolean aliases)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
103 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
104 _aliases = aliases;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
105 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
106
805
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 /** Get the directory option.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
109 * @return true if directories are listed.
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 public boolean isDirectoriesListed()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
112 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
113 return _directory;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
114 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
115
805
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 /** Set the directory.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
118 * @param directory true if directories are listed.
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 public void setDirectoriesListed(boolean directory)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
121 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
122 _directory = directory;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
123 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
124
805
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 @Override
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
127 public void doStart()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
128 throws Exception
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
129 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
130 if (!_aliases && !FileResource.getCheckAliases())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
131 throw new IllegalStateException("Alias checking disabled");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
132
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
133 super.doStart();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
134 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
135
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
136 /* ------------------------------------------------------------ */
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 Returns the resourceBase.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
139 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
140 public Resource getBaseResource()
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 if (_baseResource==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
143 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
144 return _baseResource;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
145 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
146
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
147 /* ------------------------------------------------------------ */
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 * @return Returns the base resource as a string.
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 public String getResourceBase()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
152 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
153 if (_baseResource==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
154 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
155 return _baseResource.toString();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
156 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
157
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 * @param base The resourceBase to set.
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 void setBaseResource(Resource base)
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 _baseResource=base;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
166 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
167
805
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 /**
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
170 * @param resourceBase The base resource as a string.
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 public void setResourceBase(String resourceBase)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
173 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
174 try
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
175 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
176 setBaseResource(Resource.newResource(resourceBase));
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
177 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
178 catch (Exception e)
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 LOG.warn(e.toString());
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 805
diff changeset
181 LOG.debug("",e);
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
182 throw new IllegalArgumentException(resourceBase);
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 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
185
994
4e9d373bf6e9 remove ContextHandler.Context
Franklin Schmidt <fschmidt@gmail.com>
parents: 992
diff changeset
186 private Resource getStylesheet()
805
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 if(_stylesheet != null)
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 return _stylesheet;
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 else
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 if(_defaultStylesheet == null)
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 try
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 _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
199 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
200 catch(IOException e)
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 LOG.warn(e.toString());
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 805
diff changeset
203 LOG.debug("",e);
805
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 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
206 return _defaultStylesheet;
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 }
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 /* ------------------------------------------------------------ */
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 * @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
213 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
214 public void setStylesheet(String stylesheet)
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 try
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 _stylesheet = Resource.newResource(stylesheet);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
219 if(!_stylesheet.exists())
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 LOG.warn("unable to find custom stylesheet: " + stylesheet);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
222 _stylesheet = null;
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 catch(Exception e)
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 LOG.warn(e.toString());
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 805
diff changeset
228 LOG.debug("",e);
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
229 throw new IllegalArgumentException(stylesheet.toString());
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
232
997
7d28be82ab75 simplify Request
Franklin Schmidt <fschmidt@gmail.com>
parents: 994
diff changeset
233 private Resource getResource(Request request) throws MalformedURLException
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
234 {
997
7d28be82ab75 simplify Request
Franklin Schmidt <fschmidt@gmail.com>
parents: 994
diff changeset
235 String path = request.getPathInfo();
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
236 if (path==null || !path.startsWith("/"))
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
237 throw new MalformedURLException(path);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
238
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
239 Resource base = _baseResource;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
240 if (base==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
241 {
994
4e9d373bf6e9 remove ContextHandler.Context
Franklin Schmidt <fschmidt@gmail.com>
parents: 992
diff changeset
242 ContextHandler ch = request._contextHandler;
4e9d373bf6e9 remove ContextHandler.Context
Franklin Schmidt <fschmidt@gmail.com>
parents: 992
diff changeset
243 if (ch==null)
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
244 return null;
994
4e9d373bf6e9 remove ContextHandler.Context
Franklin Schmidt <fschmidt@gmail.com>
parents: 992
diff changeset
245 base = ch.getBaseResource();
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
246 if (base==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
247 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
248 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
249
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
250 try
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
251 {
992
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
252 path = URIUtil.canonicalPath(path);
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
253 return base.addPath(path);
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 catch(Exception e)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
256 {
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 805
diff changeset
257 LOG.trace("",e);
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
258 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
259
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
260 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
261 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
262
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
263
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
264 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
265 public String[] getWelcomeFiles()
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
266 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
267 return _welcomeFiles;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
268 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
269
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
270 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
271 public void setWelcomeFiles(String[] welcomeFiles)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
272 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
273 _welcomeFiles=welcomeFiles;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
274 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
275
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
276 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
277 protected Resource getWelcome(Resource directory) throws MalformedURLException, IOException
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 for (int i=0;i<_welcomeFiles.length;i++)
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 Resource welcome=directory.addPath(_welcomeFiles[i]);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
282 if (welcome.exists() && !welcome.isDirectory())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
283 return welcome;
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 return null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
287 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
288
1000
32d4b569567c simplify handle()
Franklin Schmidt <fschmidt@gmail.com>
parents: 997
diff changeset
289 @Override
32d4b569567c simplify handle()
Franklin Schmidt <fschmidt@gmail.com>
parents: 997
diff changeset
290 public void handle(String target, Request request, HttpServletResponse response) throws IOException, ServletException
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
291 {
1000
32d4b569567c simplify handle()
Franklin Schmidt <fschmidt@gmail.com>
parents: 997
diff changeset
292 if (request.isHandled())
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
293 return;
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 boolean skipContentBody = false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
296
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
297 if(!HttpMethods.GET.equals(request.getMethod()))
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 if(!HttpMethods.HEAD.equals(request.getMethod()))
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 //try another handler
1000
32d4b569567c simplify handle()
Franklin Schmidt <fschmidt@gmail.com>
parents: 997
diff changeset
302 super.handle(target, request, response);
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
303 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
304 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
305 skipContentBody = true;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
306 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
307
1000
32d4b569567c simplify handle()
Franklin Schmidt <fschmidt@gmail.com>
parents: 997
diff changeset
308 Resource resource = getResource(request);
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
309
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
310 if (resource==null || !resource.exists())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
311 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
312 if (target.endsWith("/jetty-dir.css"))
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 resource = getStylesheet();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
315 if (resource==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
316 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
317 response.setContentType("text/css");
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
318 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
319 else
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 //no resource - try other handlers
1000
32d4b569567c simplify handle()
Franklin Schmidt <fschmidt@gmail.com>
parents: 997
diff changeset
322 super.handle(target, request, response);
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
323 return;
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 }
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 if (!_aliases && resource.getAlias()!=null)
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 LOG.info(resource+" aliased to "+resource.getAlias());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
330 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
331 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
332
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
333 // We are going to serve something
1000
32d4b569567c simplify handle()
Franklin Schmidt <fschmidt@gmail.com>
parents: 997
diff changeset
334 request.setHandled(true);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
335
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
336 if (resource.isDirectory())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
337 {
1013
6939226e0ac4 simplify URIUtil
Franklin Schmidt <fschmidt@gmail.com>
parents: 1000
diff changeset
338 if (!request.getPathInfo().endsWith("/"))
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
339 {
1013
6939226e0ac4 simplify URIUtil
Franklin Schmidt <fschmidt@gmail.com>
parents: 1000
diff changeset
340 response.sendRedirect(response.encodeRedirectURL(URIUtil.addPaths(request.getRequestURI(),"/")));
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
341 return;
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
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
344 Resource welcome=getWelcome(resource);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
345 if (welcome!=null && welcome.exists())
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
346 resource=welcome;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
347 else
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
348 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
349 doDirectory(request,response,resource);
1000
32d4b569567c simplify handle()
Franklin Schmidt <fschmidt@gmail.com>
parents: 997
diff changeset
350 request.setHandled(true);
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
351 return;
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
354
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
355 // set some headers
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
356 long last_modified=resource.lastModified();
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
357 if (last_modified>0)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
358 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
359 long if_modified=request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
360 if (if_modified>0 && last_modified/1000<=if_modified/1000)
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 response.setStatus(HttpStatus.NOT_MODIFIED_304);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
363 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
364 }
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
1023
27f3dc761452 MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1022
diff changeset
367 String mime = _mimeTypes.getMimeByExtension(resource.toString());
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
368 if (mime==null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
369 mime=_mimeTypes.getMimeByExtension(request.getPathInfo());
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
370
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
371 // set the headers
1023
27f3dc761452 MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1022
diff changeset
372 doResponseHeaders(response,resource,mime);
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
373 response.setDateHeader(HttpHeaders.LAST_MODIFIED,last_modified);
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(skipContentBody)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
376 return;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
377 // Send the content
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
378 OutputStream out =null;
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
379 try {out = response.getOutputStream();}
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
380 catch(IllegalStateException e) {out = new WriterOutputStream(response.getWriter());}
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
381
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
382 // See if a short direct method can be used?
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
383 if (out instanceof AbstractHttpConnection.Output)
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 // TODO file mapped buffers
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
386 ((AbstractHttpConnection.Output)out).sendContent(resource.getInputStream());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
387 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
388 else
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 // Write content normally
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
391 resource.writeTo(out,0,resource.length());
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
392 }
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
393 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
394
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
395 /* ------------------------------------------------------------ */
1000
32d4b569567c simplify handle()
Franklin Schmidt <fschmidt@gmail.com>
parents: 997
diff changeset
396 protected void doDirectory(Request request,HttpServletResponse response, Resource resource)
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
397 throws IOException
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
398 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
399 if (_directory)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
400 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
401 String listing = resource.getListHTML(request.getRequestURI(),request.getPathInfo().lastIndexOf("/") > 0);
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
402 response.setContentType("text/html; charset=UTF-8");
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
403 response.getWriter().println(listing);
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 else
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
406 response.sendError(HttpStatus.FORBIDDEN_403);
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 /* ------------------------------------------------------------ */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
410 /** Set the response headers.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
411 * 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
412 * May be extended to add additional headers.
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
413 * @param response
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
414 * @param resource
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
415 * @param mimeType
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
416 */
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
417 protected void doResponseHeaders(HttpServletResponse response, Resource resource, String mimeType)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
418 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
419 if (mimeType!=null)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
420 response.setContentType(mimeType);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
421
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
422 long length=resource.length();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
423
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
424 if (response instanceof Response)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
425 {
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
426 HttpFields fields = ((Response)response).getHttpFields();
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 if (length>0)
1022
3718afd99988 HttpHeaders uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1013
diff changeset
429 fields.putLongField(HttpHeaders.CONTENT_LENGTH,length);
805
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
430 }
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 if (length>0)
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
434 response.setHeader(HttpHeaders.CONTENT_LENGTH,Long.toString(length));
fc3e366caa51 add jetty-dir.css
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
435 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
436
805
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 }