Mercurial Hosting > luan
annotate src/org/eclipse/jetty/http/HttpGenerator.java @ 1039:a7319f14ba1e
remove Buffer.isImmutable()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 03 Nov 2016 22:55:28 -0600 |
parents | b71ad168fe34 |
children | 2b769da7f67d |
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 import java.io.InterruptedIOException; |
1039
a7319f14ba1e
remove Buffer.isImmutable()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1038
diff
changeset
|
23 import java.util.Arrays; |
802
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 org.eclipse.jetty.io.Buffer; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 import org.eclipse.jetty.io.BufferUtil; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 import org.eclipse.jetty.io.Buffers; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 import org.eclipse.jetty.io.EndPoint; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 import org.eclipse.jetty.io.EofException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 import org.eclipse.jetty.util.StringUtil; |
884
cb78ee27b0e0
remove Server.getVersion()
Franklin Schmidt <fschmidt@gmail.com>
parents:
877
diff
changeset
|
31 import org.eclipse.jetty.server.Server; |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
32 import org.slf4j.Logger; |
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
33 import org.slf4j.LoggerFactory; |
802
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 /* ------------------------------------------------------------ */ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 /** |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
37 * HttpGenerator. Builds HTTP Messages. |
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 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 */ |
982 | 42 public final class HttpGenerator extends AbstractGenerator |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
43 { |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
44 private static final Logger LOG = LoggerFactory.getLogger(HttpGenerator.class); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
45 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
46 // Build cache of response lines for status |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
47 private static class Status |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
48 { |
1039
a7319f14ba1e
remove Buffer.isImmutable()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1038
diff
changeset
|
49 byte[] _schemeCode; |
a7319f14ba1e
remove Buffer.isImmutable()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1038
diff
changeset
|
50 byte[] _responseLine; |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
51 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
52 private static final Status[] __status = new Status[HttpStatus.MAX_CODE+1]; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
53 static |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
54 { |
1019
f126d30e04a4
start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
990
diff
changeset
|
55 final int versionLength=HttpVersions.HTTP_1_1_BYTES.length; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
56 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
57 for (int i=0;i<__status.length;i++) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
58 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
59 HttpStatus.Code code = HttpStatus.getCode(i); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
60 if (code==null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
61 continue; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
62 String reason=code.getMessage(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
63 byte[] bytes=new byte[versionLength+5+reason.length()+2]; |
1019
f126d30e04a4
start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
990
diff
changeset
|
64 // HttpVersions.HTTP_1_1_BUFFER.peek(0,bytes, 0, versionLength); |
f126d30e04a4
start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
990
diff
changeset
|
65 System.arraycopy(HttpVersions.HTTP_1_1_BYTES,0,bytes,0,versionLength); |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
66 bytes[versionLength+0]=' '; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
67 bytes[versionLength+1]=(byte)('0'+i/100); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
68 bytes[versionLength+2]=(byte)('0'+(i%100)/10); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
69 bytes[versionLength+3]=(byte)('0'+(i%10)); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
70 bytes[versionLength+4]=' '; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
71 for (int j=0;j<reason.length();j++) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
72 bytes[versionLength+5+j]=(byte)reason.charAt(j); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
73 bytes[versionLength+5+reason.length()]=HttpTokens.CARRIAGE_RETURN; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
74 bytes[versionLength+6+reason.length()]=HttpTokens.LINE_FEED; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
75 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
76 __status[i] = new Status(); |
1039
a7319f14ba1e
remove Buffer.isImmutable()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1038
diff
changeset
|
77 __status[i]._schemeCode = Arrays.copyOf(bytes,versionLength+5); |
a7319f14ba1e
remove Buffer.isImmutable()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1038
diff
changeset
|
78 __status[i]._responseLine = bytes; |
877
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 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
81 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
82 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
83 // common _content |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
84 private static final byte[] LAST_CHUNK = |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
85 { (byte) '0', (byte) '\015', (byte) '\012', (byte) '\015', (byte) '\012'}; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
86 private static final byte[] CONTENT_LENGTH_0 = StringUtil.getBytes("Content-Length: 0\015\012"); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
87 private static final byte[] CONNECTION_KEEP_ALIVE = StringUtil.getBytes("Connection: keep-alive\015\012"); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
88 private static final byte[] CONNECTION_CLOSE = StringUtil.getBytes("Connection: close\015\012"); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
89 private static final byte[] CONNECTION_ = StringUtil.getBytes("Connection: "); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
90 private static final byte[] CRLF = StringUtil.getBytes("\015\012"); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
91 private static final byte[] TRANSFER_ENCODING_CHUNKED = StringUtil.getBytes("Transfer-Encoding: chunked\015\012"); |
884
cb78ee27b0e0
remove Server.getVersion()
Franklin Schmidt <fschmidt@gmail.com>
parents:
877
diff
changeset
|
92 private static byte[] SERVER = StringUtil.getBytes("Server: Jetty("+Server.version+")\015\012"); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
93 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
94 // other statics |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
95 private static final int CHUNK_SPACE = 12; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
96 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
97 // data |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
98 private boolean _bypass = false; // True if _content buffer can be written directly to endp and bypass the content buffer |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
99 private boolean _needCRLF = false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
100 private boolean _needEOC = false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
101 private boolean _bufferChunked = false; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
102 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
103 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
104 public HttpGenerator(Buffers buffers, EndPoint io) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
105 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
106 super(buffers,io); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
107 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
108 |
1034
563458c4dc93
remove HttpGenerator.reset()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1022
diff
changeset
|
109 public void shutdown() { |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
110 if (_persistent!=null && !_persistent && _endp!=null && !_endp.isOutputShutdown()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
111 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
112 try |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
113 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
114 _endp.shutdownOutput(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
115 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
116 catch(IOException e) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
117 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
118 LOG.trace("",e); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
119 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
120 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
121 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
122 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
123 /* ------------------------------------------------------------ */ |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
124 /** |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
125 * Add content. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
126 * |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
127 * @param content |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
128 * @param last |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
129 * @throws IllegalArgumentException if <code>content</code> is {@link Buffer#isImmutable immutable}. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
130 * @throws IllegalStateException If the request is not expecting any more content, |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
131 * or if the buffers are full and cannot be flushed. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
132 * @throws IOException if there is a problem flushing the buffers. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
133 */ |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
134 public void addContent(Buffer content, boolean last) throws IOException |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
135 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
136 if (_noContent) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
137 throw new IllegalStateException("NO CONTENT"); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
138 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
139 if (_last || _state==STATE_END) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
140 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
141 LOG.warn("Ignoring extra content {}",content); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
142 content.clear(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
143 return; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
144 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
145 _last = last; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
146 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
147 // Handle any unfinished business? |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
148 if (_content!=null && _content.remaining()>0 || _bufferChunked) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
149 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
150 if (_endp.isOutputShutdown()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
151 throw new EofException(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
152 flushBuffer(); |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
153 if (_content != null && _content.remaining()>0) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
154 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
155 if (_bufferChunked) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
156 { |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
157 Buffer nc = _buffers.getBuffer(_content.remaining()+CHUNK_SPACE+content.remaining()); |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
158 nc.put(_content); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
159 nc.put(HttpTokens.CRLF); |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
160 BufferUtil.putHexInt(nc, content.remaining()); |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
161 nc.put(HttpTokens.CRLF); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
162 nc.put(content); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
163 content=nc; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
164 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
165 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
166 { |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
167 Buffer nc = _buffers.getBuffer(_content.remaining()+content.remaining()); |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
168 nc.put(_content); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
169 nc.put(content); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
170 content=nc; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
171 } |
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 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
174 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
175 _content = content; |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
176 _contentWritten += content.remaining(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
177 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
178 // Handle the _content |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
179 if (_head) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
180 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
181 content.clear(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
182 _content=null; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
183 } |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
184 else if (_endp != null && (_buffer==null || _buffer.remaining()==0) && _content.remaining() > 0 && (_last || isCommitted() && _content.remaining()>1024)) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
185 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
186 _bypass = true; |
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 else if (!_bufferChunked) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
189 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
190 // Yes - so we better check we have a buffer |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
191 if (_buffer == null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
192 _buffer = _buffers.getBuffer(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
193 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
194 // Copy _content to buffer; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
195 int len=_buffer.put(_content); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
196 _content.skip(len); |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
197 if (_content.remaining() == 0) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
198 _content = null; |
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 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
201 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
202 /* ------------------------------------------------------------ */ |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
203 /** Prepare buffer for unchecked writes. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
204 * Prepare the generator buffer to receive unchecked writes |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
205 * @return the available space in the buffer. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
206 * @throws IOException |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
207 */ |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
208 public int prepareUncheckedAddContent() throws IOException |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
209 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
210 if (_noContent) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
211 return -1; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
212 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
213 if (_last || _state==STATE_END) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
214 return -1; |
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 // Handle any unfinished business? |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
217 Buffer content = _content; |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
218 if (content != null && content.remaining()>0 || _bufferChunked) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
219 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
220 flushBuffer(); |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
221 if (content != null && content.remaining()>0 || _bufferChunked) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
222 throw new IllegalStateException("FULL"); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
223 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
224 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
225 // we better check we have a buffer |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
226 if (_buffer == null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
227 _buffer = _buffers.getBuffer(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
228 |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
229 _contentWritten-=_buffer.remaining(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
230 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
231 // Handle the _content |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
232 if (_head) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
233 return Integer.MAX_VALUE; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
234 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
235 return _buffer.space()-(_contentLength == HttpTokens.CHUNKED_CONTENT?CHUNK_SPACE:0); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
236 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
237 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
238 @Override |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
239 public boolean isBufferFull() |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
240 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
241 // Should we flush the buffers? |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
242 return super.isBufferFull() || _bufferChunked || _bypass || (_contentLength == HttpTokens.CHUNKED_CONTENT && _buffer != null && _buffer.space() < CHUNK_SPACE); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
243 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
244 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
245 public void send1xx(int code) throws IOException |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
246 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
247 if (_state != STATE_HEADER) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
248 return; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
249 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
250 if (code<100||code>199) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
251 throw new IllegalArgumentException("!1xx"); |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
252 Status status = __status[code]; |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
253 if (status==null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
254 throw new IllegalArgumentException(code+"?"); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
255 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
256 // get a header buffer |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
257 if (_header == null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
258 _header = _buffers.getHeader(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
259 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
260 _header.put(status._responseLine); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
261 _header.put(HttpTokens.CRLF); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
262 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
263 try |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
264 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
265 // nasty semi busy flush! |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
266 while(_header.remaining()>0) |
877
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 int len = _endp.flush(_header); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
269 if (len<0) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
270 throw new EofException(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
271 if (len==0) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
272 Thread.sleep(100); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
273 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
274 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
275 catch(InterruptedException e) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
276 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
277 LOG.debug("",e); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
278 throw new InterruptedIOException(e.toString()); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
279 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
280 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
281 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
282 @Override |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
283 boolean isRequest() |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
284 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
285 return _method!=null; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
286 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
287 |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
288 private boolean isResponse() |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
289 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
290 return _method==null; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
291 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
292 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
293 @Override |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
294 public void completeHeader(HttpFields fields, boolean allContentAdded) throws IOException |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
295 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
296 if (_state != STATE_HEADER) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
297 return; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
298 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
299 // handle a reset |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
300 if (isResponse() && _status==0) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
301 throw new EofException(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
302 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
303 if (_last && !allContentAdded) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
304 throw new IllegalStateException("last?"); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
305 _last = _last | allContentAdded; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
306 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
307 // get a header buffer |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
308 if (_header == null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
309 _header = _buffers.getHeader(); |
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 boolean has_server = false; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
312 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
313 try |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
314 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
315 if (isRequest()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
316 { |
1034
563458c4dc93
remove HttpGenerator.reset()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1022
diff
changeset
|
317 _persistent = true; |
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 if (_version == HttpVersions.HTTP_0_9_ORDINAL) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
320 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
321 _contentLength = HttpTokens.NO_CONTENT; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
322 _header.put(_method); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
323 _header.put((byte)' '); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
324 _header.put(_uri.getBytes("UTF-8")); // TODO check |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
325 _header.put(HttpTokens.CRLF); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
326 _state = STATE_FLUSHING; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
327 _noContent=true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
328 return; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
329 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
330 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
331 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
332 _header.put(_method); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
333 _header.put((byte)' '); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
334 _header.put(_uri.getBytes("UTF-8")); // TODO check |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
335 _header.put((byte)' '); |
1019
f126d30e04a4
start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
990
diff
changeset
|
336 _header.put(_version==HttpVersions.HTTP_1_0_ORDINAL?HttpVersions.HTTP_1_0_BYTES:HttpVersions.HTTP_1_1_BYTES); |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
337 _header.put(HttpTokens.CRLF); |
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 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
340 else |
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 // Responses |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
343 if (_version == HttpVersions.HTTP_0_9_ORDINAL) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
344 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
345 _persistent = false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
346 _contentLength = HttpTokens.EOF_CONTENT; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
347 _state = STATE_CONTENT; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
348 return; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
349 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
350 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
351 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
352 if (_persistent==null) |
1034
563458c4dc93
remove HttpGenerator.reset()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1022
diff
changeset
|
353 _persistent = (_version > HttpVersions.HTTP_1_0_ORDINAL); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
354 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
355 // add response line |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
356 Status status = _status<__status.length?__status[_status]:null; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
357 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
358 if (status==null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
359 { |
1019
f126d30e04a4
start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
990
diff
changeset
|
360 _header.put(HttpVersions.HTTP_1_1_BYTES); |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
361 _header.put((byte) ' '); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
362 _header.put((byte) ('0' + _status / 100)); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
363 _header.put((byte) ('0' + (_status % 100) / 10)); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
364 _header.put((byte) ('0' + (_status % 10))); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
365 _header.put((byte) ' '); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
366 if (_reason==null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
367 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
368 _header.put((byte) ('0' + _status / 100)); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
369 _header.put((byte) ('0' + (_status % 100) / 10)); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
370 _header.put((byte) ('0' + (_status % 10))); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
371 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
372 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
373 _header.put(_reason); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
374 _header.put(HttpTokens.CRLF); |
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 else |
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 if (_reason==null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
379 _header.put(status._responseLine); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
380 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
381 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
382 _header.put(status._schemeCode); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
383 _header.put(_reason); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
384 _header.put(HttpTokens.CRLF); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
385 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
386 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
387 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
388 if (_status<200 && _status>=100 ) |
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 _noContent=true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
391 _content=null; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
392 if (_buffer!=null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
393 _buffer.clear(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
394 // end the header. |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
395 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
396 if (_status!=101 ) |
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 _header.put(HttpTokens.CRLF); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
399 _state = STATE_CONTENT; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
400 return; |
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 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
403 else if (_status==204 || _status==304) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
404 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
405 _noContent=true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
406 _content=null; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
407 if (_buffer!=null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
408 _buffer.clear(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
409 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
410 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
411 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
412 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
413 // key field values |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
414 HttpFields.Field content_length = null; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
415 HttpFields.Field transfer_encoding = null; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
416 boolean keep_alive = false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
417 boolean close=false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
418 boolean content_type=false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
419 StringBuilder connection = null; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
420 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
421 if (fields != null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
422 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
423 int s=fields.size(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
424 for (int f=0;f<s;f++) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
425 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
426 HttpFields.Field field = fields.getField(f); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
427 if (field==null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
428 continue; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
429 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
430 switch (field.getNameOrdinal()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
431 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
432 case HttpHeaders.CONTENT_LENGTH_ORDINAL: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
433 content_length = field; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
434 _contentLength = field.getLongValue(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
435 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
436 if (_contentLength < _contentWritten || _last && _contentLength != _contentWritten) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
437 content_length = null; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
438 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
439 // write the field to the header buffer |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
440 field.putTo(_header); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
441 break; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
442 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
443 case HttpHeaders.CONTENT_TYPE_ORDINAL: |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1019
diff
changeset
|
444 // if (BufferUtil.isPrefix(MimeTypes.MULTIPART_BYTERANGES_BUFFER, field.getValueBuffer())) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1019
diff
changeset
|
445 if (field.getValue().startsWith(MimeTypes.MULTIPART_BYTERANGES)) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1019
diff
changeset
|
446 _contentLength = HttpTokens.SELF_DEFINING_CONTENT; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
447 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
448 // write the field to the header buffer |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
449 content_type=true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
450 field.putTo(_header); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
451 break; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
452 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
453 case HttpHeaders.TRANSFER_ENCODING_ORDINAL: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
454 if (_version == HttpVersions.HTTP_1_1_ORDINAL) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
455 transfer_encoding = field; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
456 // Do NOT add yet! |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
457 break; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
458 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
459 case HttpHeaders.CONNECTION_ORDINAL: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
460 if (isRequest()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
461 field.putTo(_header); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
462 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
463 int connection_value = field.getValueOrdinal(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
464 switch (connection_value) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
465 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
466 case -1: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
467 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
468 String[] values = field.getValue().split(","); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
469 for (int i=0;values!=null && i<values.length;i++) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
470 { |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1019
diff
changeset
|
471 int ord = HttpHeaderValues.CACHE.getOrdinal(values[i].trim()); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
472 |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1019
diff
changeset
|
473 if (ord != -1) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
474 { |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1019
diff
changeset
|
475 switch(ord) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
476 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
477 case HttpHeaderValues.CLOSE_ORDINAL: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
478 close=true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
479 if (isResponse()) |
1034
563458c4dc93
remove HttpGenerator.reset()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1022
diff
changeset
|
480 _persistent = false; |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
481 keep_alive=false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
482 if (!_persistent && isResponse() && _contentLength == HttpTokens.UNKNOWN_CONTENT) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
483 _contentLength = HttpTokens.EOF_CONTENT; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
484 break; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
485 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
486 case HttpHeaderValues.KEEP_ALIVE_ORDINAL: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
487 if (_version == HttpVersions.HTTP_1_0_ORDINAL) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
488 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
489 keep_alive = true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
490 if (isResponse()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
491 _persistent = true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
492 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
493 break; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
494 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
495 default: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
496 if (connection==null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
497 connection=new StringBuilder(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
498 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
499 connection.append(','); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
500 connection.append(values[i]); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
501 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
502 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
503 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
504 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
505 if (connection==null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
506 connection=new StringBuilder(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
507 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
508 connection.append(','); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
509 connection.append(values[i]); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
510 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
511 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
512 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
513 break; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
514 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
515 case HttpHeaderValues.UPGRADE_ORDINAL: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
516 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
517 // special case for websocket connection ordering |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
518 if (isResponse()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
519 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
520 field.putTo(_header); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
521 continue; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
522 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
523 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
524 case HttpHeaderValues.CLOSE_ORDINAL: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
525 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
526 close=true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
527 if (isResponse()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
528 _persistent=false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
529 if (!_persistent && isResponse() && _contentLength == HttpTokens.UNKNOWN_CONTENT) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
530 _contentLength = HttpTokens.EOF_CONTENT; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
531 break; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
532 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
533 case HttpHeaderValues.KEEP_ALIVE_ORDINAL: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
534 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
535 if (_version == HttpVersions.HTTP_1_0_ORDINAL) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
536 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
537 keep_alive = true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
538 if (isResponse()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
539 _persistent=true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
540 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
541 break; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
542 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
543 default: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
544 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
545 if (connection==null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
546 connection=new StringBuilder(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
547 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
548 connection.append(','); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
549 connection.append(field.getValue()); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
550 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
551 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
552 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
553 // Do NOT add yet! |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
554 break; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
555 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
556 case HttpHeaders.SERVER_ORDINAL: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
557 has_server=true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
558 field.putTo(_header); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
559 break; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
560 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
561 default: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
562 // write the field to the header buffer |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
563 field.putTo(_header); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
564 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
565 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
566 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
567 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
568 // Calculate how to end _content and connection, _content length and transfer encoding |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
569 // settings. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
570 // From RFC 2616 4.4: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
571 // 1. No body for 1xx, 204, 304 & HEAD response |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
572 // 2. Force _content-length? |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
573 // 3. If Transfer-Encoding!=identity && HTTP/1.1 && !HttpConnection==close then chunk |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
574 // 4. Content-Length |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
575 // 5. multipart/byteranges |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
576 // 6. close |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
577 switch ((int) _contentLength) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
578 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
579 case HttpTokens.UNKNOWN_CONTENT: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
580 // It may be that we have no _content, or perhaps _content just has not been |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
581 // written yet? |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
582 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
583 // Response known not to have a body |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
584 if (_contentWritten == 0 && isResponse() && (_status < 200 || _status == 204 || _status == 304)) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
585 _contentLength = HttpTokens.NO_CONTENT; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
586 else if (_last) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
587 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
588 // we have seen all the _content there is |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
589 _contentLength = _contentWritten; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
590 if (content_length == null && (isResponse() || _contentLength>0 || content_type ) && !_noContent) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
591 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
592 // known length but not actually set. |
1022
3718afd99988
HttpHeaders uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1021
diff
changeset
|
593 _header.put(HttpHeaders.CONTENT_LENGTH_BYTES); |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
594 _header.put(HttpTokens.COLON); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
595 _header.put((byte) ' '); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
596 BufferUtil.putDecLong(_header, _contentLength); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
597 _header.put(HttpTokens.CRLF); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
598 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
599 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
600 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
601 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
602 // No idea, so we must assume that a body is coming |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
603 _contentLength = (!_persistent || _version < HttpVersions.HTTP_1_1_ORDINAL ) ? HttpTokens.EOF_CONTENT : HttpTokens.CHUNKED_CONTENT; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
604 if (isRequest() && _contentLength==HttpTokens.EOF_CONTENT) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
605 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
606 _contentLength=HttpTokens.NO_CONTENT; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
607 _noContent=true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
608 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
609 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
610 break; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
611 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
612 case HttpTokens.NO_CONTENT: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
613 if (content_length == null && isResponse() && _status >= 200 && _status != 204 && _status != 304) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
614 _header.put(CONTENT_LENGTH_0); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
615 break; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
616 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
617 case HttpTokens.EOF_CONTENT: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
618 _persistent = isRequest(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
619 break; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
620 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
621 case HttpTokens.CHUNKED_CONTENT: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
622 break; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
623 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
624 default: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
625 // TODO - maybe allow forced chunking by setting te ??? |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
626 break; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
627 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
628 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
629 // Add transfer_encoding if needed |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
630 if (_contentLength == HttpTokens.CHUNKED_CONTENT) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
631 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
632 // try to use user supplied encoding as it may have other values. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
633 if (transfer_encoding != null && HttpHeaderValues.CHUNKED_ORDINAL != transfer_encoding.getValueOrdinal()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
634 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
635 String c = transfer_encoding.getValue(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
636 if (c.endsWith(HttpHeaderValues.CHUNKED)) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
637 transfer_encoding.putTo(_header); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
638 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
639 throw new IllegalArgumentException("BAD TE"); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
640 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
641 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
642 _header.put(TRANSFER_ENCODING_CHUNKED); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
643 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
644 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
645 // Handle connection if need be |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
646 if (_contentLength==HttpTokens.EOF_CONTENT) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
647 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
648 keep_alive=false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
649 _persistent=false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
650 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
651 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
652 if (isResponse()) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
653 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
654 if (!_persistent && (close || _version > HttpVersions.HTTP_1_0_ORDINAL)) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
655 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
656 _header.put(CONNECTION_CLOSE); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
657 if (connection!=null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
658 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
659 _header.setPutIndex(_header.putIndex()-2); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
660 _header.put((byte)','); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
661 _header.put(connection.toString().getBytes()); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
662 _header.put(CRLF); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
663 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
664 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
665 else if (keep_alive) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
666 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
667 _header.put(CONNECTION_KEEP_ALIVE); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
668 if (connection!=null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
669 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
670 _header.setPutIndex(_header.putIndex()-2); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
671 _header.put((byte)','); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
672 _header.put(connection.toString().getBytes()); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
673 _header.put(CRLF); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
674 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
675 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
676 else if (connection!=null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
677 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
678 _header.put(CONNECTION_); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
679 _header.put(connection.toString().getBytes()); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
680 _header.put(CRLF); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
681 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
682 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
683 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
684 if (!has_server && _status>199) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
685 _header.put(SERVER); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
686 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
687 // end the header. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
688 _header.put(HttpTokens.CRLF); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
689 _state = STATE_CONTENT; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
690 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
691 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
692 catch(ArrayIndexOutOfBoundsException e) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
693 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
694 throw new RuntimeException("Header>"+_header.capacity(),e); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
695 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
696 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
697 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
698 /* ------------------------------------------------------------ */ |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
699 /** |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
700 * Complete the message. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
701 * |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
702 * @throws IOException |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
703 */ |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
704 @Override |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
705 public void complete() throws IOException |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
706 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
707 if (_state == STATE_END) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
708 return; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
709 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
710 super.complete(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
711 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
712 if (_state < STATE_FLUSHING) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
713 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
714 _state = STATE_FLUSHING; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
715 if (_contentLength == HttpTokens.CHUNKED_CONTENT) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
716 _needEOC = true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
717 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
718 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
719 flushBuffer(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
720 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
721 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
722 @Override |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
723 public int flushBuffer() throws IOException |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
724 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
725 try |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
726 { |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
727 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
728 if (_state == STATE_HEADER) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
729 throw new IllegalStateException("State==HEADER"); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
730 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
731 prepareBuffers(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
732 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
733 if (_endp == null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
734 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
735 if (_needCRLF && _buffer!=null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
736 _buffer.put(HttpTokens.CRLF); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
737 if (_needEOC && _buffer!=null && !_head) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
738 _buffer.put(LAST_CHUNK); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
739 _needCRLF=false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
740 _needEOC=false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
741 return 0; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
742 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
743 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
744 int total= 0; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
745 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
746 int len = -1; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
747 int to_flush = flushMask(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
748 int last_flush; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
749 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
750 do |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
751 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
752 last_flush=to_flush; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
753 switch (to_flush) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
754 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
755 case 7: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
756 throw new IllegalStateException(); // should never happen! |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
757 case 6: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
758 len = _endp.flush(_header, _buffer, null); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
759 break; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
760 case 5: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
761 len = _endp.flush(_header, _content, null); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
762 break; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
763 case 4: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
764 len = _endp.flush(_header); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
765 break; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
766 case 3: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
767 len = _endp.flush(_buffer, _content, null); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
768 break; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
769 case 2: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
770 len = _endp.flush(_buffer); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
771 break; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
772 case 1: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
773 len = _endp.flush(_content); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
774 break; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
775 case 0: |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
776 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
777 len=0; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
778 // Nothing more we can write now. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
779 if (_header != null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
780 _header.clear(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
781 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
782 _bypass = false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
783 _bufferChunked = false; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
784 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
785 if (_buffer != null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
786 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
787 _buffer.clear(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
788 if (_contentLength == HttpTokens.CHUNKED_CONTENT) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
789 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
790 // reserve some space for the chunk header |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
791 _buffer.setPutIndex(CHUNK_SPACE); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
792 _buffer.setGetIndex(CHUNK_SPACE); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
793 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
794 // Special case handling for small left over buffer from |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
795 // an addContent that caused a buffer flush. |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
796 if (_content != null && _content.remaining() < _buffer.space() && _state != STATE_FLUSHING) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
797 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
798 _buffer.put(_content); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
799 _content.clear(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
800 _content=null; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
801 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
802 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
803 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
804 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
805 // Are we completely finished for now? |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
806 if (!_needCRLF && !_needEOC && (_content==null || _content.remaining()==0)) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
807 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
808 if (_state == STATE_FLUSHING) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
809 _state = STATE_END; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
810 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
811 if (_state==STATE_END && _persistent != null && !_persistent && _status!=100 && _method==null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
812 _endp.shutdownOutput(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
813 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
814 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
815 // Try to prepare more to write. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
816 prepareBuffers(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
817 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
818 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
819 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
820 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
821 if (len > 0) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
822 total+=len; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
823 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
824 to_flush = flushMask(); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
825 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
826 // loop while progress is being made (OR we have prepared some buffers that might make progress) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
827 while (len>0 || (to_flush!=0 && last_flush==0)); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
828 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
829 return total; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
830 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
831 catch (IOException e) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
832 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
833 LOG.trace("",e); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
834 throw (e instanceof EofException) ? e:new EofException(e); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
835 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
836 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
837 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
838 private int flushMask() |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
839 { |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
840 return ((_header != null && _header.remaining() > 0)?4:0) |
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
841 | ((_buffer != null && _buffer.remaining() > 0)?2:0) |
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
842 | ((_bypass && _content != null && _content.remaining() > 0)?1:0); |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
843 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
844 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
845 private void prepareBuffers() |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
846 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
847 // if we are not flushing an existing chunk |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
848 if (!_bufferChunked) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
849 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
850 // Refill buffer if possible |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
851 if (!_bypass && _content != null && _content.remaining() > 0 && _buffer != null && _buffer.space() > 0) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
852 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
853 int len = _buffer.put(_content); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
854 _content.skip(len); |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
855 if (_content.remaining() == 0) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
856 _content = null; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
857 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
858 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
859 // Chunk buffer if need be |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
860 if (_contentLength == HttpTokens.CHUNKED_CONTENT) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
861 { |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
862 if (_bypass && (_buffer==null||_buffer.remaining()==0) && _content!=null) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
863 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
864 // this is a bypass write |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
865 int size = _content.remaining(); |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
866 _bufferChunked = true; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
867 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
868 if (_header == null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
869 _header = _buffers.getHeader(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
870 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
871 // if we need CRLF add this to header |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
872 if (_needCRLF) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
873 { |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
874 if (_header.remaining() > 0) throw new IllegalStateException("EOC"); |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
875 _header.put(HttpTokens.CRLF); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
876 _needCRLF = false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
877 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
878 // Add the chunk size to the header |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
879 BufferUtil.putHexInt(_header, size); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
880 _header.put(HttpTokens.CRLF); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
881 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
882 // Need a CRLF after the content |
983
23ec25435b8c
simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents:
982
diff
changeset
|
883 _needCRLF = true; |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
884 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
885 else if (_buffer!=null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
886 { |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
887 int size = _buffer.remaining(); |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
888 if (size > 0) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
889 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
890 // Prepare a chunk! |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
891 _bufferChunked = true; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
892 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
893 // Did we leave space at the start of the buffer. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
894 //noinspection ConstantConditions |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
895 if (_buffer.getIndex() == CHUNK_SPACE) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
896 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
897 // Oh yes, goodie! let's use it then! |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
898 _buffer.poke(_buffer.getIndex() - 2, HttpTokens.CRLF, 0, 2); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
899 _buffer.setGetIndex(_buffer.getIndex() - 2); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
900 BufferUtil.prependHexInt(_buffer, size); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
901 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
902 if (_needCRLF) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
903 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
904 _buffer.poke(_buffer.getIndex() - 2, HttpTokens.CRLF, 0, 2); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
905 _buffer.setGetIndex(_buffer.getIndex() - 2); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
906 _needCRLF = false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
907 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
908 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
909 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
910 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
911 // No space so lets use a header buffer. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
912 if (_header == null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
913 _header = _buffers.getHeader(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
914 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
915 if (_needCRLF) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
916 { |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
917 if (_header.remaining() > 0) throw new IllegalStateException("EOC"); |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
918 _header.put(HttpTokens.CRLF); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
919 _needCRLF = false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
920 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
921 BufferUtil.putHexInt(_header, size); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
922 _header.put(HttpTokens.CRLF); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
923 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
924 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
925 // Add end chunk trailer. |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
926 if (_buffer.space() >= 2) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
927 _buffer.put(HttpTokens.CRLF); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
928 else |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
929 _needCRLF = true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
930 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
931 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
932 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
933 // If we need EOC and everything written |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
934 if (_needEOC && (_content == null || _content.remaining() == 0)) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
935 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
936 if (_header == null && _buffer == null) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
937 _header = _buffers.getHeader(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
938 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
939 if (_needCRLF) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
940 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
941 if (_buffer == null && _header != null && _header.space() >= HttpTokens.CRLF.length) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
942 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
943 _header.put(HttpTokens.CRLF); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
944 _needCRLF = false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
945 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
946 else if (_buffer!=null && _buffer.space() >= HttpTokens.CRLF.length) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
947 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
948 _buffer.put(HttpTokens.CRLF); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
949 _needCRLF = false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
950 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
951 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
952 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
953 if (!_needCRLF && _needEOC) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
954 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
955 if (_buffer == null && _header != null && _header.space() >= LAST_CHUNK.length) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
956 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
957 if (!_head) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
958 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
959 _header.put(LAST_CHUNK); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
960 _bufferChunked=true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
961 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
962 _needEOC = false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
963 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
964 else if (_buffer!=null && _buffer.space() >= LAST_CHUNK.length) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
965 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
966 if (!_head) |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
967 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
968 _buffer.put(LAST_CHUNK); |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
969 _bufferChunked=true; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
970 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
971 _needEOC = false; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
972 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
973 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
974 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
975 } |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
976 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
977 |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
978 if (_content != null && _content.remaining() == 0) |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
979 _content = null; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
980 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
981 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
982 |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
983 @Override |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
984 public String toString() |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
985 { |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
986 Buffer header=_header; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
987 Buffer buffer=_buffer; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
988 Buffer content=_content; |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
989 return String.format("%s{s=%d,h=%d,b=%d,c=%d}", |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
990 getClass().getSimpleName(), |
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
991 _state, |
1038
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
992 header == null ? -1 : header.remaining(), |
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
993 buffer == null ? -1 : buffer.remaining(), |
b71ad168fe34
rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1036
diff
changeset
|
994 content == null ? -1 : content.remaining()); |
877
fef4392f4905
remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
995 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
996 } |