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