Mercurial Hosting > luan
annotate src/org/eclipse/jetty/server/Response.java @ 939:8db5996c8c89
remove AsyncContinuation
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 10 Oct 2016 00:50:06 -0600 |
parents | cab5830e1ab0 |
children | 5ee36654b383 |
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; |
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.PrintWriter; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 import java.util.Collection; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 import java.util.ArrayList; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 import java.util.Collections; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 import java.util.EnumSet; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 import java.util.Enumeration; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 import java.util.Locale; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 import javax.servlet.RequestDispatcher; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
31 import javax.servlet.ServletOutputStream; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
32 import javax.servlet.SessionTrackingMode; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 import javax.servlet.http.Cookie; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 import javax.servlet.http.HttpServletResponse; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
35 import javax.servlet.http.HttpSession; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
37 import org.eclipse.jetty.http.HttpCookie; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 import org.eclipse.jetty.http.HttpFields; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
39 import org.eclipse.jetty.http.HttpGenerator; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 import org.eclipse.jetty.http.HttpHeaderValues; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 import org.eclipse.jetty.http.HttpHeaders; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
42 import org.eclipse.jetty.http.HttpSchemes; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
43 import org.eclipse.jetty.http.HttpStatus; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 import org.eclipse.jetty.http.HttpURI; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
45 import org.eclipse.jetty.http.HttpVersions; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
46 import org.eclipse.jetty.http.MimeTypes; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
47 import org.eclipse.jetty.io.BufferCache.CachedBuffer; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
48 import org.eclipse.jetty.server.handler.ContextHandler; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
49 import org.eclipse.jetty.util.ByteArrayISO8859Writer; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
50 import org.eclipse.jetty.util.QuotedStringTokenizer; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
51 import org.eclipse.jetty.util.StringUtil; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
52 import org.eclipse.jetty.util.URIUtil; |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
813
diff
changeset
|
53 import org.slf4j.Logger; |
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
813
diff
changeset
|
54 import org.slf4j.LoggerFactory; |
802
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 /** Response. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
57 * <p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
58 * Implements {@link javax.servlet.http.HttpServletResponse} from the <code>javax.servlet.http</code> package. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
59 * </p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
60 */ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
61 public class Response implements HttpServletResponse |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
62 { |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
813
diff
changeset
|
63 private static final Logger LOG = LoggerFactory.getLogger(Response.class); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
64 |
813 | 65 |
66 public static final int | |
67 NONE=0, | |
68 STREAM=1, | |
69 WRITER=2; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
70 |
813 | 71 /** |
72 * If a header name starts with this string, the header (stripped of the prefix) | |
73 * can be set during include using only {@link #setHeader(String, String)} or | |
74 * {@link #addHeader(String, String)}. | |
75 */ | |
76 public final static String SET_INCLUDE_HEADER_PREFIX = "org.eclipse.jetty.server.include."; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
77 |
813 | 78 /** |
79 * If this string is found within the comment of a cookie added with {@link #addCookie(Cookie)}, then the cookie | |
80 * will be set as HTTP ONLY. | |
81 */ | |
82 public final static String HTTP_ONLY_COMMENT="__HTTP_ONLY__"; | |
83 | |
84 | |
85 /* ------------------------------------------------------------ */ | |
86 public static Response getResponse(HttpServletResponse response) | |
87 { | |
88 if (response instanceof Response) | |
89 return (Response)response; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
90 |
813 | 91 return AbstractHttpConnection.getCurrentConnection().getResponse(); |
92 } | |
93 | |
94 private final AbstractHttpConnection _connection; | |
95 private int _status=SC_OK; | |
96 private String _reason; | |
97 private Locale _locale; | |
98 private String _mimeType; | |
99 private CachedBuffer _cachedMimeType; | |
100 private String _characterEncoding; | |
101 private boolean _explicitEncoding; | |
102 private String _contentType; | |
103 private volatile int _outputState; | |
104 private PrintWriter _writer; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
105 |
813 | 106 /* ------------------------------------------------------------ */ |
107 /** | |
108 * | |
109 */ | |
110 public Response(AbstractHttpConnection connection) | |
111 { | |
112 _connection=connection; | |
113 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
114 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
115 |
813 | 116 /* ------------------------------------------------------------ */ |
117 /* | |
118 * @see javax.servlet.ServletResponse#reset() | |
119 */ | |
120 protected void recycle() | |
121 { | |
122 _status=SC_OK; | |
123 _reason=null; | |
124 _locale=null; | |
125 _mimeType=null; | |
126 _cachedMimeType=null; | |
127 _characterEncoding=null; | |
128 _explicitEncoding=false; | |
129 _contentType=null; | |
130 _writer=null; | |
131 _outputState=NONE; | |
132 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
133 |
813 | 134 /* ------------------------------------------------------------ */ |
135 /* | |
136 * @see javax.servlet.http.HttpServletResponse#addCookie(javax.servlet.http.Cookie) | |
137 */ | |
138 public void addCookie(HttpCookie cookie) | |
139 { | |
140 _connection.getResponseFields().addSetCookie(cookie); | |
141 } | |
142 | |
143 /* ------------------------------------------------------------ */ | |
144 /* | |
145 * @see javax.servlet.http.HttpServletResponse#addCookie(javax.servlet.http.Cookie) | |
146 */ | |
147 public void addCookie(Cookie cookie) | |
148 { | |
149 String comment=cookie.getComment(); | |
150 boolean http_only=false; | |
151 | |
152 if (comment!=null) | |
153 { | |
154 int i=comment.indexOf(HTTP_ONLY_COMMENT); | |
155 if (i>=0) | |
156 { | |
157 http_only=true; | |
158 comment=comment.replace(HTTP_ONLY_COMMENT,"").trim(); | |
159 if (comment.length()==0) | |
160 comment=null; | |
161 } | |
162 } | |
163 _connection.getResponseFields().addSetCookie(cookie.getName(), | |
164 cookie.getValue(), | |
165 cookie.getDomain(), | |
166 cookie.getPath(), | |
167 cookie.getMaxAge(), | |
168 comment, | |
169 cookie.getSecure(), | |
170 http_only || cookie.isHttpOnly(), | |
171 cookie.getVersion()); | |
172 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
173 |
813 | 174 /* ------------------------------------------------------------ */ |
175 /* | |
176 * @see javax.servlet.http.HttpServletResponse#containsHeader(java.lang.String) | |
177 */ | |
178 public boolean containsHeader(String name) | |
179 { | |
180 return _connection.getResponseFields().containsKey(name); | |
181 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
182 |
813 | 183 /* ------------------------------------------------------------ */ |
184 /* | |
185 * @see javax.servlet.http.HttpServletResponse#encodeURL(java.lang.String) | |
186 */ | |
187 public String encodeURL(String url) | |
188 { | |
809
09d518d313b7
remove SessionManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
189 throw new UnsupportedOperationException(); |
813 | 190 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
191 |
813 | 192 /* ------------------------------------------------------------ */ |
193 /** | |
194 * @see javax.servlet.http.HttpServletResponse#encodeRedirectURL(java.lang.String) | |
195 */ | |
196 public String encodeRedirectURL(String url) | |
197 { | |
198 return encodeURL(url); | |
199 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
200 |
813 | 201 /* ------------------------------------------------------------ */ |
202 @Deprecated | |
203 public String encodeUrl(String url) | |
204 { | |
205 return encodeURL(url); | |
206 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
207 |
813 | 208 /* ------------------------------------------------------------ */ |
209 @Deprecated | |
210 public String encodeRedirectUrl(String url) | |
211 { | |
212 return encodeRedirectURL(url); | |
213 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
214 |
813 | 215 /* ------------------------------------------------------------ */ |
216 /* | |
217 * @see javax.servlet.http.HttpServletResponse#sendError(int, java.lang.String) | |
218 */ | |
219 public void sendError(int code, String message) throws IOException | |
220 { | |
221 if (_connection.isIncluding()) | |
222 return; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
223 |
813 | 224 if (isCommitted()) |
225 LOG.warn("Committed before "+code+" "+message); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
226 |
813 | 227 resetBuffer(); |
228 _characterEncoding=null; | |
229 setHeader(HttpHeaders.EXPIRES,null); | |
230 setHeader(HttpHeaders.LAST_MODIFIED,null); | |
231 setHeader(HttpHeaders.CACHE_CONTROL,null); | |
232 setHeader(HttpHeaders.CONTENT_TYPE,null); | |
233 setHeader(HttpHeaders.CONTENT_LENGTH,null); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
234 |
813 | 235 _outputState=NONE; |
236 setStatus(code,message); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
237 |
813 | 238 if (message==null) |
239 message=HttpStatus.getMessage(code); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
240 |
813 | 241 // If we are allowed to have a body |
242 if (code!=SC_NO_CONTENT && | |
243 code!=SC_NOT_MODIFIED && | |
244 code!=SC_PARTIAL_CONTENT && | |
245 code>=SC_OK) | |
246 { | |
247 Request request = _connection.getRequest(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
248 |
911 | 249 setHeader(HttpHeaders.CACHE_CONTROL, "must-revalidate,no-cache,no-store"); |
250 setContentType(MimeTypes.TEXT_HTML_8859_1); | |
251 ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(2048); | |
252 if (message != null) | |
813 | 253 { |
911 | 254 message= StringUtil.replace(message, "&", "&"); |
255 message= StringUtil.replace(message, "<", "<"); | |
256 message= StringUtil.replace(message, ">", ">"); | |
813 | 257 } |
911 | 258 String uri= request.getRequestURI(); |
259 if (uri!=null) | |
813 | 260 { |
911 | 261 uri= StringUtil.replace(uri, "&", "&"); |
262 uri= StringUtil.replace(uri, "<", "<"); | |
263 uri= StringUtil.replace(uri, ">", ">"); | |
264 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
265 |
911 | 266 writer.write("<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=ISO-8859-1\"/>\n"); |
267 writer.write("<title>Error "); | |
268 writer.write(Integer.toString(code)); | |
269 writer.write(' '); | |
270 if (message==null) | |
271 message=HttpStatus.getMessage(code); | |
272 writer.write(message); | |
273 writer.write("</title>\n</head>\n<body>\n<h2>HTTP ERROR: "); | |
274 writer.write(Integer.toString(code)); | |
275 writer.write("</h2>\n<p>Problem accessing "); | |
276 writer.write(uri); | |
277 writer.write(". Reason:\n<pre> "); | |
278 writer.write(message); | |
279 writer.write("</pre>"); | |
280 writer.write("</p>\n<hr /><i><small>Powered by Jetty://</small></i>"); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
281 |
911 | 282 for (int i= 0; i < 20; i++) |
283 writer.write("\n "); | |
284 writer.write("\n</body>\n</html>\n"); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
285 |
911 | 286 writer.flush(); |
287 setContentLength(writer.size()); | |
288 writer.writeTo(getOutputStream()); | |
289 writer.destroy(); | |
813 | 290 } |
291 else if (code!=SC_PARTIAL_CONTENT) | |
292 { | |
293 _connection.getRequestFields().remove(HttpHeaders.CONTENT_TYPE_BUFFER); | |
294 _connection.getRequestFields().remove(HttpHeaders.CONTENT_LENGTH_BUFFER); | |
295 _characterEncoding=null; | |
296 _mimeType=null; | |
297 _cachedMimeType=null; | |
298 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
299 |
813 | 300 complete(); |
301 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
302 |
813 | 303 /* ------------------------------------------------------------ */ |
304 /* | |
305 * @see javax.servlet.http.HttpServletResponse#sendError(int) | |
306 */ | |
307 public void sendError(int sc) throws IOException | |
308 { | |
309 if (sc==102) | |
310 sendProcessing(); | |
311 else | |
312 sendError(sc,null); | |
313 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
314 |
813 | 315 /* ------------------------------------------------------------ */ |
316 /* Send a 102-Processing response. | |
317 * If the connection is a HTTP connection, the version is 1.1 and the | |
318 * request has a Expect header starting with 102, then a 102 response is | |
319 * sent. This indicates that the request still be processed and real response | |
320 * can still be sent. This method is called by sendError if it is passed 102. | |
321 * @see javax.servlet.http.HttpServletResponse#sendError(int) | |
322 */ | |
323 public void sendProcessing() throws IOException | |
324 { | |
325 if (_connection.isExpecting102Processing() && !isCommitted()) | |
326 ((HttpGenerator)_connection.getGenerator()).send1xx(HttpStatus.PROCESSING_102); | |
327 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
328 |
813 | 329 /* ------------------------------------------------------------ */ |
330 /* | |
331 * @see javax.servlet.http.HttpServletResponse#sendRedirect(java.lang.String) | |
332 */ | |
333 public void sendRedirect(String location) throws IOException | |
334 { | |
335 if (_connection.isIncluding()) | |
336 return; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
337 |
813 | 338 if (location==null) |
339 throw new IllegalArgumentException(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
340 |
813 | 341 if (!URIUtil.hasScheme(location)) |
342 { | |
343 StringBuilder buf = _connection.getRequest().getRootURL(); | |
344 if (location.startsWith("/")) | |
345 buf.append(location); | |
346 else | |
347 { | |
348 String path=_connection.getRequest().getRequestURI(); | |
349 String parent=(path.endsWith("/"))?path:URIUtil.parentPath(path); | |
350 location=URIUtil.addPaths(parent,location); | |
351 if(location==null) | |
352 throw new IllegalStateException("path cannot be above root"); | |
353 if (!location.startsWith("/")) | |
354 buf.append('/'); | |
355 buf.append(location); | |
356 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
357 |
813 | 358 location=buf.toString(); |
359 HttpURI uri = new HttpURI(location); | |
360 String path=uri.getDecodedPath(); | |
361 String canonical=URIUtil.canonicalPath(path); | |
362 if (canonical==null) | |
363 throw new IllegalArgumentException(); | |
364 if (!canonical.equals(path)) | |
365 { | |
366 buf = _connection.getRequest().getRootURL(); | |
367 buf.append(URIUtil.encodePath(canonical)); | |
368 String param=uri.getParam(); | |
369 if (param!=null) | |
370 { | |
371 buf.append(';'); | |
372 buf.append(param); | |
373 } | |
374 String query=uri.getQuery(); | |
375 if (query!=null) | |
376 { | |
377 buf.append('?'); | |
378 buf.append(query); | |
379 } | |
380 String fragment=uri.getFragment(); | |
381 if (fragment!=null) | |
382 { | |
383 buf.append('#'); | |
384 buf.append(fragment); | |
385 } | |
386 location=buf.toString(); | |
387 } | |
388 } | |
389 | |
390 resetBuffer(); | |
391 setHeader(HttpHeaders.LOCATION,location); | |
392 setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); | |
393 complete(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
394 |
813 | 395 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
396 |
813 | 397 /* ------------------------------------------------------------ */ |
398 /* | |
399 * @see javax.servlet.http.HttpServletResponse#setDateHeader(java.lang.String, long) | |
400 */ | |
401 public void setDateHeader(String name, long date) | |
402 { | |
403 if (!_connection.isIncluding()) | |
404 _connection.getResponseFields().putDateField(name, date); | |
405 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
406 |
813 | 407 /* ------------------------------------------------------------ */ |
408 /* | |
409 * @see javax.servlet.http.HttpServletResponse#addDateHeader(java.lang.String, long) | |
410 */ | |
411 public void addDateHeader(String name, long date) | |
412 { | |
413 if (!_connection.isIncluding()) | |
414 _connection.getResponseFields().addDateField(name, date); | |
415 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
416 |
813 | 417 /* ------------------------------------------------------------ */ |
418 /* | |
419 * @see javax.servlet.http.HttpServletResponse#setHeader(java.lang.String, java.lang.String) | |
420 */ | |
421 public void setHeader(String name, String value) | |
422 { | |
423 if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name)) | |
424 setContentType(value); | |
425 else | |
426 { | |
427 if (_connection.isIncluding()) | |
428 { | |
429 if (name.startsWith(SET_INCLUDE_HEADER_PREFIX)) | |
430 name=name.substring(SET_INCLUDE_HEADER_PREFIX.length()); | |
431 else | |
432 return; | |
433 } | |
434 _connection.getResponseFields().put(name, value); | |
435 if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name)) | |
436 { | |
437 if (value==null) | |
438 _connection._generator.setContentLength(-1); | |
439 else | |
440 _connection._generator.setContentLength(Long.parseLong(value)); | |
441 } | |
442 } | |
443 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
444 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
445 |
813 | 446 /* ------------------------------------------------------------ */ |
447 public Collection<String> getHeaderNames() | |
448 { | |
449 final HttpFields fields=_connection.getResponseFields(); | |
450 return fields.getFieldNamesCollection(); | |
451 } | |
452 | |
453 /* ------------------------------------------------------------ */ | |
454 /* | |
455 */ | |
456 public String getHeader(String name) | |
457 { | |
458 return _connection.getResponseFields().getStringField(name); | |
459 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
460 |
813 | 461 /* ------------------------------------------------------------ */ |
462 /* | |
463 */ | |
464 public Collection<String> getHeaders(String name) | |
465 { | |
466 final HttpFields fields=_connection.getResponseFields(); | |
467 Collection<String> i = fields.getValuesCollection(name); | |
468 if (i==null) | |
469 return Collections.EMPTY_LIST; | |
470 return i; | |
471 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
472 |
813 | 473 /* ------------------------------------------------------------ */ |
474 /* | |
475 * @see javax.servlet.http.HttpServletResponse#addHeader(java.lang.String, java.lang.String) | |
476 */ | |
477 public void addHeader(String name, String value) | |
478 { | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
479 |
813 | 480 if (_connection.isIncluding()) |
481 { | |
482 if (name.startsWith(SET_INCLUDE_HEADER_PREFIX)) | |
483 name=name.substring(SET_INCLUDE_HEADER_PREFIX.length()); | |
484 else | |
485 return; | |
486 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
487 |
813 | 488 if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name)) |
489 { | |
490 setContentType(value); | |
491 return; | |
492 } | |
493 | |
494 _connection.getResponseFields().add(name, value); | |
495 if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name)) | |
496 _connection._generator.setContentLength(Long.parseLong(value)); | |
497 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
498 |
813 | 499 /* ------------------------------------------------------------ */ |
500 /* | |
501 * @see javax.servlet.http.HttpServletResponse#setIntHeader(java.lang.String, int) | |
502 */ | |
503 public void setIntHeader(String name, int value) | |
504 { | |
505 if (!_connection.isIncluding()) | |
506 { | |
507 _connection.getResponseFields().putLongField(name, value); | |
508 if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name)) | |
509 _connection._generator.setContentLength(value); | |
510 } | |
511 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
512 |
813 | 513 /* ------------------------------------------------------------ */ |
514 /* | |
515 * @see javax.servlet.http.HttpServletResponse#addIntHeader(java.lang.String, int) | |
516 */ | |
517 public void addIntHeader(String name, int value) | |
518 { | |
519 if (!_connection.isIncluding()) | |
520 { | |
521 _connection.getResponseFields().addLongField(name, value); | |
522 if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name)) | |
523 _connection._generator.setContentLength(value); | |
524 } | |
525 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
526 |
813 | 527 /* ------------------------------------------------------------ */ |
528 /* | |
529 * @see javax.servlet.http.HttpServletResponse#setStatus(int) | |
530 */ | |
531 public void setStatus(int sc) | |
532 { | |
533 setStatus(sc,null); | |
534 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
535 |
813 | 536 /* ------------------------------------------------------------ */ |
537 /* | |
538 * @see javax.servlet.http.HttpServletResponse#setStatus(int, java.lang.String) | |
539 */ | |
540 public void setStatus(int sc, String sm) | |
541 { | |
542 if (sc<=0) | |
543 throw new IllegalArgumentException(); | |
544 if (!_connection.isIncluding()) | |
545 { | |
546 _status=sc; | |
547 _reason=sm; | |
548 } | |
549 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
550 |
813 | 551 /* ------------------------------------------------------------ */ |
552 /* | |
553 * @see javax.servlet.ServletResponse#getCharacterEncoding() | |
554 */ | |
555 public String getCharacterEncoding() | |
556 { | |
557 if (_characterEncoding==null) | |
558 _characterEncoding=StringUtil.__ISO_8859_1; | |
559 return _characterEncoding; | |
560 } | |
561 | |
562 /* ------------------------------------------------------------ */ | |
563 String getSetCharacterEncoding() | |
564 { | |
565 return _characterEncoding; | |
566 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
567 |
813 | 568 /* ------------------------------------------------------------ */ |
569 /* | |
570 * @see javax.servlet.ServletResponse#getContentType() | |
571 */ | |
572 public String getContentType() | |
573 { | |
574 return _contentType; | |
575 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
576 |
813 | 577 /* ------------------------------------------------------------ */ |
578 /* | |
579 * @see javax.servlet.ServletResponse#getOutputStream() | |
580 */ | |
581 public ServletOutputStream getOutputStream() throws IOException | |
582 { | |
583 if (_outputState!=NONE && _outputState!=STREAM) | |
584 throw new IllegalStateException("WRITER"); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
585 |
813 | 586 ServletOutputStream out = _connection.getOutputStream(); |
587 _outputState=STREAM; | |
588 return out; | |
589 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
590 |
813 | 591 /* ------------------------------------------------------------ */ |
592 public boolean isWriting() | |
593 { | |
594 return _outputState==WRITER; | |
595 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
596 |
813 | 597 /* ------------------------------------------------------------ */ |
598 public boolean isOutputing() | |
599 { | |
600 return _outputState!=NONE; | |
601 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
602 |
813 | 603 /* ------------------------------------------------------------ */ |
604 /* | |
605 * @see javax.servlet.ServletResponse#getWriter() | |
606 */ | |
607 public PrintWriter getWriter() throws IOException | |
608 { | |
609 if (_outputState!=NONE && _outputState!=WRITER) | |
610 throw new IllegalStateException("STREAM"); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
611 |
813 | 612 /* if there is no writer yet */ |
613 if (_writer==null) | |
614 { | |
615 /* get encoding from Content-Type header */ | |
616 String encoding = _characterEncoding; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
617 |
813 | 618 if (encoding==null) |
619 { | |
620 /* implementation of educated defaults */ | |
621 if(_cachedMimeType != null) | |
622 encoding = MimeTypes.getCharsetFromContentType(_cachedMimeType); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
623 |
813 | 624 if (encoding==null) |
625 encoding = StringUtil.__ISO_8859_1; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
626 |
813 | 627 setCharacterEncoding(encoding); |
628 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
629 |
813 | 630 /* construct Writer using correct encoding */ |
631 _writer = _connection.getPrintWriter(encoding); | |
632 } | |
633 _outputState=WRITER; | |
634 return _writer; | |
635 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
636 |
813 | 637 /* ------------------------------------------------------------ */ |
638 /* | |
639 * @see javax.servlet.ServletResponse#setCharacterEncoding(java.lang.String) | |
640 */ | |
641 public void setCharacterEncoding(String encoding) | |
642 { | |
643 if (_connection.isIncluding()) | |
644 return; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
645 |
813 | 646 if (this._outputState==0 && !isCommitted()) |
647 { | |
648 _explicitEncoding=true; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
649 |
813 | 650 if (encoding==null) |
651 { | |
652 // Clear any encoding. | |
653 if (_characterEncoding!=null) | |
654 { | |
655 _characterEncoding=null; | |
656 if (_cachedMimeType!=null) | |
657 _contentType=_cachedMimeType.toString(); | |
658 else if (_mimeType!=null) | |
659 _contentType=_mimeType; | |
660 else | |
661 _contentType=null; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
662 |
813 | 663 if (_contentType==null) |
664 _connection.getResponseFields().remove(HttpHeaders.CONTENT_TYPE_BUFFER); | |
665 else | |
666 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | |
667 } | |
668 } | |
669 else | |
670 { | |
671 // No, so just add this one to the mimetype | |
672 _characterEncoding=encoding; | |
673 if (_contentType!=null) | |
674 { | |
675 int i0=_contentType.indexOf(';'); | |
676 if (i0<0) | |
677 { | |
678 _contentType=null; | |
679 if(_cachedMimeType!=null) | |
680 { | |
681 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); | |
682 if (content_type!=null) | |
683 { | |
684 _contentType=content_type.toString(); | |
685 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type); | |
686 } | |
687 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
688 |
813 | 689 if (_contentType==null) |
690 { | |
691 _contentType = _mimeType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); | |
692 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | |
693 } | |
694 } | |
695 else | |
696 { | |
697 int i1=_contentType.indexOf("charset=",i0); | |
698 if (i1<0) | |
699 { | |
700 _contentType = _contentType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); | |
701 } | |
702 else | |
703 { | |
704 int i8=i1+8; | |
705 int i2=_contentType.indexOf(" ",i8); | |
706 if (i2<0) | |
707 _contentType=_contentType.substring(0,i8)+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); | |
708 else | |
709 _contentType=_contentType.substring(0,i8)+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ")+_contentType.substring(i2); | |
710 } | |
711 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | |
712 } | |
713 } | |
714 } | |
715 } | |
716 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
717 |
813 | 718 /* ------------------------------------------------------------ */ |
719 /* | |
720 * @see javax.servlet.ServletResponse#setContentLength(int) | |
721 */ | |
722 public void setContentLength(int len) | |
723 { | |
724 // Protect from setting after committed as default handling | |
725 // of a servlet HEAD request ALWAYS sets _content length, even | |
726 // if the getHandling committed the response! | |
727 if (isCommitted() || _connection.isIncluding()) | |
728 return; | |
729 _connection._generator.setContentLength(len); | |
730 if (len>0) | |
731 { | |
732 _connection.getResponseFields().putLongField(HttpHeaders.CONTENT_LENGTH, len); | |
733 if (_connection._generator.isAllContentWritten()) | |
734 { | |
735 if (_outputState==WRITER) | |
736 _writer.close(); | |
737 else if (_outputState==STREAM) | |
738 { | |
739 try | |
740 { | |
741 getOutputStream().close(); | |
742 } | |
743 catch(IOException e) | |
744 { | |
745 throw new RuntimeException(e); | |
746 } | |
747 } | |
748 } | |
749 } | |
750 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
751 |
813 | 752 /* ------------------------------------------------------------ */ |
753 /* | |
754 * @see javax.servlet.ServletResponse#setContentLength(int) | |
755 */ | |
756 public void setLongContentLength(long len) | |
757 { | |
758 // Protect from setting after committed as default handling | |
759 // of a servlet HEAD request ALWAYS sets _content length, even | |
760 // if the getHandling committed the response! | |
761 if (isCommitted() || _connection.isIncluding()) | |
762 return; | |
763 _connection._generator.setContentLength(len); | |
764 _connection.getResponseFields().putLongField(HttpHeaders.CONTENT_LENGTH, len); | |
765 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
766 |
813 | 767 /* ------------------------------------------------------------ */ |
768 /* | |
769 * @see javax.servlet.ServletResponse#setContentType(java.lang.String) | |
770 */ | |
771 public void setContentType(String contentType) | |
772 { | |
773 if (isCommitted() || _connection.isIncluding()) | |
774 return; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
775 |
813 | 776 // Yes this method is horribly complex.... but there are lots of special cases and |
777 // as this method is called on every request, it is worth trying to save string creation. | |
778 // | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
779 |
813 | 780 if (contentType==null) |
781 { | |
782 if (_locale==null) | |
783 _characterEncoding=null; | |
784 _mimeType=null; | |
785 _cachedMimeType=null; | |
786 _contentType=null; | |
787 _connection.getResponseFields().remove(HttpHeaders.CONTENT_TYPE_BUFFER); | |
788 } | |
789 else | |
790 { | |
791 // Look for encoding in contentType | |
792 int i0=contentType.indexOf(';'); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
793 |
813 | 794 if (i0>0) |
795 { | |
796 // we have content type parameters | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
797 |
813 | 798 // Extract params off mimetype |
799 _mimeType=contentType.substring(0,i0).trim(); | |
800 _cachedMimeType=MimeTypes.CACHE.get(_mimeType); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
801 |
813 | 802 // Look for charset |
803 int i1=contentType.indexOf("charset=",i0+1); | |
804 if (i1>=0) | |
805 { | |
806 _explicitEncoding=true; | |
807 int i8=i1+8; | |
808 int i2 = contentType.indexOf(' ',i8); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
809 |
813 | 810 if (_outputState==WRITER) |
811 { | |
812 // strip the charset and ignore; | |
813 if ((i1==i0+1 && i2<0) || (i1==i0+2 && i2<0 && contentType.charAt(i0+1)==' ')) | |
814 { | |
815 if (_cachedMimeType!=null) | |
816 { | |
817 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); | |
818 if (content_type!=null) | |
819 { | |
820 _contentType=content_type.toString(); | |
821 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type); | |
822 } | |
823 else | |
824 { | |
825 _contentType=_mimeType+";charset="+_characterEncoding; | |
826 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | |
827 } | |
828 } | |
829 else | |
830 { | |
831 _contentType=_mimeType+";charset="+_characterEncoding; | |
832 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | |
833 } | |
834 } | |
835 else if (i2<0) | |
836 { | |
837 _contentType=contentType.substring(0,i1)+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); | |
838 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | |
839 } | |
840 else | |
841 { | |
842 _contentType=contentType.substring(0,i1)+contentType.substring(i2)+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); | |
843 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | |
844 } | |
845 } | |
846 else if ((i1==i0+1 && i2<0) || (i1==i0+2 && i2<0 && contentType.charAt(i0+1)==' ')) | |
847 { | |
848 // The params are just the char encoding | |
849 _cachedMimeType=MimeTypes.CACHE.get(_mimeType); | |
850 _characterEncoding = QuotedStringTokenizer.unquote(contentType.substring(i8)); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
851 |
813 | 852 if (_cachedMimeType!=null) |
853 { | |
854 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); | |
855 if (content_type!=null) | |
856 { | |
857 _contentType=content_type.toString(); | |
858 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type); | |
859 } | |
860 else | |
861 { | |
862 _contentType=contentType; | |
863 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | |
864 } | |
865 } | |
866 else | |
867 { | |
868 _contentType=contentType; | |
869 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | |
870 } | |
871 } | |
872 else if (i2>0) | |
873 { | |
874 _characterEncoding = QuotedStringTokenizer.unquote(contentType.substring(i8,i2)); | |
875 _contentType=contentType; | |
876 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | |
877 } | |
878 else | |
879 { | |
880 _characterEncoding = QuotedStringTokenizer.unquote(contentType.substring(i8)); | |
881 _contentType=contentType; | |
882 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | |
883 } | |
884 } | |
885 else // No encoding in the params. | |
886 { | |
887 _cachedMimeType=null; | |
888 _contentType=_characterEncoding==null?contentType:contentType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); | |
889 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | |
890 } | |
891 } | |
892 else // No params at all | |
893 { | |
894 _mimeType=contentType; | |
895 _cachedMimeType=MimeTypes.CACHE.get(_mimeType); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
896 |
813 | 897 if (_characterEncoding!=null) |
898 { | |
899 if (_cachedMimeType!=null) | |
900 { | |
901 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); | |
902 if (content_type!=null) | |
903 { | |
904 _contentType=content_type.toString(); | |
905 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type); | |
906 } | |
907 else | |
908 { | |
909 _contentType=_mimeType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); | |
910 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | |
911 } | |
912 } | |
913 else | |
914 { | |
915 _contentType=contentType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); | |
916 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | |
917 } | |
918 } | |
919 else if (_cachedMimeType!=null) | |
920 { | |
921 _contentType=_cachedMimeType.toString(); | |
922 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_cachedMimeType); | |
923 } | |
924 else | |
925 { | |
926 _contentType=contentType; | |
927 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | |
928 } | |
929 } | |
930 } | |
931 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
932 |
813 | 933 /* ------------------------------------------------------------ */ |
934 /* | |
935 * @see javax.servlet.ServletResponse#setBufferSize(int) | |
936 */ | |
937 public void setBufferSize(int size) | |
938 { | |
939 if (isCommitted() || getContentCount()>0) | |
940 throw new IllegalStateException("Committed or content written"); | |
941 _connection.getGenerator().increaseContentBufferSize(size); | |
942 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
943 |
813 | 944 /* ------------------------------------------------------------ */ |
945 /* | |
946 * @see javax.servlet.ServletResponse#getBufferSize() | |
947 */ | |
948 public int getBufferSize() | |
949 { | |
950 return _connection.getGenerator().getContentBufferSize(); | |
951 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
952 |
813 | 953 /* ------------------------------------------------------------ */ |
954 /* | |
955 * @see javax.servlet.ServletResponse#flushBuffer() | |
956 */ | |
957 public void flushBuffer() throws IOException | |
958 { | |
959 _connection.flushResponse(); | |
960 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
961 |
813 | 962 /* ------------------------------------------------------------ */ |
963 /* | |
964 * @see javax.servlet.ServletResponse#reset() | |
965 */ | |
966 public void reset() | |
967 { | |
968 resetBuffer(); | |
969 fwdReset(); | |
970 _status=200; | |
971 _reason=null; | |
972 | |
973 HttpFields response_fields=_connection.getResponseFields(); | |
974 | |
975 response_fields.clear(); | |
976 String connection=_connection.getRequestFields().getStringField(HttpHeaders.CONNECTION_BUFFER); | |
977 if (connection!=null) | |
978 { | |
979 String[] values = connection.split(","); | |
980 for (int i=0;values!=null && i<values.length;i++) | |
981 { | |
982 CachedBuffer cb = HttpHeaderValues.CACHE.get(values[0].trim()); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
983 |
813 | 984 if (cb!=null) |
985 { | |
986 switch(cb.getOrdinal()) | |
987 { | |
988 case HttpHeaderValues.CLOSE_ORDINAL: | |
989 response_fields.put(HttpHeaders.CONNECTION_BUFFER,HttpHeaderValues.CLOSE_BUFFER); | |
990 break; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
991 |
813 | 992 case HttpHeaderValues.KEEP_ALIVE_ORDINAL: |
993 if (HttpVersions.HTTP_1_0.equalsIgnoreCase(_connection.getRequest().getProtocol())) | |
994 response_fields.put(HttpHeaders.CONNECTION_BUFFER,HttpHeaderValues.KEEP_ALIVE); | |
995 break; | |
996 case HttpHeaderValues.TE_ORDINAL: | |
997 response_fields.put(HttpHeaders.CONNECTION_BUFFER,HttpHeaderValues.TE); | |
998 break; | |
999 } | |
1000 } | |
1001 } | |
1002 } | |
1003 } | |
1004 | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1005 |
813 | 1006 public void reset(boolean preserveCookies) |
1007 { | |
1008 if (!preserveCookies) | |
1009 reset(); | |
1010 else | |
1011 { | |
1012 HttpFields response_fields=_connection.getResponseFields(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1013 |
813 | 1014 ArrayList<String> cookieValues = new ArrayList<String>(5); |
1015 Enumeration<String> vals = response_fields.getValues(HttpHeaders.SET_COOKIE); | |
1016 while (vals.hasMoreElements()) | |
1017 cookieValues.add((String)vals.nextElement()); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1018 |
813 | 1019 reset(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1020 |
813 | 1021 for (String v:cookieValues) |
1022 response_fields.add(HttpHeaders.SET_COOKIE, v); | |
1023 } | |
1024 } | |
1025 | |
1026 | |
1027 | |
1028 /* ------------------------------------------------------------ */ | |
1029 /* | |
1030 * @see javax.servlet.ServletResponse#reset() | |
1031 */ | |
1032 public void fwdReset() | |
1033 { | |
1034 resetBuffer(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1035 |
813 | 1036 _writer=null; |
1037 _outputState=NONE; | |
1038 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1039 |
813 | 1040 /* ------------------------------------------------------------ */ |
1041 /* | |
1042 * @see javax.servlet.ServletResponse#resetBuffer() | |
1043 */ | |
1044 public void resetBuffer() | |
1045 { | |
1046 if (isCommitted()) | |
1047 throw new IllegalStateException("Committed"); | |
1048 _connection.getGenerator().resetBuffer(); | |
1049 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1050 |
813 | 1051 /* ------------------------------------------------------------ */ |
1052 /* | |
1053 * @see javax.servlet.ServletResponse#isCommitted() | |
1054 */ | |
1055 public boolean isCommitted() | |
1056 { | |
1057 return _connection.isResponseCommitted(); | |
1058 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1059 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1060 |
813 | 1061 /* ------------------------------------------------------------ */ |
1062 /* | |
1063 * @see javax.servlet.ServletResponse#setLocale(java.util.Locale) | |
1064 */ | |
1065 public void setLocale(Locale locale) | |
1066 { | |
1067 if (locale == null || isCommitted() ||_connection.isIncluding()) | |
1068 return; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1069 |
813 | 1070 _locale = locale; |
1071 _connection.getResponseFields().put(HttpHeaders.CONTENT_LANGUAGE_BUFFER,locale.toString().replace('_','-')); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1072 |
813 | 1073 if (_explicitEncoding || _outputState!=0 ) |
1074 return; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1075 |
813 | 1076 if (_connection.getRequest().getContext()==null) |
1077 return; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1078 |
813 | 1079 String charset = _connection.getRequest().getContext().getContextHandler().getLocaleEncoding(locale); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1080 |
813 | 1081 if (charset!=null && charset.length()>0) |
1082 { | |
1083 _characterEncoding=charset; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1084 |
813 | 1085 /* get current MIME type from Content-Type header */ |
1086 String type=getContentType(); | |
1087 if (type!=null) | |
1088 { | |
1089 _characterEncoding=charset; | |
1090 int semi=type.indexOf(';'); | |
1091 if (semi<0) | |
1092 { | |
1093 _mimeType=type; | |
1094 _contentType= type += ";charset="+charset; | |
1095 } | |
1096 else | |
1097 { | |
1098 _mimeType=type.substring(0,semi); | |
1099 _contentType= _mimeType += ";charset="+charset; | |
1100 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1101 |
813 | 1102 _cachedMimeType=MimeTypes.CACHE.get(_mimeType); |
1103 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | |
1104 } | |
1105 } | |
1106 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1107 |
813 | 1108 /* ------------------------------------------------------------ */ |
1109 /* | |
1110 * @see javax.servlet.ServletResponse#getLocale() | |
1111 */ | |
1112 public Locale getLocale() | |
1113 { | |
1114 if (_locale==null) | |
1115 return Locale.getDefault(); | |
1116 return _locale; | |
1117 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1118 |
813 | 1119 /* ------------------------------------------------------------ */ |
1120 /** | |
1121 * @return The HTTP status code that has been set for this request. This will be <code>200<code> | |
1122 * ({@link HttpServletResponse#SC_OK}), unless explicitly set through one of the <code>setStatus</code> methods. | |
1123 */ | |
1124 public int getStatus() | |
1125 { | |
1126 return _status; | |
1127 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1128 |
813 | 1129 /* ------------------------------------------------------------ */ |
1130 /** | |
1131 * @return The reason associated with the current {@link #getStatus() status}. This will be <code>null</code>, | |
1132 * unless one of the <code>setStatus</code> methods have been called. | |
1133 */ | |
1134 public String getReason() | |
1135 { | |
1136 return _reason; | |
1137 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1138 |
813 | 1139 /* ------------------------------------------------------------ */ |
1140 /** | |
1141 */ | |
1142 public void complete() | |
1143 throws IOException | |
1144 { | |
1145 _connection.completeResponse(); | |
1146 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1147 |
813 | 1148 /* ------------------------------------------------------------- */ |
1149 /** | |
1150 * @return the number of bytes actually written in response body | |
1151 */ | |
1152 public long getContentCount() | |
1153 { | |
1154 if (_connection==null || _connection.getGenerator()==null) | |
1155 return -1; | |
1156 return _connection.getGenerator().getContentWritten(); | |
1157 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1158 |
813 | 1159 /* ------------------------------------------------------------ */ |
1160 public HttpFields getHttpFields() | |
1161 { | |
1162 return _connection.getResponseFields(); | |
1163 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1164 |
813 | 1165 /* ------------------------------------------------------------ */ |
1166 @Override | |
1167 public String toString() | |
1168 { | |
1169 return "HTTP/1.1 "+_status+" "+ (_reason==null?"":_reason) +System.getProperty("line.separator")+ | |
1170 _connection.getResponseFields().toString(); | |
1171 } | |
1172 | |
1173 /* ------------------------------------------------------------ */ | |
1174 /* ------------------------------------------------------------ */ | |
1175 /* ------------------------------------------------------------ */ | |
1176 private static class NullOutput extends ServletOutputStream | |
1177 { | |
1178 @Override | |
1179 public void write(int b) throws IOException | |
1180 { | |
1181 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1182 |
813 | 1183 @Override |
1184 public void print(String s) throws IOException | |
1185 { | |
1186 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1187 |
813 | 1188 @Override |
1189 public void println(String s) throws IOException | |
1190 { | |
1191 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1192 |
813 | 1193 @Override |
1194 public void write(byte[] b, int off, int len) throws IOException | |
1195 { | |
1196 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1197 |
813 | 1198 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1199 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1200 } |