Mercurial Hosting > luan
annotate src/org/eclipse/jetty/http/AbstractGenerator.java @ 1031:921c25a05eaa
remove Buffer.asReadOnlyBuffer()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 03 Nov 2016 02:04:40 -0600 |
parents | 8c13b9224cff |
children | 563458c4dc93 |
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.http; |
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 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 import org.eclipse.jetty.io.Buffer; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 import org.eclipse.jetty.io.Buffers; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 import org.eclipse.jetty.io.ByteArrayBuffer; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 import org.eclipse.jetty.io.EndPoint; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 import org.eclipse.jetty.io.EofException; |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
28 import org.slf4j.Logger; |
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
29 import org.slf4j.LoggerFactory; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 |
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 /** |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 * Abstract Generator. Builds HTTP Messages. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
35 * Currently this class uses a system parameter "jetty.direct.writers" to control |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 * two optional writer to byte conversions. buffer.writers=true will probably be |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
37 * faster, but will consume more memory. This option is just for testing and tuning. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
39 */ |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
40 abstract class AbstractGenerator |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 { |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
42 private static final Logger LOG = LoggerFactory.getLogger(AbstractGenerator.class); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
43 |
982 | 44 public static final boolean LAST=true; |
45 public static final boolean MORE=false; | |
46 | |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
47 // states |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
48 final static int STATE_HEADER = 0; |
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
49 final static int STATE_CONTENT = 2; |
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
50 final static int STATE_FLUSHING = 3; |
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
51 final static int STATE_END = 4; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
52 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
53 // data |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
54 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
55 final Buffers _buffers; // source of buffers |
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
56 final EndPoint _endp; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
57 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
58 int _state = STATE_HEADER; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
59 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
60 int _status = 0; |
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
61 int _version = HttpVersions.HTTP_1_1_ORDINAL; |
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
62 Buffer _reason; |
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
63 Buffer _method; |
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
64 String _uri; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
65 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
66 long _contentWritten = 0; |
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
67 long _contentLength = HttpTokens.UNKNOWN_CONTENT; |
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
68 boolean _last = false; |
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
69 boolean _head = false; |
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
70 boolean _noContent = false; |
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
71 Boolean _persistent = null; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
72 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
73 Buffer _header; // Buffer for HTTP header (and maybe small _content) |
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
74 Buffer _buffer; // Buffer for copy of passed _content |
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
75 Buffer _content; // Buffer passed to addContent |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
76 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
77 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
78 /* ------------------------------------------------------------------------------- */ |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
79 /** |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
80 * Constructor. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
81 * |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
82 * @param buffers buffer pool |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
83 * @param io the end point |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
84 */ |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
85 AbstractGenerator(Buffers buffers, EndPoint io) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
86 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
87 this._buffers = buffers; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
88 this._endp = io; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
89 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
90 |
982 | 91 /* ------------------------------------------------------------ */ |
92 /** | |
93 * Add content. | |
94 * | |
95 * @param content | |
96 * @param last | |
97 * @throws IllegalArgumentException if <code>content</code> is {@link Buffer#isImmutable immutable}. | |
98 * @throws IllegalStateException If the request is not expecting any more content, | |
99 * or if the buffers are full and cannot be flushed. | |
100 * @throws IOException if there is a problem flushing the buffers. | |
101 */ | |
102 public abstract void addContent(Buffer content, boolean last) throws IOException; | |
103 | |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
104 abstract boolean isRequest(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
105 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
106 public final boolean isOpen() |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
107 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
108 return _endp.isOpen(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
109 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
110 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
111 public void reset() |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
112 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
113 _state = STATE_HEADER; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
114 _status = 0; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
115 _version = HttpVersions.HTTP_1_1_ORDINAL; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
116 _reason = null; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
117 _last = false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
118 _head = false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
119 _noContent=false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
120 _persistent = null; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
121 _contentWritten = 0; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
122 _contentLength = HttpTokens.UNKNOWN_CONTENT; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
123 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
124 _content = null; |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
125 _method = null; |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
126 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
127 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
128 public final void returnBuffers() |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
129 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
130 if (_buffer!=null && _buffer.length()==0) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
131 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
132 _buffer=null; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
133 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
134 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
135 if (_header!=null && _header.length()==0) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
136 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
137 _header=null; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
138 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
139 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
140 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
141 public final void resetBuffer() |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
142 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
143 if(_state>=STATE_FLUSHING) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
144 throw new IllegalStateException("Flushed"); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
145 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
146 _last = false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
147 _persistent=null; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
148 _contentWritten = 0; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
149 _contentLength = HttpTokens.UNKNOWN_CONTENT; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
150 _content=null; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
151 if (_buffer!=null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
152 _buffer.clear(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
153 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
154 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
155 /* ------------------------------------------------------------ */ |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
156 /** |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
157 * @return Returns the contentBufferSize. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
158 */ |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
159 public final int getContentBufferSize() |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
160 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
161 if (_buffer==null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
162 _buffer=_buffers.getBuffer(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
163 return _buffer.capacity(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
164 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
165 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
166 public final Buffer getUncheckedBuffer() |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
167 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
168 return _buffer; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
169 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
170 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
171 public final boolean isComplete() |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
172 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
173 return _state == STATE_END; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
174 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
175 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
176 public final boolean isIdle() |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
177 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
178 return _state == STATE_HEADER && _method==null && _status==0; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
179 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
180 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
181 public final boolean isCommitted() |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
182 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
183 return _state != STATE_HEADER; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
184 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
185 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
186 public final void setContentLength(long value) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
187 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
188 if (value<0) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
189 _contentLength=HttpTokens.UNKNOWN_CONTENT; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
190 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
191 _contentLength=value; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
192 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
193 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
194 public final void setHead(boolean head) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
195 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
196 _head = head; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
197 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
198 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
199 /* ------------------------------------------------------------ */ |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
200 /** |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
201 * @return <code>false</code> if the connection should be closed after a request has been read, |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
202 * <code>true</code> if it should be used for additional requests. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
203 */ |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
204 public final boolean isPersistent() |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
205 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
206 return _persistent!=null |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
207 ?_persistent.booleanValue() |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
208 :(isRequest()?true:_version>HttpVersions.HTTP_1_0_ORDINAL); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
209 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
210 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
211 public final void setPersistent(boolean persistent) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
212 { |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
213 _persistent = persistent; |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
214 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
215 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
216 /* ------------------------------------------------------------ */ |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
217 /** |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
218 * @param version The version of the client the response is being sent to (NB. Not the version |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
219 * in the response, which is the version of the server). |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
220 */ |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
221 public final void setVersion(int version) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
222 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
223 if (_state != STATE_HEADER) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
224 throw new IllegalStateException("STATE!=START "+_state); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
225 _version = version; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
226 if (_version==HttpVersions.HTTP_0_9_ORDINAL && _method!=null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
227 _noContent=true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
228 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
229 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
230 /* ------------------------------------------------------------ */ |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
231 /** |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
232 * @param status The status code to send. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
233 * @param reason the status message to send. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
234 */ |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
235 public final void setResponse(int status, String reason) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
236 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
237 if (_state != STATE_HEADER) throw new IllegalStateException("STATE!=START"); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
238 _method=null; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
239 _status = status; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
240 if (reason!=null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
241 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
242 int len=reason.length(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
243 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
244 // TODO don't hard code |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
245 if (len>1024) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
246 len=1024; |
1031
921c25a05eaa
remove Buffer.asReadOnlyBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1016
diff
changeset
|
247 _reason = new ByteArrayBuffer(len); |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
248 for (int i=0;i<len;i++) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
249 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
250 char ch = reason.charAt(i); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
251 if (ch!='\r'&&ch!='\n') |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
252 _reason.put((byte)ch); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
253 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
254 _reason.put((byte)' '); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
255 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
256 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
257 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
258 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
259 public final void completeUncheckedAddContent() |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
260 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
261 if (_noContent) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
262 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
263 if(_buffer!=null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
264 _buffer.clear(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
265 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
266 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
267 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
268 _contentWritten+=_buffer.length(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
269 if (_head) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
270 _buffer.clear(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
271 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
272 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
273 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
274 public boolean isBufferFull() |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
275 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
276 if (_buffer != null && _buffer.space()==0) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
277 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
278 if (_buffer.length()==0 && !_buffer.isImmutable()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
279 _buffer.compact(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
280 return _buffer.space()==0; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
281 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
282 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
283 return _content!=null && _content.length()>0; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
284 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
285 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
286 public final boolean isWritten() |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
287 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
288 return _contentWritten>0; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
289 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
290 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
291 public final boolean isAllContentWritten() |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
292 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
293 return _contentLength>=0 && _contentWritten>=_contentLength; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
294 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
295 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
296 public abstract void completeHeader(HttpFields fields, boolean allContentAdded) throws IOException; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
297 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
298 /* ------------------------------------------------------------ */ |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
299 /** |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
300 * Complete the message. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
301 * |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
302 * @throws IOException |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
303 */ |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
304 public void complete() throws IOException |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
305 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
306 if (_state == STATE_HEADER) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
307 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
308 throw new IllegalStateException("State==HEADER"); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
309 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
310 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
311 if (_contentLength >= 0 && _contentLength != _contentWritten && !_head) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
312 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
313 if (LOG.isDebugEnabled()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
314 LOG.debug("ContentLength written=="+_contentWritten+" != contentLength=="+_contentLength); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
315 _persistent = false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
316 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
317 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
318 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
319 public abstract int flushBuffer() throws IOException; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
320 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
321 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
322 public final void flush(long maxIdleTime) throws IOException |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
323 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
324 // block until everything is flushed |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
325 long now=System.currentTimeMillis(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
326 long end=now+maxIdleTime; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
327 Buffer content = _content; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
328 Buffer buffer = _buffer; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
329 if (content!=null && content.length()>0 || buffer!=null && buffer.length()>0 || isBufferFull()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
330 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
331 flushBuffer(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
332 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
333 while (now<end && (content!=null && content.length()>0 ||buffer!=null && buffer.length()>0) && _endp.isOpen()&& !_endp.isOutputShutdown()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
334 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
335 blockForOutput(end-now); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
336 now=System.currentTimeMillis(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
337 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
338 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
339 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
340 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
341 /* ------------------------------------------------------------ */ |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
342 /** |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
343 * Utility method to send an error response. If the builder is not committed, this call is |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
344 * equivalent to a setResponse, addContent and complete call. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
345 * |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
346 * @param code The error code |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
347 * @param reason The error reason |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
348 * @param content Contents of the error page |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
349 * @param close True if the connection should be closed |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
350 * @throws IOException if there is a problem flushing the response |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
351 */ |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
352 public final void sendError(int code, String reason, String content, boolean close) throws IOException |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
353 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
354 if (close) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
355 _persistent=false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
356 if (isCommitted()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
357 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
358 LOG.debug("sendError on committed: {} {}",code,reason); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
359 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
360 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
361 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
362 LOG.debug("sendError: {} {}",code,reason); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
363 setResponse(code, reason); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
364 if (content != null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
365 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
366 completeHeader(null, false); |
1031
921c25a05eaa
remove Buffer.asReadOnlyBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1016
diff
changeset
|
367 addContent(new ByteArrayBuffer(content), LAST); |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
368 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
369 else if (code>=400) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
370 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
371 completeHeader(null, false); |
1031
921c25a05eaa
remove Buffer.asReadOnlyBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1016
diff
changeset
|
372 addContent(new ByteArrayBuffer("Error: "+(reason==null?(""+code):reason)), LAST); |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
373 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
374 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
375 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
376 completeHeader(null, true); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
377 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
378 complete(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
379 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
380 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
381 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
382 public final long getContentWritten() |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
383 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
384 return _contentWritten; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
385 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
386 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
387 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
388 public final void blockForOutput(long maxIdleTime) throws IOException |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
389 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
390 if (_endp.isBlocking()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
391 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
392 try |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
393 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
394 flushBuffer(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
395 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
396 catch(IOException e) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
397 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
398 _endp.close(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
399 throw e; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
400 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
401 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
402 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
403 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
404 if (!_endp.blockWritable(maxIdleTime)) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
405 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
406 _endp.close(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
407 throw new EofException("timeout"); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
408 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
409 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
410 flushBuffer(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
411 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
412 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
413 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
414 } |