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