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