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