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