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