Mercurial Hosting > luan
annotate src/org/eclipse/jetty/server/AbstractHttpConnection.java @ 978:bdb6eb0fbf93
simplify ChannelEndPoint
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 16 Oct 2016 14:53:43 -0600 |
parents | d35b0a3a7a4a |
children | c8cd3e96db5f |
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.InputStream; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 import java.io.PrintWriter; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 import javax.servlet.DispatcherType; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 import javax.servlet.RequestDispatcher; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 import javax.servlet.ServletInputStream; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 import javax.servlet.ServletOutputStream; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 import javax.servlet.http.HttpServletRequest; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 import javax.servlet.http.HttpServletResponse; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
31 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
32 import org.eclipse.jetty.http.EncodedHttpURI; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 import org.eclipse.jetty.http.Generator; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 import org.eclipse.jetty.http.HttpBuffers; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
35 import org.eclipse.jetty.http.HttpException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 import org.eclipse.jetty.http.HttpFields; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
37 import org.eclipse.jetty.http.HttpGenerator; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 import org.eclipse.jetty.http.HttpHeaderValues; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
39 import org.eclipse.jetty.http.HttpHeaders; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 import org.eclipse.jetty.http.HttpMethods; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 import org.eclipse.jetty.http.HttpParser; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
42 import org.eclipse.jetty.http.HttpStatus; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
43 import org.eclipse.jetty.http.HttpURI; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 import org.eclipse.jetty.http.HttpVersions; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
45 import org.eclipse.jetty.http.MimeTypes; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
46 import org.eclipse.jetty.http.Parser; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
47 import org.eclipse.jetty.io.AbstractConnection; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
48 import org.eclipse.jetty.io.Buffer; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
49 import org.eclipse.jetty.io.BufferCache.CachedBuffer; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
50 import org.eclipse.jetty.io.Buffers; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
51 import org.eclipse.jetty.io.EndPoint; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
52 import org.eclipse.jetty.io.EofException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
53 import org.eclipse.jetty.io.RuntimeIOException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
54 import org.eclipse.jetty.util.QuotedStringTokenizer; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
55 import org.eclipse.jetty.util.StringUtil; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
56 import org.eclipse.jetty.util.URIUtil; |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
57 import org.slf4j.Logger; |
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
58 import org.slf4j.LoggerFactory; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
59 import org.eclipse.jetty.util.resource.Resource; |
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 /** |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
62 * <p>A HttpConnection represents the connection of a HTTP client to the server |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
63 * and is created by an instance of a {@link Connector}. It's prime function is |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
64 * to associate {@link Request} and {@link Response} instances with a {@link EndPoint}. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
65 * </p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
66 * <p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
67 * A connection is also the prime mechanism used by jetty to recycle objects without |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
68 * pooling. The {@link Request}, {@link Response}, {@link HttpParser}, {@link HttpGenerator} |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
69 * and {@link HttpFields} instances are all recycled for the duraction of |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
70 * a connection. Where appropriate, allocated buffers are also kept associated |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
71 * with the connection via the parser and/or generator. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
72 * </p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
73 * <p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
74 * The connection state is held by 3 separate state machines: The request state, the |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
75 * response state and the continuation state. All three state machines must be driven |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
76 * to completion for every request, and all three can complete in any order. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
77 * </p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
78 * <p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
79 * The HttpConnection support protocol upgrade. If on completion of a request, the |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
80 * response code is 101 (switch protocols), then the org.eclipse.jetty.io.Connection |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
81 * request attribute is checked to see if there is a new Connection instance. If so, |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
82 * the new connection is returned from {@link #handle()} and is used for future |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
83 * handling of the underlying connection. Note that for switching protocols that |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
84 * don't use 101 responses (eg CONNECT), the response should be sent and then the |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
85 * status code changed to 101 before returning from the handler. Implementors |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
86 * of new Connection types should be careful to extract any buffered data from |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
87 * (HttpParser)http.getParser()).getHeaderBuffer() and |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
88 * (HttpParser)http.getParser()).getBodyBuffer() to initialise their new connection. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
89 * </p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
90 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
91 */ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
92 public abstract class AbstractHttpConnection extends AbstractConnection |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
93 { |
826 | 94 private static final Logger LOG = LoggerFactory.getLogger(AbstractHttpConnection.class); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
95 |
826 | 96 private int _requests; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
97 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
98 private final Connector _connector; |
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
99 private final Server _server; |
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
100 protected final HttpURI _uri = StringUtil.__UTF8.equals(URIUtil.__CHARSET)?new HttpURI():new EncodedHttpURI(URIUtil.__CHARSET); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
101 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
102 protected final HttpParser _parser; |
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
103 protected final HttpFields _requestFields = new HttpFields(); |
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
104 private final Request _request; |
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
105 private volatile ServletInputStream _in; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
106 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
107 protected final HttpGenerator _generator; |
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
108 final HttpFields _responseFields = new HttpFields(); |
826 | 109 protected final Response _response; |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
110 private volatile Output _out; |
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
111 private volatile HttpWriter _writer; |
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
112 private volatile PrintWriter _printWriter; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
113 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
114 private int _version = -2; // UNKNOWN |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
115 |
826 | 116 private String _charset; |
117 private boolean _expect = false; | |
118 private boolean _expect100Continue = false; | |
119 private boolean _expect102Processing = false; | |
120 private boolean _head = false; | |
121 private boolean _host = false; | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
122 private boolean _delayedHandling = false; |
826 | 123 private boolean _earlyEOF = false; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
124 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
125 protected AbstractHttpConnection(Connector connector, EndPoint endpoint) |
826 | 126 { |
127 super(endpoint); | |
128 _connector = connector; | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
129 HttpBuffers ab = _connector; |
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
130 _parser = new HttpParser(ab.getRequestBuffers(), endpoint, new RequestHandler()); |
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
131 _request = new Request(this); |
826 | 132 _response = new Response(this); |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
133 _generator = new HttpGenerator(ab.getResponseBuffers(), endpoint); |
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
134 _server = connector.server; |
826 | 135 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
136 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
137 public final Connector getConnector() |
826 | 138 { |
139 return _connector; | |
140 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
141 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
142 public final Request getRequest() |
826 | 143 { |
144 return _request; | |
145 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
146 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
147 public final Response getResponse() |
826 | 148 { |
149 return _response; | |
150 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
151 |
826 | 152 /* ------------------------------------------------------------ */ |
153 /** | |
154 * Get the inputStream from the connection. | |
155 * <p> | |
156 * If the associated response has the Expect header set to 100 Continue, | |
157 * then accessing the input stream indicates that the handler/servlet | |
158 * is ready for the request body and thus a 100 Continue response is sent. | |
159 * | |
160 * @return The input stream for this connection. | |
161 * The stream will be created if it does not already exist. | |
162 * @throws IOException if the input stream cannot be retrieved | |
163 */ | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
164 public final ServletInputStream getInputStream() throws IOException |
826 | 165 { |
166 // If the client is expecting 100 CONTINUE, then send it now. | |
167 if (_expect100Continue) | |
168 { | |
169 // is content missing? | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
170 if (_parser.getHeaderBuffer()==null || _parser.getHeaderBuffer().length()<2) |
826 | 171 { |
172 if (_generator.isCommitted()) | |
173 throw new IllegalStateException("Committed before 100 Continues"); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
174 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
175 _generator.send1xx(HttpStatus.CONTINUE_100); |
826 | 176 } |
177 _expect100Continue=false; | |
178 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
179 |
826 | 180 if (_in == null) |
181 _in = new HttpInput(AbstractHttpConnection.this); | |
182 return _in; | |
183 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
184 |
826 | 185 /* ------------------------------------------------------------ */ |
186 /** | |
187 * @return The output stream for this connection. The stream will be created if it does not already exist. | |
188 */ | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
189 public final ServletOutputStream getOutputStream() |
826 | 190 { |
191 if (_out == null) | |
192 _out = new Output(); | |
193 return _out; | |
194 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
195 |
826 | 196 /* ------------------------------------------------------------ */ |
197 /** | |
198 * @param encoding the PrintWriter encoding | |
199 * @return A {@link PrintWriter} wrapping the {@link #getOutputStream output stream}. The writer is created if it | |
200 * does not already exist. | |
201 */ | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
202 public final PrintWriter getPrintWriter(String encoding) |
826 | 203 { |
204 getOutputStream(); | |
205 if (_writer==null) | |
206 { | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
207 _writer = new HttpWriter(_out); |
882
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
208 _printWriter = new PrintWriter(_writer) |
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
209 { |
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
210 public void close() |
826 | 211 { |
882
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
212 synchronized (lock) |
826 | 213 { |
882
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
214 try |
826 | 215 { |
882
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
216 out.close(); |
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
217 } |
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
218 catch (IOException e) |
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
219 { |
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
220 setError(); |
826 | 221 } |
222 } | |
882
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
223 } |
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
224 }; |
826 | 225 } |
226 _writer.setCharacterEncoding(encoding); | |
227 return _printWriter; | |
228 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
229 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
230 public final boolean isEarlyEOF() |
826 | 231 { |
232 return _earlyEOF; | |
233 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
234 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
235 protected void reset() |
826 | 236 { |
237 _parser.reset(); | |
238 _parser.returnBuffers(); // TODO maybe only on unhandle | |
239 _requestFields.clear(); | |
240 _request.recycle(); | |
241 _generator.reset(); | |
242 _generator.returnBuffers();// TODO maybe only on unhandle | |
243 _responseFields.clear(); | |
244 _response.recycle(); | |
245 _uri.clear(); | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
246 _writer = null; |
826 | 247 _earlyEOF = false; |
248 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
249 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
250 private void handleRequest() throws IOException |
826 | 251 { |
252 boolean error = false; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
253 |
826 | 254 try |
255 { | |
256 // Loop here to handle async request redispatches. | |
257 // The loop is controlled by the call to async.unhandle in the | |
258 // finally block below. If call is from a non-blocking connector, | |
259 // then the unhandle will return false only if an async dispatch has | |
260 // already happened when unhandle is called. For a blocking connector, | |
261 // the wait for the asynchronous dispatch or timeout actually happens | |
262 // within the call to unhandle(). | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
263 |
939
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
264 _request.setHandled(false); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
265 |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
266 String info=null; |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
267 try |
826 | 268 { |
939
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
269 _uri.getPort(); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
270 String path = null; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
271 |
826 | 272 try |
273 { | |
939
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
274 path = _uri.getDecodedPath(); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
275 } |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
276 catch (Exception e) |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
277 { |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
278 LOG.warn("Failed UTF-8 decode for request path, trying ISO-8859-1"); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
279 LOG.trace("",e); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
280 path = _uri.getDecodedPath(StringUtil.__ISO_8859_1); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
281 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
282 |
939
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
283 info = URIUtil.canonicalPath(path); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
284 if (info==null && !_request.getMethod().equals(HttpMethods.CONNECT)) |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
285 { |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
286 if (path==null && _uri.getScheme()!=null && _uri.getHost()!=null) |
826 | 287 { |
939
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
288 info="/"; |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
289 _request.setRequestURI(""); |
826 | 290 } |
939
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
291 else |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
292 throw new HttpException(400); |
826 | 293 } |
939
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
294 _request.setPathInfo(info); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
295 |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
296 if (_out!=null) |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
297 _out.reopen(); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
298 |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
299 _request.setDispatcherType(DispatcherType.REQUEST); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
300 _connector.customize(_endp, _request); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
301 _server.handle(this); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
302 } |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
303 catch (EofException e) |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
304 { |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
305 LOG.debug("",e); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
306 error=true; |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
307 _request.setHandled(true); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
308 if (!_response.isCommitted()) |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
309 _generator.sendError(500, null, null, true); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
310 } |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
311 catch (RuntimeIOException e) |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
312 { |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
313 LOG.debug("",e); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
314 error=true; |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
315 _request.setHandled(true); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
316 } |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
317 catch (HttpException e) |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
318 { |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
319 LOG.debug("",e); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
320 error=true; |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
321 _request.setHandled(true); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
322 _response.sendError(e.getStatus(), e.getReason()); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
323 } |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
324 catch (Throwable e) |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
325 { |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
326 LOG.warn(String.valueOf(_uri),e); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
327 error=true; |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
328 _request.setHandled(true); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
329 _generator.sendError(info==null?400:500, null, null, true); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
330 |
826 | 331 } |
332 } | |
333 finally | |
334 { | |
939
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
335 if (_expect100Continue) |
826 | 336 { |
939
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
337 LOG.debug("100 continues not sent"); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
338 // We didn't send 100 continues, but the latest interpretation |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
339 // of the spec (see httpbis) is that the client will either |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
340 // send the body anyway, or close. So we no longer need to |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
341 // do anything special here other than make the connection not persistent |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
342 _expect100Continue = false; |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
343 if (!_response.isCommitted()) |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
344 _generator.setPersistent(false); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
345 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
346 |
939
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
347 if(_endp.isOpen()) |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
348 { |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
349 if (error) |
826 | 350 { |
939
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
351 _endp.shutdownOutput(); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
352 _generator.setPersistent(false); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
353 if (!_generator.isComplete()) |
826 | 354 _response.complete(); |
355 } | |
356 else | |
357 { | |
939
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
358 if (!_response.isCommitted() && !_request.isHandled()) |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
359 _response.sendError(HttpServletResponse.SC_NOT_FOUND); |
826 | 360 _response.complete(); |
361 } | |
939
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
362 } |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
363 else |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
364 { |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
365 _response.complete(); |
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
366 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
367 |
939
8db5996c8c89
remove AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
368 _request.setHandled(true); |
826 | 369 } |
370 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
371 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
372 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
373 public final void commitResponse(boolean last) throws IOException |
826 | 374 { |
375 if (!_generator.isCommitted()) | |
376 { | |
377 _generator.setResponse(_response.getStatus(), _response.getReason()); | |
378 try | |
379 { | |
380 // If the client was expecting 100 continues, but we sent something | |
381 // else, then we need to close the connection | |
382 if (_expect100Continue && _response.getStatus()!=100) | |
383 _generator.setPersistent(false); | |
384 _generator.completeHeader(_responseFields, last); | |
385 } | |
386 catch(RuntimeException e) | |
387 { | |
388 LOG.warn("header full: " + e); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
389 |
826 | 390 _response.reset(); |
391 _generator.reset(); | |
392 _generator.setResponse(HttpStatus.INTERNAL_SERVER_ERROR_500,null); | |
393 _generator.completeHeader(_responseFields,Generator.LAST); | |
394 _generator.complete(); | |
395 throw new HttpException(HttpStatus.INTERNAL_SERVER_ERROR_500); | |
396 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
397 |
826 | 398 } |
399 if (last) | |
400 _generator.complete(); | |
401 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
402 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
403 public final void completeResponse() throws IOException |
826 | 404 { |
405 if (!_generator.isCommitted()) | |
406 { | |
407 _generator.setResponse(_response.getStatus(), _response.getReason()); | |
408 try | |
409 { | |
410 _generator.completeHeader(_responseFields, Generator.LAST); | |
411 } | |
412 catch(RuntimeException e) | |
413 { | |
414 LOG.warn("header full: "+e); | |
415 LOG.debug("",e); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
416 |
826 | 417 _response.reset(); |
418 _generator.reset(); | |
419 _generator.setResponse(HttpStatus.INTERNAL_SERVER_ERROR_500,null); | |
420 _generator.completeHeader(_responseFields,Generator.LAST); | |
421 _generator.complete(); | |
422 throw new HttpException(HttpStatus.INTERNAL_SERVER_ERROR_500); | |
423 } | |
424 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
425 |
826 | 426 _generator.complete(); |
427 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
428 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
429 public final void flushResponse() throws IOException |
826 | 430 { |
431 try | |
432 { | |
433 commitResponse(Generator.MORE); | |
434 _generator.flushBuffer(); | |
435 } | |
436 catch(IOException e) | |
437 { | |
438 throw (e instanceof EofException) ? e:new EofException(e); | |
439 } | |
440 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
441 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
442 public final boolean isExpecting102Processing() |
826 | 443 { |
444 return _expect102Processing; | |
445 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
446 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
447 public final int getMaxIdleTime() |
826 | 448 { |
449 if (_connector.isLowResources() && _endp.getMaxIdleTime()==_connector.getMaxIdleTime()) | |
913 | 450 return 0; |
826 | 451 if (_endp.getMaxIdleTime()>0) |
452 return _endp.getMaxIdleTime(); | |
453 return _connector.getMaxIdleTime(); | |
454 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
455 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
456 @Override |
826 | 457 public String toString() |
458 { | |
459 return String.format("%s,g=%s,p=%s,r=%d", | |
460 super.toString(), | |
461 _generator, | |
462 _parser, | |
463 _requests); | |
464 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
465 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
466 private void startRequest(Buffer method, Buffer uri, Buffer version) throws IOException |
826 | 467 { |
468 uri=uri.asImmutableBuffer(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
469 |
826 | 470 _host = false; |
471 _expect = false; | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
472 _expect100Continue = false; |
826 | 473 _expect102Processing=false; |
474 _delayedHandling=false; | |
475 _charset=null; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
476 |
826 | 477 if(_request.getTimeStamp()==0) |
478 _request.setTimeStamp(System.currentTimeMillis()); | |
479 _request.setMethod(method.toString()); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
480 |
826 | 481 try |
482 { | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
483 _head = false; |
826 | 484 switch (HttpMethods.CACHE.getOrdinal(method)) |
485 { | |
486 case HttpMethods.CONNECT_ORDINAL: | |
487 _uri.parseConnect(uri.array(), uri.getIndex(), uri.length()); | |
488 break; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
489 |
826 | 490 case HttpMethods.HEAD_ORDINAL: |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
491 _head = true; |
826 | 492 _uri.parse(uri.array(), uri.getIndex(), uri.length()); |
493 break; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
494 |
826 | 495 default: |
496 _uri.parse(uri.array(), uri.getIndex(), uri.length()); | |
497 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
498 |
826 | 499 _request.setUri(_uri); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
500 |
826 | 501 if (version==null) |
502 { | |
503 _request.setProtocol(HttpVersions.HTTP_0_9); | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
504 _version = HttpVersions.HTTP_0_9_ORDINAL; |
826 | 505 } |
506 else | |
507 { | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
508 version = HttpVersions.CACHE.get(version); |
826 | 509 if (version==null) |
510 throw new HttpException(HttpStatus.BAD_REQUEST_400,null); | |
511 _version = HttpVersions.CACHE.getOrdinal(version); | |
512 if (_version <= 0) _version = HttpVersions.HTTP_1_0_ORDINAL; | |
513 _request.setProtocol(version.toString()); | |
514 } | |
515 } | |
516 catch (Exception e) | |
517 { | |
518 LOG.debug("",e); | |
519 if (e instanceof HttpException) | |
520 throw (HttpException)e; | |
521 throw new HttpException(HttpStatus.BAD_REQUEST_400,null,e); | |
522 } | |
523 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
524 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
525 private void parsedHeader(Buffer name, Buffer value) throws IOException |
826 | 526 { |
527 int ho = HttpHeaders.CACHE.getOrdinal(name); | |
528 switch (ho) | |
529 { | |
530 case HttpHeaders.HOST_ORDINAL: | |
531 // TODO check if host matched a host in the URI. | |
532 _host = true; | |
533 break; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
534 |
826 | 535 case HttpHeaders.EXPECT_ORDINAL: |
536 if (_version>=HttpVersions.HTTP_1_1_ORDINAL) | |
537 { | |
538 value = HttpHeaderValues.CACHE.lookup(value); | |
539 switch(HttpHeaderValues.CACHE.getOrdinal(value)) | |
540 { | |
541 case HttpHeaderValues.CONTINUE_ORDINAL: | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
542 _expect100Continue = true; |
826 | 543 break; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
544 |
826 | 545 case HttpHeaderValues.PROCESSING_ORDINAL: |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
546 _expect102Processing = true; |
826 | 547 break; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
548 |
826 | 549 default: |
550 String[] values = value.toString().split(","); | |
551 for (int i=0;values!=null && i<values.length;i++) | |
552 { | |
553 CachedBuffer cb=HttpHeaderValues.CACHE.get(values[i].trim()); | |
554 if (cb==null) | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
555 _expect = true; |
826 | 556 else |
557 { | |
558 switch(cb.getOrdinal()) | |
559 { | |
560 case HttpHeaderValues.CONTINUE_ORDINAL: | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
561 _expect100Continue = true; |
826 | 562 break; |
563 case HttpHeaderValues.PROCESSING_ORDINAL: | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
564 _expect102Processing = true; |
826 | 565 break; |
566 default: | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
567 _expect = true; |
826 | 568 } |
569 } | |
570 } | |
571 } | |
572 } | |
573 break; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
574 |
826 | 575 case HttpHeaders.ACCEPT_ENCODING_ORDINAL: |
576 case HttpHeaders.USER_AGENT_ORDINAL: | |
577 value = HttpHeaderValues.CACHE.lookup(value); | |
578 break; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
579 |
826 | 580 case HttpHeaders.CONTENT_TYPE_ORDINAL: |
581 value = MimeTypes.CACHE.lookup(value); | |
582 _charset=MimeTypes.getCharsetFromContentType(value); | |
583 break; | |
584 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
585 |
826 | 586 _requestFields.add(name, value); |
587 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
588 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
589 private void headerComplete() throws IOException |
826 | 590 { |
591 // Handle idle race | |
592 if (_endp.isOutputShutdown()) | |
593 { | |
594 _endp.close(); | |
595 return; | |
596 } | |
597 | |
598 _requests++; | |
599 _generator.setVersion(_version); | |
600 switch (_version) | |
601 { | |
602 case HttpVersions.HTTP_0_9_ORDINAL: | |
603 break; | |
604 case HttpVersions.HTTP_1_0_ORDINAL: | |
605 _generator.setHead(_head); | |
606 if (_parser.isPersistent()) | |
607 { | |
608 _responseFields.add(HttpHeaders.CONNECTION_BUFFER, HttpHeaderValues.KEEP_ALIVE_BUFFER); | |
609 _generator.setPersistent(true); | |
610 } | |
611 else if (HttpMethods.CONNECT.equals(_request.getMethod())) | |
612 { | |
613 _generator.setPersistent(true); | |
614 _parser.setPersistent(true); | |
615 } | |
616 break; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
617 |
826 | 618 case HttpVersions.HTTP_1_1_ORDINAL: |
619 _generator.setHead(_head); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
620 |
826 | 621 if (!_parser.isPersistent()) |
622 { | |
623 _responseFields.add(HttpHeaders.CONNECTION_BUFFER,HttpHeaderValues.CLOSE_BUFFER); | |
624 _generator.setPersistent(false); | |
625 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
626 |
826 | 627 if (!_host) |
628 { | |
629 LOG.debug("!host {}",this); | |
630 _generator.setResponse(HttpStatus.BAD_REQUEST_400, null); | |
631 _responseFields.put(HttpHeaders.CONNECTION_BUFFER, HttpHeaderValues.CLOSE_BUFFER); | |
632 _generator.completeHeader(_responseFields, true); | |
633 _generator.complete(); | |
634 return; | |
635 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
636 |
826 | 637 if (_expect) |
638 { | |
639 LOG.debug("!expectation {}",this); | |
640 _generator.setResponse(HttpStatus.EXPECTATION_FAILED_417, null); | |
641 _responseFields.put(HttpHeaders.CONNECTION_BUFFER, HttpHeaderValues.CLOSE_BUFFER); | |
642 _generator.completeHeader(_responseFields, true); | |
643 _generator.complete(); | |
644 return; | |
645 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
646 |
826 | 647 break; |
648 default: | |
649 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
650 |
826 | 651 if(_charset!=null) |
652 _request.setCharacterEncodingUnchecked(_charset); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
653 |
826 | 654 // Either handle now or wait for first content |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
655 if ((_parser.getContentLength()<=0 && !_parser.isChunking())||_expect100Continue) |
826 | 656 handleRequest(); |
657 else | |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
658 _delayedHandling = true; |
826 | 659 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
660 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
661 private void content(Buffer buffer) throws IOException |
826 | 662 { |
663 if (_delayedHandling) | |
664 { | |
974
7422ca1ae146
remove Connection.isIdle()
Franklin Schmidt <fschmidt@gmail.com>
parents:
972
diff
changeset
|
665 _delayedHandling = false; |
826 | 666 handleRequest(); |
667 } | |
668 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
669 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
670 private void messageComplete(long contentLength) throws IOException |
826 | 671 { |
672 if (_delayedHandling) | |
673 { | |
974
7422ca1ae146
remove Connection.isIdle()
Franklin Schmidt <fschmidt@gmail.com>
parents:
972
diff
changeset
|
674 _delayedHandling = false; |
826 | 675 handleRequest(); |
676 } | |
677 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
678 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
679 private void earlyEOF() |
826 | 680 { |
681 _earlyEOF = true; | |
682 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
683 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
684 |
826 | 685 private class RequestHandler extends HttpParser.EventHandler |
686 { | |
687 @Override | |
688 public void startRequest(Buffer method, Buffer uri, Buffer version) throws IOException | |
689 { | |
690 AbstractHttpConnection.this.startRequest(method, uri, version); | |
691 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
692 |
826 | 693 @Override |
694 public void parsedHeader(Buffer name, Buffer value) throws IOException | |
695 { | |
696 AbstractHttpConnection.this.parsedHeader(name, value); | |
697 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
698 |
826 | 699 @Override |
700 public void headerComplete() throws IOException | |
701 { | |
702 AbstractHttpConnection.this.headerComplete(); | |
703 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
704 |
826 | 705 @Override |
706 public void content(Buffer ref) throws IOException | |
707 { | |
708 AbstractHttpConnection.this.content(ref); | |
709 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
710 |
826 | 711 @Override |
712 public void messageComplete(long contentLength) throws IOException | |
713 { | |
714 AbstractHttpConnection.this.messageComplete(contentLength); | |
715 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
716 |
826 | 717 @Override |
718 public void startResponse(Buffer version, int status, Buffer reason) | |
719 { | |
720 if (LOG.isDebugEnabled()) | |
721 LOG.debug("Bad request!: "+version+" "+status+" "+reason); | |
722 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
723 |
826 | 724 @Override |
725 public void earlyEOF() | |
726 { | |
727 AbstractHttpConnection.this.earlyEOF(); | |
728 } | |
729 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
730 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
731 |
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
732 public final class Output extends HttpOutput |
826 | 733 { |
734 Output() | |
735 { | |
736 super(AbstractHttpConnection.this); | |
737 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
738 |
826 | 739 /* ------------------------------------------------------------ */ |
740 /* | |
741 * @see java.io.OutputStream#close() | |
742 */ | |
743 @Override | |
744 public void close() throws IOException | |
745 { | |
746 if (isClosed()) | |
747 return; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
748 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
749 if (!super._generator.isCommitted()) |
826 | 750 commitResponse(Generator.LAST); |
751 else | |
752 flushResponse(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
753 |
826 | 754 super.close(); |
755 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
756 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
757 |
826 | 758 /* ------------------------------------------------------------ */ |
759 /* | |
760 * @see java.io.OutputStream#flush() | |
761 */ | |
762 @Override | |
763 public void flush() throws IOException | |
764 { | |
765 if (!super._generator.isCommitted()) | |
766 commitResponse(Generator.MORE); | |
767 super.flush(); | |
768 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
769 |
826 | 770 /* ------------------------------------------------------------ */ |
771 /* | |
772 * @see javax.servlet.ServletOutputStream#print(java.lang.String) | |
773 */ | |
774 @Override | |
775 public void print(String s) throws IOException | |
776 { | |
777 if (isClosed()) | |
778 throw new IOException("Closed"); | |
779 PrintWriter writer=getPrintWriter(null); | |
780 writer.print(s); | |
781 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
782 |
826 | 783 /* ------------------------------------------------------------ */ |
784 public void sendResponse(Buffer response) throws IOException | |
785 { | |
786 ((HttpGenerator)super._generator).sendResponse(response); | |
787 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
788 |
826 | 789 /* ------------------------------------------------------------ */ |
790 public void sendContent(Object content) throws IOException | |
791 { | |
792 Resource resource=null; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
793 |
826 | 794 if (isClosed()) |
795 throw new IOException("Closed"); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
796 |
826 | 797 if (super._generator.isWritten()) |
798 throw new IllegalStateException("!empty"); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
799 |
826 | 800 if (content instanceof Resource) |
801 { | |
802 resource=(Resource)content; | |
803 _responseFields.putDateField(HttpHeaders.LAST_MODIFIED_BUFFER, resource.lastModified()); | |
804 content=resource.getInputStream(); | |
805 } | |
806 | |
807 // Process content. | |
808 if (content instanceof Buffer) | |
809 { | |
810 super._generator.addContent((Buffer) content, Generator.LAST); | |
811 commitResponse(Generator.LAST); | |
812 } | |
813 else if (content instanceof InputStream) | |
814 { | |
815 InputStream in = (InputStream)content; | |
816 | |
817 try | |
818 { | |
819 int max = super._generator.prepareUncheckedAddContent(); | |
820 Buffer buffer = super._generator.getUncheckedBuffer(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
821 |
826 | 822 int len=buffer.readFrom(in,max); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
823 |
826 | 824 while (len>=0) |
825 { | |
826 super._generator.completeUncheckedAddContent(); | |
827 _out.flush(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
828 |
826 | 829 max = super._generator.prepareUncheckedAddContent(); |
830 buffer = super._generator.getUncheckedBuffer(); | |
831 len=buffer.readFrom(in,max); | |
832 } | |
833 super._generator.completeUncheckedAddContent(); | |
834 _out.flush(); | |
835 } | |
836 finally | |
837 { | |
838 if (resource!=null) | |
839 resource.release(); | |
840 else | |
841 in.close(); | |
842 } | |
843 } | |
844 else | |
845 throw new IllegalArgumentException("unknown content type?"); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
846 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
847 |
826 | 848 } |
849 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
850 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
851 } |