Mercurial Hosting > luan
annotate src/org/eclipse/jetty/server/AbstractHttpConnection.java @ 912:1d0c304e12b5
simplify AggregateLifeCycle
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Sat, 08 Oct 2016 22:05:14 -0600 |
| parents | cab5830e1ab0 |
| children | 17f4fe8271de |
| 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.continuation.ContinuationThrowable; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 import org.eclipse.jetty.http.EncodedHttpURI; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 import org.eclipse.jetty.http.Generator; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
35 import org.eclipse.jetty.http.HttpBuffers; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 import org.eclipse.jetty.http.HttpException; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
37 import org.eclipse.jetty.http.HttpFields; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 import org.eclipse.jetty.http.HttpGenerator; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
39 import org.eclipse.jetty.http.HttpHeaderValues; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 import org.eclipse.jetty.http.HttpHeaders; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 import org.eclipse.jetty.http.HttpMethods; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
42 import org.eclipse.jetty.http.HttpParser; |
|
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.http.Parser; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
48 import org.eclipse.jetty.io.AbstractConnection; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
49 import org.eclipse.jetty.io.Buffer; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
50 import org.eclipse.jetty.io.BufferCache.CachedBuffer; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
51 import org.eclipse.jetty.io.Buffers; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
52 import org.eclipse.jetty.io.Connection; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
53 import org.eclipse.jetty.io.EndPoint; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
54 import org.eclipse.jetty.io.EofException; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
55 import org.eclipse.jetty.io.RuntimeIOException; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
56 import org.eclipse.jetty.util.QuotedStringTokenizer; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
57 import org.eclipse.jetty.util.StringUtil; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
58 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
|
59 import org.slf4j.Logger; |
|
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
60 import org.slf4j.LoggerFactory; |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
61 import org.eclipse.jetty.util.resource.Resource; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
62 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
63 /** |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
64 * <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
|
65 * 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
|
66 * 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
|
67 * </p> |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
68 * <p> |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
69 * 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
|
70 * pooling. The {@link Request}, {@link Response}, {@link HttpParser}, {@link HttpGenerator} |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
71 * 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
|
72 * a connection. Where appropriate, allocated buffers are also kept associated |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
73 * with the connection via the parser and/or generator. |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
74 * </p> |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
75 * <p> |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
76 * 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
|
77 * 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
|
78 * 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
|
79 * </p> |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
80 * <p> |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
81 * 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
|
82 * 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
|
83 * 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
|
84 * 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
|
85 * 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
|
86 * 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
|
87 * 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
|
88 * 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
|
89 * (HttpParser)http.getParser()).getHeaderBuffer() and |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
90 * (HttpParser)http.getParser()).getBodyBuffer() to initialise their new connection. |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
91 * </p> |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
92 * |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
93 */ |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
94 public abstract class AbstractHttpConnection extends AbstractConnection |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
95 { |
| 826 | 96 private static final Logger LOG = LoggerFactory.getLogger(AbstractHttpConnection.class); |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
97 |
| 826 | 98 private static final int UNKNOWN = -2; |
| 99 private static final ThreadLocal<AbstractHttpConnection> __currentConnection = new ThreadLocal<AbstractHttpConnection>(); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
100 |
| 826 | 101 private int _requests; |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
102 |
| 826 | 103 protected final Connector _connector; |
| 104 protected final Server _server; | |
| 105 protected final HttpURI _uri; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
106 |
| 826 | 107 protected final Parser _parser; |
| 108 protected final HttpFields _requestFields; | |
| 109 protected final Request _request; | |
| 110 protected volatile ServletInputStream _in; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
111 |
| 826 | 112 protected final Generator _generator; |
| 113 protected final HttpFields _responseFields; | |
| 114 protected final Response _response; | |
| 115 protected volatile Output _out; | |
| 116 protected volatile OutputWriter _writer; | |
| 117 protected volatile PrintWriter _printWriter; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
118 |
| 826 | 119 int _include; |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
120 |
| 826 | 121 private Object _associatedObject; // associated object |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
122 |
| 826 | 123 private int _version = UNKNOWN; |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
124 |
| 826 | 125 private String _charset; |
| 126 private boolean _expect = false; | |
| 127 private boolean _expect100Continue = false; | |
| 128 private boolean _expect102Processing = false; | |
| 129 private boolean _head = false; | |
| 130 private boolean _host = false; | |
| 131 private boolean _delayedHandling=false; | |
| 132 private boolean _earlyEOF = false; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
133 |
| 826 | 134 /* ------------------------------------------------------------ */ |
| 135 public static AbstractHttpConnection getCurrentConnection() | |
| 136 { | |
| 137 return __currentConnection.get(); | |
| 138 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
139 |
| 826 | 140 /* ------------------------------------------------------------ */ |
| 141 protected static void setCurrentConnection(AbstractHttpConnection connection) | |
| 142 { | |
| 143 __currentConnection.set(connection); | |
| 144 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
145 |
| 826 | 146 /* ------------------------------------------------------------ */ |
| 147 public AbstractHttpConnection(Connector connector, EndPoint endpoint, Server server) | |
| 148 { | |
| 149 super(endpoint); | |
| 150 _uri = StringUtil.__UTF8.equals(URIUtil.__CHARSET)?new HttpURI():new EncodedHttpURI(URIUtil.__CHARSET); | |
| 151 _connector = connector; | |
| 152 HttpBuffers ab = (HttpBuffers)_connector; | |
| 153 _parser = newHttpParser(ab.getRequestBuffers(), endpoint, new RequestHandler()); | |
| 154 _requestFields = new HttpFields(); | |
| 155 _responseFields = new HttpFields(); | |
| 156 _request = new Request(this); | |
| 157 _response = new Response(this); | |
| 158 _generator = newHttpGenerator(ab.getResponseBuffers(), endpoint); | |
| 159 _server = server; | |
| 160 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
161 |
| 826 | 162 /* ------------------------------------------------------------ */ |
| 163 protected AbstractHttpConnection(Connector connector, EndPoint endpoint, Server server, | |
| 164 Parser parser, Generator generator, Request request) | |
| 165 { | |
| 166 super(endpoint); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
167 |
| 826 | 168 _uri = URIUtil.__CHARSET.equals(StringUtil.__UTF8)?new HttpURI():new EncodedHttpURI(URIUtil.__CHARSET); |
| 169 _connector = connector; | |
| 170 _parser = parser; | |
| 171 _requestFields = new HttpFields(); | |
| 172 _responseFields = new HttpFields(); | |
| 173 _request = request; | |
| 174 _response = new Response(this); | |
| 175 _generator = generator; | |
| 176 _server = server; | |
| 177 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
178 |
| 826 | 179 protected HttpParser newHttpParser(Buffers requestBuffers, EndPoint endpoint, HttpParser.EventHandler requestHandler) |
| 180 { | |
| 181 return new HttpParser(requestBuffers, endpoint, requestHandler); | |
| 182 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
183 |
| 826 | 184 protected HttpGenerator newHttpGenerator(Buffers responseBuffers, EndPoint endPoint) |
| 185 { | |
| 186 return new HttpGenerator(responseBuffers, endPoint); | |
| 187 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
188 |
| 826 | 189 /* ------------------------------------------------------------ */ |
| 190 /** | |
| 191 * @return the parser used by this connection | |
| 192 */ | |
| 193 public Parser getParser() | |
| 194 { | |
| 195 return _parser; | |
| 196 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
197 |
| 826 | 198 /* ------------------------------------------------------------ */ |
| 199 /** | |
| 200 * @return the number of requests handled by this connection | |
| 201 */ | |
| 202 public int getRequests() | |
| 203 { | |
| 204 return _requests; | |
| 205 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
206 |
| 826 | 207 /* ------------------------------------------------------------ */ |
| 208 public Server getServer() | |
| 209 { | |
| 210 return _server; | |
| 211 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
212 |
| 826 | 213 /* ------------------------------------------------------------ */ |
| 214 /** | |
| 215 * @return Returns the associatedObject. | |
| 216 */ | |
| 217 public Object getAssociatedObject() | |
| 218 { | |
| 219 return _associatedObject; | |
| 220 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
221 |
| 826 | 222 /* ------------------------------------------------------------ */ |
| 223 /** | |
| 224 * @param associatedObject The associatedObject to set. | |
| 225 */ | |
| 226 public void setAssociatedObject(Object associatedObject) | |
| 227 { | |
| 228 _associatedObject = associatedObject; | |
| 229 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
230 |
| 826 | 231 /* ------------------------------------------------------------ */ |
| 232 /** | |
| 233 * @return Returns the connector. | |
| 234 */ | |
| 235 public Connector getConnector() | |
| 236 { | |
| 237 return _connector; | |
| 238 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
239 |
| 826 | 240 /* ------------------------------------------------------------ */ |
| 241 /** | |
| 242 * @return Returns the requestFields. | |
| 243 */ | |
| 244 public HttpFields getRequestFields() | |
| 245 { | |
| 246 return _requestFields; | |
| 247 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
248 |
| 826 | 249 /* ------------------------------------------------------------ */ |
| 250 /** | |
| 251 * @return Returns the responseFields. | |
| 252 */ | |
| 253 public HttpFields getResponseFields() | |
| 254 { | |
| 255 return _responseFields; | |
| 256 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
257 |
| 826 | 258 /* ------------------------------------------------------------ */ |
| 259 /** | |
| 260 * Find out if the request supports CONFIDENTIAL security. | |
| 261 * @param request the incoming HTTP request | |
| 262 * @return the result of calling {@link Connector#isConfidential(Request)}, or false | |
| 263 * if there is no connector | |
| 264 */ | |
| 265 public boolean isConfidential(Request request) | |
| 266 { | |
| 267 return _connector != null && _connector.isConfidential(request); | |
| 268 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
269 |
| 826 | 270 /* ------------------------------------------------------------ */ |
| 271 /** | |
| 272 * @return Returns the request. | |
| 273 */ | |
| 274 public Request getRequest() | |
| 275 { | |
| 276 return _request; | |
| 277 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
278 |
| 826 | 279 /* ------------------------------------------------------------ */ |
| 280 /** | |
| 281 * @return Returns the response. | |
| 282 */ | |
| 283 public Response getResponse() | |
| 284 { | |
| 285 return _response; | |
| 286 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
287 |
| 826 | 288 /* ------------------------------------------------------------ */ |
| 289 /** | |
| 290 * Get the inputStream from the connection. | |
| 291 * <p> | |
| 292 * If the associated response has the Expect header set to 100 Continue, | |
| 293 * then accessing the input stream indicates that the handler/servlet | |
| 294 * is ready for the request body and thus a 100 Continue response is sent. | |
| 295 * | |
| 296 * @return The input stream for this connection. | |
| 297 * The stream will be created if it does not already exist. | |
| 298 * @throws IOException if the input stream cannot be retrieved | |
| 299 */ | |
| 300 public ServletInputStream getInputStream() throws IOException | |
| 301 { | |
| 302 // If the client is expecting 100 CONTINUE, then send it now. | |
| 303 if (_expect100Continue) | |
| 304 { | |
| 305 // is content missing? | |
| 306 if (((HttpParser)_parser).getHeaderBuffer()==null || ((HttpParser)_parser).getHeaderBuffer().length()<2) | |
| 307 { | |
| 308 if (_generator.isCommitted()) | |
| 309 throw new IllegalStateException("Committed before 100 Continues"); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
310 |
| 826 | 311 ((HttpGenerator)_generator).send1xx(HttpStatus.CONTINUE_100); |
| 312 } | |
| 313 _expect100Continue=false; | |
| 314 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
315 |
| 826 | 316 if (_in == null) |
| 317 _in = new HttpInput(AbstractHttpConnection.this); | |
| 318 return _in; | |
| 319 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
320 |
| 826 | 321 /* ------------------------------------------------------------ */ |
| 322 /** | |
| 323 * @return The output stream for this connection. The stream will be created if it does not already exist. | |
| 324 */ | |
| 325 public ServletOutputStream getOutputStream() | |
| 326 { | |
| 327 if (_out == null) | |
| 328 _out = new Output(); | |
| 329 return _out; | |
| 330 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
331 |
| 826 | 332 /* ------------------------------------------------------------ */ |
| 333 /** | |
| 334 * @param encoding the PrintWriter encoding | |
| 335 * @return A {@link PrintWriter} wrapping the {@link #getOutputStream output stream}. The writer is created if it | |
| 336 * does not already exist. | |
| 337 */ | |
| 338 public PrintWriter getPrintWriter(String encoding) | |
| 339 { | |
| 340 getOutputStream(); | |
| 341 if (_writer==null) | |
| 342 { | |
| 343 _writer=new OutputWriter(); | |
|
882
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
344 _printWriter = new PrintWriter(_writer) |
|
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
345 { |
|
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
346 public void close() |
| 826 | 347 { |
|
882
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
348 synchronized (lock) |
| 826 | 349 { |
|
882
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
350 try |
| 826 | 351 { |
|
882
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
352 out.close(); |
|
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
353 } |
|
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
354 catch (IOException e) |
|
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
355 { |
|
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
356 setError(); |
| 826 | 357 } |
| 358 } | |
|
882
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
359 } |
|
d850a5e6ff15
remove UncheckedPrintWriter
Franklin Schmidt <fschmidt@gmail.com>
parents:
878
diff
changeset
|
360 }; |
| 826 | 361 } |
| 362 _writer.setCharacterEncoding(encoding); | |
| 363 return _printWriter; | |
| 364 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
365 |
| 826 | 366 /* ------------------------------------------------------------ */ |
| 367 public boolean isResponseCommitted() | |
| 368 { | |
| 369 return _generator.isCommitted(); | |
| 370 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
371 |
| 826 | 372 /* ------------------------------------------------------------ */ |
| 373 public boolean isEarlyEOF() | |
| 374 { | |
| 375 return _earlyEOF; | |
| 376 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
377 |
| 826 | 378 /* ------------------------------------------------------------ */ |
| 379 public void reset() | |
| 380 { | |
| 381 _parser.reset(); | |
| 382 _parser.returnBuffers(); // TODO maybe only on unhandle | |
| 383 _requestFields.clear(); | |
| 384 _request.recycle(); | |
| 385 _generator.reset(); | |
| 386 _generator.returnBuffers();// TODO maybe only on unhandle | |
| 387 _responseFields.clear(); | |
| 388 _response.recycle(); | |
| 389 _uri.clear(); | |
| 390 _writer=null; | |
| 391 _earlyEOF = false; | |
| 392 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
393 |
| 826 | 394 /* ------------------------------------------------------------ */ |
| 395 protected void handleRequest() throws IOException | |
| 396 { | |
| 397 boolean error = false; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
398 |
| 826 | 399 String threadName=null; |
| 400 Throwable async_exception=null; | |
| 401 try | |
| 402 { | |
| 403 if (LOG.isDebugEnabled()) | |
| 404 { | |
| 405 threadName=Thread.currentThread().getName(); | |
| 406 Thread.currentThread().setName(threadName+" - "+_uri); | |
| 407 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
408 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
409 |
| 826 | 410 // Loop here to handle async request redispatches. |
| 411 // The loop is controlled by the call to async.unhandle in the | |
| 412 // finally block below. If call is from a non-blocking connector, | |
| 413 // then the unhandle will return false only if an async dispatch has | |
| 414 // already happened when unhandle is called. For a blocking connector, | |
| 415 // the wait for the asynchronous dispatch or timeout actually happens | |
| 416 // within the call to unhandle(). | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
417 |
| 826 | 418 final Server server=_server; |
| 419 boolean was_continuation=_request._async.isContinuation(); | |
| 420 boolean handling=_request._async.handling() && server!=null && server.isRunning(); | |
| 421 while (handling) | |
| 422 { | |
| 423 _request.setHandled(false); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
424 |
| 826 | 425 String info=null; |
| 426 try | |
| 427 { | |
| 428 _uri.getPort(); | |
| 429 String path = null; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
430 |
| 826 | 431 try |
| 432 { | |
| 433 path = _uri.getDecodedPath(); | |
| 434 } | |
| 435 catch (Exception e) | |
| 436 { | |
| 437 LOG.warn("Failed UTF-8 decode for request path, trying ISO-8859-1"); | |
| 438 LOG.trace("",e); | |
| 439 path = _uri.getDecodedPath(StringUtil.__ISO_8859_1); | |
| 440 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
441 |
| 826 | 442 info=URIUtil.canonicalPath(path); |
| 443 if (info==null && !_request.getMethod().equals(HttpMethods.CONNECT)) | |
| 444 { | |
| 445 if (path==null && _uri.getScheme()!=null && _uri.getHost()!=null) | |
| 446 { | |
| 447 info="/"; | |
| 448 _request.setRequestURI(""); | |
| 449 } | |
| 450 else | |
| 451 throw new HttpException(400); | |
| 452 } | |
| 453 _request.setPathInfo(info); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
454 |
| 826 | 455 if (_out!=null) |
| 456 _out.reopen(); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
457 |
| 826 | 458 if (_request._async.isInitial()) |
| 459 { | |
| 460 _request.setDispatcherType(DispatcherType.REQUEST); | |
| 461 _connector.customize(_endp, _request); | |
| 462 server.handle(this); | |
| 463 } | |
| 464 else | |
| 465 { | |
| 466 if (_request._async.isExpired()&&!was_continuation) | |
| 467 { | |
| 468 async_exception = (Throwable)_request.getAttribute(RequestDispatcher.ERROR_EXCEPTION); | |
| 469 _response.setStatus(500,async_exception==null?"Async Timeout":"Async Exception"); | |
| 470 _request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE,new Integer(500)); | |
| 471 _request.setAttribute(RequestDispatcher.ERROR_MESSAGE, _response.getReason()); | |
| 472 _request.setDispatcherType(DispatcherType.ERROR); | |
| 473 } | |
| 474 else | |
| 475 _request.setDispatcherType(DispatcherType.ASYNC); | |
| 476 server.handleAsync(this); | |
| 477 } | |
| 478 } | |
| 479 catch (ContinuationThrowable e) | |
| 480 { | |
| 481 LOG.trace("",e); | |
| 482 } | |
| 483 catch (EofException e) | |
| 484 { | |
| 485 async_exception=e; | |
| 486 LOG.debug("",e); | |
| 487 error=true; | |
| 488 _request.setHandled(true); | |
| 489 if (!_response.isCommitted()) | |
| 490 _generator.sendError(500, null, null, true); | |
| 491 } | |
| 492 catch (RuntimeIOException e) | |
| 493 { | |
| 494 async_exception=e; | |
| 495 LOG.debug("",e); | |
| 496 error=true; | |
| 497 _request.setHandled(true); | |
| 498 } | |
| 499 catch (HttpException e) | |
| 500 { | |
| 501 LOG.debug("",e); | |
| 502 error=true; | |
| 503 _request.setHandled(true); | |
| 504 _response.sendError(e.getStatus(), e.getReason()); | |
| 505 } | |
| 506 catch (Throwable e) | |
| 507 { | |
| 508 async_exception=e; | |
| 509 LOG.warn(String.valueOf(_uri),e); | |
| 510 error=true; | |
| 511 _request.setHandled(true); | |
| 512 _generator.sendError(info==null?400:500, null, null, true); | |
| 513 | |
| 514 } | |
| 515 finally | |
| 516 { | |
| 517 // Complete async requests | |
| 518 if (error && _request.isAsyncStarted()) | |
| 519 _request.getAsyncContinuation().errorComplete(); | |
| 520 | |
| 521 was_continuation=_request._async.isContinuation(); | |
| 522 handling = !_request._async.unhandle() && server.isRunning() && _server!=null; | |
| 523 } | |
| 524 } | |
| 525 } | |
| 526 finally | |
| 527 { | |
| 528 if (threadName!=null) | |
| 529 Thread.currentThread().setName(threadName); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
530 |
| 826 | 531 if (_request._async.isUncompleted()) |
| 532 { | |
| 533 | |
| 534 _request._async.doComplete(async_exception); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
535 |
| 826 | 536 if (_expect100Continue) |
| 537 { | |
| 538 LOG.debug("100 continues not sent"); | |
| 539 // We didn't send 100 continues, but the latest interpretation | |
| 540 // of the spec (see httpbis) is that the client will either | |
| 541 // send the body anyway, or close. So we no longer need to | |
| 542 // do anything special here other than make the connection not persistent | |
| 543 _expect100Continue = false; | |
| 544 if (!_response.isCommitted()) | |
| 545 _generator.setPersistent(false); | |
| 546 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
547 |
| 826 | 548 if(_endp.isOpen()) |
| 549 { | |
| 550 if (error) | |
| 551 { | |
| 552 _endp.shutdownOutput(); | |
| 553 _generator.setPersistent(false); | |
| 554 if (!_generator.isComplete()) | |
| 555 _response.complete(); | |
| 556 } | |
| 557 else | |
| 558 { | |
| 559 if (!_response.isCommitted() && !_request.isHandled()) | |
| 560 _response.sendError(HttpServletResponse.SC_NOT_FOUND); | |
| 561 _response.complete(); | |
| 562 if (_generator.isPersistent()) | |
| 563 _connector.persist(_endp); | |
| 564 } | |
| 565 } | |
| 566 else | |
| 567 { | |
| 568 _response.complete(); | |
| 569 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
570 |
| 826 | 571 _request.setHandled(true); |
| 572 } | |
| 573 } | |
| 574 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
575 |
| 826 | 576 /* ------------------------------------------------------------ */ |
| 577 public abstract Connection handle() throws IOException; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
578 |
| 826 | 579 /* ------------------------------------------------------------ */ |
| 580 public void commitResponse(boolean last) throws IOException | |
| 581 { | |
| 582 if (!_generator.isCommitted()) | |
| 583 { | |
| 584 _generator.setResponse(_response.getStatus(), _response.getReason()); | |
| 585 try | |
| 586 { | |
| 587 // If the client was expecting 100 continues, but we sent something | |
| 588 // else, then we need to close the connection | |
| 589 if (_expect100Continue && _response.getStatus()!=100) | |
| 590 _generator.setPersistent(false); | |
| 591 _generator.completeHeader(_responseFields, last); | |
| 592 } | |
| 593 catch(RuntimeException e) | |
| 594 { | |
| 595 LOG.warn("header full: " + e); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
596 |
| 826 | 597 _response.reset(); |
| 598 _generator.reset(); | |
| 599 _generator.setResponse(HttpStatus.INTERNAL_SERVER_ERROR_500,null); | |
| 600 _generator.completeHeader(_responseFields,Generator.LAST); | |
| 601 _generator.complete(); | |
| 602 throw new HttpException(HttpStatus.INTERNAL_SERVER_ERROR_500); | |
| 603 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
604 |
| 826 | 605 } |
| 606 if (last) | |
| 607 _generator.complete(); | |
| 608 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
609 |
| 826 | 610 /* ------------------------------------------------------------ */ |
| 611 public void completeResponse() throws IOException | |
| 612 { | |
| 613 if (!_generator.isCommitted()) | |
| 614 { | |
| 615 _generator.setResponse(_response.getStatus(), _response.getReason()); | |
| 616 try | |
| 617 { | |
| 618 _generator.completeHeader(_responseFields, Generator.LAST); | |
| 619 } | |
| 620 catch(RuntimeException e) | |
| 621 { | |
| 622 LOG.warn("header full: "+e); | |
| 623 LOG.debug("",e); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
624 |
| 826 | 625 _response.reset(); |
| 626 _generator.reset(); | |
| 627 _generator.setResponse(HttpStatus.INTERNAL_SERVER_ERROR_500,null); | |
| 628 _generator.completeHeader(_responseFields,Generator.LAST); | |
| 629 _generator.complete(); | |
| 630 throw new HttpException(HttpStatus.INTERNAL_SERVER_ERROR_500); | |
| 631 } | |
| 632 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
633 |
| 826 | 634 _generator.complete(); |
| 635 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
636 |
| 826 | 637 /* ------------------------------------------------------------ */ |
| 638 public void flushResponse() throws IOException | |
| 639 { | |
| 640 try | |
| 641 { | |
| 642 commitResponse(Generator.MORE); | |
| 643 _generator.flushBuffer(); | |
| 644 } | |
| 645 catch(IOException e) | |
| 646 { | |
| 647 throw (e instanceof EofException) ? e:new EofException(e); | |
| 648 } | |
| 649 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
650 |
| 826 | 651 /* ------------------------------------------------------------ */ |
| 652 public Generator getGenerator() | |
| 653 { | |
| 654 return _generator; | |
| 655 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
656 |
| 826 | 657 /* ------------------------------------------------------------ */ |
| 658 public boolean isIncluding() | |
| 659 { | |
| 660 return _include>0; | |
| 661 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
662 |
| 826 | 663 /* ------------------------------------------------------------ */ |
| 664 public void include() | |
| 665 { | |
| 666 _include++; | |
| 667 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
668 |
| 826 | 669 /* ------------------------------------------------------------ */ |
| 670 public void included() | |
| 671 { | |
| 672 _include--; | |
| 673 if (_out!=null) | |
| 674 _out.reopen(); | |
| 675 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
676 |
| 826 | 677 /* ------------------------------------------------------------ */ |
| 678 public boolean isIdle() | |
| 679 { | |
| 680 return _generator.isIdle() && (_parser.isIdle() || _delayedHandling); | |
| 681 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
682 |
| 826 | 683 /* ------------------------------------------------------------ */ |
| 684 /** | |
| 685 * @see org.eclipse.jetty.io.Connection#isSuspended() | |
| 686 */ | |
| 687 public boolean isSuspended() | |
| 688 { | |
| 689 return _request.getAsyncContinuation().isSuspended(); | |
| 690 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
691 |
| 826 | 692 /* ------------------------------------------------------------ */ |
| 693 public void onClose() | |
| 694 { | |
| 695 LOG.debug("closed {}",this); | |
| 696 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
697 |
| 826 | 698 /* ------------------------------------------------------------ */ |
| 699 public boolean isExpecting100Continues() | |
| 700 { | |
| 701 return _expect100Continue; | |
| 702 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
703 |
| 826 | 704 /* ------------------------------------------------------------ */ |
| 705 public boolean isExpecting102Processing() | |
| 706 { | |
| 707 return _expect102Processing; | |
| 708 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
709 |
| 826 | 710 /* ------------------------------------------------------------ */ |
| 711 public int getMaxIdleTime() | |
| 712 { | |
| 713 if (_connector.isLowResources() && _endp.getMaxIdleTime()==_connector.getMaxIdleTime()) | |
| 714 return _connector.getLowResourceMaxIdleTime(); | |
| 715 if (_endp.getMaxIdleTime()>0) | |
| 716 return _endp.getMaxIdleTime(); | |
| 717 return _connector.getMaxIdleTime(); | |
| 718 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
719 |
| 826 | 720 /* ------------------------------------------------------------ */ |
| 721 public String toString() | |
| 722 { | |
| 723 return String.format("%s,g=%s,p=%s,r=%d", | |
| 724 super.toString(), | |
| 725 _generator, | |
| 726 _parser, | |
| 727 _requests); | |
| 728 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
729 |
| 826 | 730 /* ------------------------------------------------------------ */ |
| 731 protected void startRequest(Buffer method, Buffer uri, Buffer version) throws IOException | |
| 732 { | |
| 733 uri=uri.asImmutableBuffer(); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
734 |
| 826 | 735 _host = false; |
| 736 _expect = false; | |
| 737 _expect100Continue=false; | |
| 738 _expect102Processing=false; | |
| 739 _delayedHandling=false; | |
| 740 _charset=null; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
741 |
| 826 | 742 if(_request.getTimeStamp()==0) |
| 743 _request.setTimeStamp(System.currentTimeMillis()); | |
| 744 _request.setMethod(method.toString()); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
745 |
| 826 | 746 try |
| 747 { | |
| 748 _head=false; | |
| 749 switch (HttpMethods.CACHE.getOrdinal(method)) | |
| 750 { | |
| 751 case HttpMethods.CONNECT_ORDINAL: | |
| 752 _uri.parseConnect(uri.array(), uri.getIndex(), uri.length()); | |
| 753 break; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
754 |
| 826 | 755 case HttpMethods.HEAD_ORDINAL: |
| 756 _head=true; | |
| 757 _uri.parse(uri.array(), uri.getIndex(), uri.length()); | |
| 758 break; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
759 |
| 826 | 760 default: |
| 761 _uri.parse(uri.array(), uri.getIndex(), uri.length()); | |
| 762 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
763 |
| 826 | 764 _request.setUri(_uri); |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
765 |
| 826 | 766 if (version==null) |
| 767 { | |
| 768 _request.setProtocol(HttpVersions.HTTP_0_9); | |
| 769 _version=HttpVersions.HTTP_0_9_ORDINAL; | |
| 770 } | |
| 771 else | |
| 772 { | |
| 773 version= HttpVersions.CACHE.get(version); | |
| 774 if (version==null) | |
| 775 throw new HttpException(HttpStatus.BAD_REQUEST_400,null); | |
| 776 _version = HttpVersions.CACHE.getOrdinal(version); | |
| 777 if (_version <= 0) _version = HttpVersions.HTTP_1_0_ORDINAL; | |
| 778 _request.setProtocol(version.toString()); | |
| 779 } | |
| 780 } | |
| 781 catch (Exception e) | |
| 782 { | |
| 783 LOG.debug("",e); | |
| 784 if (e instanceof HttpException) | |
| 785 throw (HttpException)e; | |
| 786 throw new HttpException(HttpStatus.BAD_REQUEST_400,null,e); | |
| 787 } | |
| 788 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
789 |
| 826 | 790 /* ------------------------------------------------------------ */ |
| 791 protected void parsedHeader(Buffer name, Buffer value) throws IOException | |
| 792 { | |
| 793 int ho = HttpHeaders.CACHE.getOrdinal(name); | |
| 794 switch (ho) | |
| 795 { | |
| 796 case HttpHeaders.HOST_ORDINAL: | |
| 797 // TODO check if host matched a host in the URI. | |
| 798 _host = true; | |
| 799 break; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
800 |
| 826 | 801 case HttpHeaders.EXPECT_ORDINAL: |
| 802 if (_version>=HttpVersions.HTTP_1_1_ORDINAL) | |
| 803 { | |
| 804 value = HttpHeaderValues.CACHE.lookup(value); | |
| 805 switch(HttpHeaderValues.CACHE.getOrdinal(value)) | |
| 806 { | |
| 807 case HttpHeaderValues.CONTINUE_ORDINAL: | |
| 808 _expect100Continue=_generator instanceof HttpGenerator; | |
| 809 break; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
810 |
| 826 | 811 case HttpHeaderValues.PROCESSING_ORDINAL: |
| 812 _expect102Processing=_generator instanceof HttpGenerator; | |
| 813 break; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
814 |
| 826 | 815 default: |
| 816 String[] values = value.toString().split(","); | |
| 817 for (int i=0;values!=null && i<values.length;i++) | |
| 818 { | |
| 819 CachedBuffer cb=HttpHeaderValues.CACHE.get(values[i].trim()); | |
| 820 if (cb==null) | |
| 821 _expect=true; | |
| 822 else | |
| 823 { | |
| 824 switch(cb.getOrdinal()) | |
| 825 { | |
| 826 case HttpHeaderValues.CONTINUE_ORDINAL: | |
| 827 _expect100Continue=_generator instanceof HttpGenerator; | |
| 828 break; | |
| 829 case HttpHeaderValues.PROCESSING_ORDINAL: | |
| 830 _expect102Processing=_generator instanceof HttpGenerator; | |
| 831 break; | |
| 832 default: | |
| 833 _expect=true; | |
| 834 } | |
| 835 } | |
| 836 } | |
| 837 } | |
| 838 } | |
| 839 break; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
840 |
| 826 | 841 case HttpHeaders.ACCEPT_ENCODING_ORDINAL: |
| 842 case HttpHeaders.USER_AGENT_ORDINAL: | |
| 843 value = HttpHeaderValues.CACHE.lookup(value); | |
| 844 break; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
845 |
| 826 | 846 case HttpHeaders.CONTENT_TYPE_ORDINAL: |
| 847 value = MimeTypes.CACHE.lookup(value); | |
| 848 _charset=MimeTypes.getCharsetFromContentType(value); | |
| 849 break; | |
| 850 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
851 |
| 826 | 852 _requestFields.add(name, value); |
| 853 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
854 |
| 826 | 855 /* ------------------------------------------------------------ */ |
| 856 protected void headerComplete() throws IOException | |
| 857 { | |
| 858 // Handle idle race | |
| 859 if (_endp.isOutputShutdown()) | |
| 860 { | |
| 861 _endp.close(); | |
| 862 return; | |
| 863 } | |
| 864 | |
| 865 _requests++; | |
| 866 _generator.setVersion(_version); | |
| 867 switch (_version) | |
| 868 { | |
| 869 case HttpVersions.HTTP_0_9_ORDINAL: | |
| 870 break; | |
| 871 case HttpVersions.HTTP_1_0_ORDINAL: | |
| 872 _generator.setHead(_head); | |
| 873 if (_parser.isPersistent()) | |
| 874 { | |
| 875 _responseFields.add(HttpHeaders.CONNECTION_BUFFER, HttpHeaderValues.KEEP_ALIVE_BUFFER); | |
| 876 _generator.setPersistent(true); | |
| 877 } | |
| 878 else if (HttpMethods.CONNECT.equals(_request.getMethod())) | |
| 879 { | |
| 880 _generator.setPersistent(true); | |
| 881 _parser.setPersistent(true); | |
| 882 } | |
| 883 break; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
884 |
| 826 | 885 case HttpVersions.HTTP_1_1_ORDINAL: |
| 886 _generator.setHead(_head); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
887 |
| 826 | 888 if (!_parser.isPersistent()) |
| 889 { | |
| 890 _responseFields.add(HttpHeaders.CONNECTION_BUFFER,HttpHeaderValues.CLOSE_BUFFER); | |
| 891 _generator.setPersistent(false); | |
| 892 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
893 |
| 826 | 894 if (!_host) |
| 895 { | |
| 896 LOG.debug("!host {}",this); | |
| 897 _generator.setResponse(HttpStatus.BAD_REQUEST_400, null); | |
| 898 _responseFields.put(HttpHeaders.CONNECTION_BUFFER, HttpHeaderValues.CLOSE_BUFFER); | |
| 899 _generator.completeHeader(_responseFields, true); | |
| 900 _generator.complete(); | |
| 901 return; | |
| 902 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
903 |
| 826 | 904 if (_expect) |
| 905 { | |
| 906 LOG.debug("!expectation {}",this); | |
| 907 _generator.setResponse(HttpStatus.EXPECTATION_FAILED_417, null); | |
| 908 _responseFields.put(HttpHeaders.CONNECTION_BUFFER, HttpHeaderValues.CLOSE_BUFFER); | |
| 909 _generator.completeHeader(_responseFields, true); | |
| 910 _generator.complete(); | |
| 911 return; | |
| 912 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
913 |
| 826 | 914 break; |
| 915 default: | |
| 916 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
917 |
| 826 | 918 if(_charset!=null) |
| 919 _request.setCharacterEncodingUnchecked(_charset); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
920 |
| 826 | 921 // Either handle now or wait for first content |
| 922 if ((((HttpParser)_parser).getContentLength()<=0 && !((HttpParser)_parser).isChunking())||_expect100Continue) | |
| 923 handleRequest(); | |
| 924 else | |
| 925 _delayedHandling=true; | |
| 926 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
927 |
| 826 | 928 /* ------------------------------------------------------------ */ |
| 929 protected void content(Buffer buffer) throws IOException | |
| 930 { | |
| 931 if (_delayedHandling) | |
| 932 { | |
| 933 _delayedHandling=false; | |
| 934 handleRequest(); | |
| 935 } | |
| 936 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
937 |
| 826 | 938 /* ------------------------------------------------------------ */ |
| 939 public void messageComplete(long contentLength) throws IOException | |
| 940 { | |
| 941 if (_delayedHandling) | |
| 942 { | |
| 943 _delayedHandling=false; | |
| 944 handleRequest(); | |
| 945 } | |
| 946 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
947 |
| 826 | 948 /* ------------------------------------------------------------ */ |
| 949 public void earlyEOF() | |
| 950 { | |
| 951 _earlyEOF = true; | |
| 952 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
953 |
| 826 | 954 /* ------------------------------------------------------------ */ |
| 955 /* ------------------------------------------------------------ */ | |
| 956 /* ------------------------------------------------------------ */ | |
| 957 private class RequestHandler extends HttpParser.EventHandler | |
| 958 { | |
| 959 /* | |
| 960 * | |
| 961 * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#startRequest(org.eclipse.io.Buffer, | |
| 962 * org.eclipse.io.Buffer, org.eclipse.io.Buffer) | |
| 963 */ | |
| 964 @Override | |
| 965 public void startRequest(Buffer method, Buffer uri, Buffer version) throws IOException | |
| 966 { | |
| 967 AbstractHttpConnection.this.startRequest(method, uri, version); | |
| 968 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
969 |
| 826 | 970 /* |
| 971 * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#parsedHeaderValue(org.eclipse.io.Buffer) | |
| 972 */ | |
| 973 @Override | |
| 974 public void parsedHeader(Buffer name, Buffer value) throws IOException | |
| 975 { | |
| 976 AbstractHttpConnection.this.parsedHeader(name, value); | |
| 977 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
978 |
| 826 | 979 /* |
| 980 * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#headerComplete() | |
| 981 */ | |
| 982 @Override | |
| 983 public void headerComplete() throws IOException | |
| 984 { | |
| 985 AbstractHttpConnection.this.headerComplete(); | |
| 986 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
987 |
| 826 | 988 /* ------------------------------------------------------------ */ |
| 989 /* | |
| 990 * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#content(int, org.eclipse.io.Buffer) | |
| 991 */ | |
| 992 @Override | |
| 993 public void content(Buffer ref) throws IOException | |
| 994 { | |
| 995 AbstractHttpConnection.this.content(ref); | |
| 996 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
997 |
| 826 | 998 /* ------------------------------------------------------------ */ |
| 999 /* | |
| 1000 * (non-Javadoc) | |
| 1001 * | |
| 1002 * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#messageComplete(int) | |
| 1003 */ | |
| 1004 @Override | |
| 1005 public void messageComplete(long contentLength) throws IOException | |
| 1006 { | |
| 1007 AbstractHttpConnection.this.messageComplete(contentLength); | |
| 1008 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1009 |
| 826 | 1010 /* ------------------------------------------------------------ */ |
| 1011 /* | |
| 1012 * (non-Javadoc) | |
| 1013 * | |
| 1014 * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#startResponse(org.eclipse.io.Buffer, int, | |
| 1015 * org.eclipse.io.Buffer) | |
| 1016 */ | |
| 1017 @Override | |
| 1018 public void startResponse(Buffer version, int status, Buffer reason) | |
| 1019 { | |
| 1020 if (LOG.isDebugEnabled()) | |
| 1021 LOG.debug("Bad request!: "+version+" "+status+" "+reason); | |
| 1022 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1023 |
| 826 | 1024 /* ------------------------------------------------------------ */ |
| 1025 /* | |
| 1026 * (non-Javadoc) | |
| 1027 * | |
| 1028 * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#earlyEOF() | |
| 1029 */ | |
| 1030 @Override | |
| 1031 public void earlyEOF() | |
| 1032 { | |
| 1033 AbstractHttpConnection.this.earlyEOF(); | |
| 1034 } | |
| 1035 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1036 |
| 826 | 1037 /* ------------------------------------------------------------ */ |
| 1038 /* ------------------------------------------------------------ */ | |
| 1039 /* ------------------------------------------------------------ */ | |
| 1040 public class Output extends HttpOutput | |
| 1041 { | |
| 1042 Output() | |
| 1043 { | |
| 1044 super(AbstractHttpConnection.this); | |
| 1045 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1046 |
| 826 | 1047 /* ------------------------------------------------------------ */ |
| 1048 /* | |
| 1049 * @see java.io.OutputStream#close() | |
| 1050 */ | |
| 1051 @Override | |
| 1052 public void close() throws IOException | |
| 1053 { | |
| 1054 if (isClosed()) | |
| 1055 return; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1056 |
| 826 | 1057 if (!isIncluding() && !super._generator.isCommitted()) |
| 1058 commitResponse(Generator.LAST); | |
| 1059 else | |
| 1060 flushResponse(); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1061 |
| 826 | 1062 super.close(); |
| 1063 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1064 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1065 |
| 826 | 1066 /* ------------------------------------------------------------ */ |
| 1067 /* | |
| 1068 * @see java.io.OutputStream#flush() | |
| 1069 */ | |
| 1070 @Override | |
| 1071 public void flush() throws IOException | |
| 1072 { | |
| 1073 if (!super._generator.isCommitted()) | |
| 1074 commitResponse(Generator.MORE); | |
| 1075 super.flush(); | |
| 1076 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1077 |
| 826 | 1078 /* ------------------------------------------------------------ */ |
| 1079 /* | |
| 1080 * @see javax.servlet.ServletOutputStream#print(java.lang.String) | |
| 1081 */ | |
| 1082 @Override | |
| 1083 public void print(String s) throws IOException | |
| 1084 { | |
| 1085 if (isClosed()) | |
| 1086 throw new IOException("Closed"); | |
| 1087 PrintWriter writer=getPrintWriter(null); | |
| 1088 writer.print(s); | |
| 1089 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1090 |
| 826 | 1091 /* ------------------------------------------------------------ */ |
| 1092 public void sendResponse(Buffer response) throws IOException | |
| 1093 { | |
| 1094 ((HttpGenerator)super._generator).sendResponse(response); | |
| 1095 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1096 |
| 826 | 1097 /* ------------------------------------------------------------ */ |
| 1098 public void sendContent(Object content) throws IOException | |
| 1099 { | |
| 1100 Resource resource=null; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1101 |
| 826 | 1102 if (isClosed()) |
| 1103 throw new IOException("Closed"); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1104 |
| 826 | 1105 if (super._generator.isWritten()) |
| 1106 throw new IllegalStateException("!empty"); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1107 |
| 826 | 1108 if (content instanceof Resource) |
| 1109 { | |
| 1110 resource=(Resource)content; | |
| 1111 _responseFields.putDateField(HttpHeaders.LAST_MODIFIED_BUFFER, resource.lastModified()); | |
| 1112 content=resource.getInputStream(); | |
| 1113 } | |
| 1114 | |
| 1115 // Process content. | |
| 1116 if (content instanceof Buffer) | |
| 1117 { | |
| 1118 super._generator.addContent((Buffer) content, Generator.LAST); | |
| 1119 commitResponse(Generator.LAST); | |
| 1120 } | |
| 1121 else if (content instanceof InputStream) | |
| 1122 { | |
| 1123 InputStream in = (InputStream)content; | |
| 1124 | |
| 1125 try | |
| 1126 { | |
| 1127 int max = super._generator.prepareUncheckedAddContent(); | |
| 1128 Buffer buffer = super._generator.getUncheckedBuffer(); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1129 |
| 826 | 1130 int len=buffer.readFrom(in,max); |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1131 |
| 826 | 1132 while (len>=0) |
| 1133 { | |
| 1134 super._generator.completeUncheckedAddContent(); | |
| 1135 _out.flush(); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1136 |
| 826 | 1137 max = super._generator.prepareUncheckedAddContent(); |
| 1138 buffer = super._generator.getUncheckedBuffer(); | |
| 1139 len=buffer.readFrom(in,max); | |
| 1140 } | |
| 1141 super._generator.completeUncheckedAddContent(); | |
| 1142 _out.flush(); | |
| 1143 } | |
| 1144 finally | |
| 1145 { | |
| 1146 if (resource!=null) | |
| 1147 resource.release(); | |
| 1148 else | |
| 1149 in.close(); | |
| 1150 } | |
| 1151 } | |
| 1152 else | |
| 1153 throw new IllegalArgumentException("unknown content type?"); | |
|
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 |
| 826 | 1156 } |
| 1157 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1158 |
| 826 | 1159 /* ------------------------------------------------------------ */ |
| 1160 /* ------------------------------------------------------------ */ | |
| 1161 /* ------------------------------------------------------------ */ | |
| 1162 public class OutputWriter extends HttpWriter | |
| 1163 { | |
| 1164 OutputWriter() | |
| 1165 { | |
| 1166 super(AbstractHttpConnection.this._out); | |
| 1167 } | |
| 1168 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1169 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1170 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1171 } |
