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