annotate src/org/eclipse/jetty/http/HttpGenerator.java @ 1069:7dd6ec499000

fix use of HttpGenerator._content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 10 Nov 2016 00:42:51 -0700
parents 9d357b9e4bcb
children a44fc6b53757
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1039
diff changeset
25 import org.eclipse.jetty.io.JBuffer;
802
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 */
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
42 public final class HttpGenerator
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
1034
563458c4dc93 remove HttpGenerator.reset()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1022
diff changeset
104 public void shutdown() {
1059
013939bfc9e8 remove JBuffer.poke()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1058
diff changeset
105 if (_persistent!=null && !_persistent && !_endp.isOutputShutdown())
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
106 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 try
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
108 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
109 _endp.shutdownOutput();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
110 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
111 catch(IOException e)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113 LOG.trace("",e);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 }
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
118 /* ------------------------------------------------------------ */
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 * Add content.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
121 *
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
122 * @param content
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
123 * @param last
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1039
diff changeset
124 * @throws IllegalArgumentException if <code>content</code> is {@link JBuffer#isImmutable immutable}.
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 * @throws IllegalStateException If the request is not expecting any more content,
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
126 * or if the buffers are full and cannot be flushed.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
127 * @throws IOException if there is a problem flushing the buffers.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
128 */
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1039
diff changeset
129 public void addContent(JBuffer content, boolean last) throws IOException
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
130 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
131 if (_noContent)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
132 throw new IllegalStateException("NO CONTENT");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
133
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
134 if (_last || _state==STATE_END)
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 LOG.warn("Ignoring extra content {}",content);
1065
158d1e6ac17f fix JBuffer.compact()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1064
diff changeset
137 // content.clear();
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
138 return;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
139 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
140 _last = last;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
142 // Handle any unfinished business?
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
143 if (_content!=null && _content.hasRemaining() || _bufferChunked)
877
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 if (_endp.isOutputShutdown())
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
146 throw new EofException();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
147 flushBuffer();
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
148 if (_content != null && _content.hasRemaining())
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 (_bufferChunked)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
151 {
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1039
diff changeset
152 JBuffer nc = _buffers.getBuffer(_content.remaining()+CHUNK_SPACE+content.remaining());
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
153 nc.putQ(_content);
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
154 nc.putQ(HttpTokens.CRLF);
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1036
diff changeset
155 BufferUtil.putHexInt(nc, content.remaining());
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
156 nc.putQ(HttpTokens.CRLF);
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
157 nc.putQ(content);
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
158 nc.flip();
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
159 content = nc;
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
160 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
162 {
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1039
diff changeset
163 JBuffer nc = _buffers.getBuffer(_content.remaining()+content.remaining());
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
164 nc.putQ(_content);
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
165 nc.putQ(content);
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
166 nc.flip();
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
167 content = nc;
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
168 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
169 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
170 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
171
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
172 _content = content;
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1036
diff changeset
173 _contentWritten += content.remaining();
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 // Handle the _content
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
176 if (_head)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
177 {
1065
158d1e6ac17f fix JBuffer.compact()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1064
diff changeset
178 // content.clear();
158d1e6ac17f fix JBuffer.compact()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1064
diff changeset
179 _content = null;
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
180 }
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
181 else if ((_buffer==null || _buffer.remaining()==0) && _content.hasRemaining() && (_last || isCommitted() && _content.remaining()>1024))
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
183 _bypass = true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
184 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 else if (!_bufferChunked)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 {
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
187 //System.out.println("qqqqqqqqqqqqqqqqqqq c");
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
188 // Copy _content to buffer;
1067
56b515be91e1 fix use of HttpGenerator._reason
Franklin Schmidt <fschmidt@gmail.com>
parents: 1066
diff changeset
189 int len = _buffer.put(_content);
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 _content.skip(len);
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
191 if (!_content.hasRemaining())
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
192 _content = null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
193 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
194 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
195
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 /* ------------------------------------------------------------ */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 /** Prepare buffer for unchecked writes.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 * Prepare the generator buffer to receive unchecked writes
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 * @return the available space in the buffer.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
200 * @throws IOException
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 */
1064
a0abb16cf6e7 remove JBuffer.readFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1059
diff changeset
202 public void prepareUncheckedAddContent() throws IOException
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
203 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
204 if (_noContent)
1064
a0abb16cf6e7 remove JBuffer.readFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1059
diff changeset
205 // return -1;
a0abb16cf6e7 remove JBuffer.readFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1059
diff changeset
206 throw new RuntimeException("_noContent");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
207
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
208 if (_last || _state==STATE_END)
1064
a0abb16cf6e7 remove JBuffer.readFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1059
diff changeset
209 // return -1;
a0abb16cf6e7 remove JBuffer.readFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1059
diff changeset
210 throw new RuntimeException("_last");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
211
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
212 // Handle any unfinished business?
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
213 if (_content != null && _content.hasRemaining() || _bufferChunked)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
214 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
215 flushBuffer();
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
216 if (_content != null && _content.hasRemaining() || _bufferChunked)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
217 throw new IllegalStateException("FULL");
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
219
1064
a0abb16cf6e7 remove JBuffer.readFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1059
diff changeset
220 _contentWritten -= _buffer.remaining();
a0abb16cf6e7 remove JBuffer.readFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1059
diff changeset
221 /*
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 // Handle the _content
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
223 if (_head)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
224 return Integer.MAX_VALUE;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
225
1059
013939bfc9e8 remove JBuffer.poke()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1058
diff changeset
226 return _buffer.space();
1064
a0abb16cf6e7 remove JBuffer.readFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1059
diff changeset
227 */
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
228 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
229
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 public boolean isBufferFull()
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
231 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
232 // Should we flush the buffers?
1059
013939bfc9e8 remove JBuffer.poke()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1058
diff changeset
233 return isBufferFull2() || _bufferChunked || _bypass /* || (_contentLength == HttpTokens.CHUNKED_CONTENT && _buffer != null && _buffer.space() < CHUNK_SPACE)*/;
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
234 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
235
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236 public void send1xx(int code) throws IOException
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
237 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 if (_state != STATE_HEADER)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
239 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
240
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 if (code<100||code>199)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
242 throw new IllegalArgumentException("!1xx");
983
23ec25435b8c simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 982
diff changeset
243 Status status = __status[code];
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 if (status==null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
245 throw new IllegalArgumentException(code+"?");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
246
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
247 _header.putQ(status._responseLine);
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
248 _header.putQ(HttpTokens.CRLF);
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 try
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
251 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
252 // nasty semi busy flush!
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
253 _header.flip();
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1036
diff changeset
254 while(_header.remaining()>0)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
255 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
256 int len = _endp.flush(_header);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
257 if (len<0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
258 throw new EofException();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
259 if (len==0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
260 Thread.sleep(100);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
261 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
262 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
263 catch(InterruptedException e)
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 LOG.debug("",e);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
266 throw new InterruptedIOException(e.toString());
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
269
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
270 public void completeHeader(HttpFields fields, boolean allContentAdded) throws IOException
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
271 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
272 if (_state != STATE_HEADER)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
273 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
274
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
275 // handle a reset
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
276 if (_status==0)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
277 throw new EofException();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
278
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 if (_last && !allContentAdded)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
280 throw new IllegalStateException("last?");
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
281 _last = _last | allContentAdded;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
282
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
283 boolean has_server = false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
284
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
285 try
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
286 {
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
287 // Responses
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
288 if (_version == HttpVersions.HTTP_0_9_ORDINAL)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
289 {
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
290 _persistent = false;
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
291 _contentLength = HttpTokens.EOF_CONTENT;
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
292 _state = STATE_CONTENT;
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
293 return;
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
294 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
295 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
296 {
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
297 if (_persistent==null)
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
298 _persistent = (_version > HttpVersions.HTTP_1_0_ORDINAL);
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
299
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
300 // add response line
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
301 Status status = _status<__status.length?__status[_status]:null;
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
302
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
303 if (status==null)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
304 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
305 _header.putQ(HttpVersions.HTTP_1_1_BYTES);
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
306 _header.putQ((byte) ' ');
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
307 _header.putQ((byte) ('0' + _status / 100));
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
308 _header.putQ((byte) ('0' + (_status % 100) / 10));
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
309 _header.putQ((byte) ('0' + (_status % 10)));
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
310 _header.putQ((byte) ' ');
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
311 if (_reason==null)
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
312 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
313 _header.putQ((byte) ('0' + _status / 100));
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
314 _header.putQ((byte) ('0' + (_status % 100) / 10));
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
315 _header.putQ((byte) ('0' + (_status % 10)));
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
316 }
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
317 else
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
318 _header.putQ(_reason);
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
319 _header.putQ(HttpTokens.CRLF);
877
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 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
322 {
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
323 if (_reason==null)
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
324 _header.putQ(status._responseLine);
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
325 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
326 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
327 _header.putQ(status._schemeCode);
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
328 _header.putQ(_reason);
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
329 _header.putQ(HttpTokens.CRLF);
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
330 }
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
331 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
332
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
333 if (_status<200 && _status>=100 )
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
334 {
1059
013939bfc9e8 remove JBuffer.poke()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1058
diff changeset
335 _noContent = true;
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
336 _content = null;
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
337 if (_buffer!=null)
1065
158d1e6ac17f fix JBuffer.compact()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1064
diff changeset
338 _buffer.clearJ();
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
339 // end the header.
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
340
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
341 if (_status!=101 )
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
343 _header.putQ(HttpTokens.CRLF);
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
344 _state = STATE_CONTENT;
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
345 return;
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346 }
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
347 }
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
348 else if (_status==204 || _status==304)
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
349 {
1059
013939bfc9e8 remove JBuffer.poke()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1058
diff changeset
350 _noContent = true;
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
351 _content = null;
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
352 if (_buffer!=null)
1065
158d1e6ac17f fix JBuffer.compact()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1064
diff changeset
353 _buffer.clearJ();
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
354 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
355 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
356
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
357 // key field values
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
358 HttpFields.Field content_length = null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
359 HttpFields.Field transfer_encoding = null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
360 boolean keep_alive = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
361 boolean close=false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
362 boolean content_type=false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
363 StringBuilder connection = null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
364
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
365 if (fields != null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
366 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
367 int s=fields.size();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
368 for (int f=0;f<s;f++)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
369 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
370 HttpFields.Field field = fields.getField(f);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
371 if (field==null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
372 continue;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
373
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
374 switch (field.getNameOrdinal())
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 case HttpHeaders.CONTENT_LENGTH_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
377 content_length = field;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
378 _contentLength = field.getLongValue();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
379
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
380 if (_contentLength < _contentWritten || _last && _contentLength != _contentWritten)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
381 content_length = null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
382
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
383 // write the field to the header buffer
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
384 field.putTo(_header);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
385 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
386
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
387 case HttpHeaders.CONTENT_TYPE_ORDINAL:
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
388 // if (BufferUtil.isPrefix(MimeTypes.MULTIPART_BYTERANGES_BUFFER, field.getValueBuffer()))
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
389 if (field.getValue().startsWith(MimeTypes.MULTIPART_BYTERANGES))
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
390 _contentLength = HttpTokens.SELF_DEFINING_CONTENT;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
391
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
392 // write the field to the header buffer
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
393 content_type=true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
394 field.putTo(_header);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
395 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
396
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
397 case HttpHeaders.TRANSFER_ENCODING_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
398 if (_version == HttpVersions.HTTP_1_1_ORDINAL)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
399 transfer_encoding = field;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
400 // Do NOT add yet!
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
401 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
402
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
403 case HttpHeaders.CONNECTION_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
404 int connection_value = field.getValueOrdinal();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
405 switch (connection_value)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
406 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
407 case -1:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
408 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
409 String[] values = field.getValue().split(",");
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
410 for (int i=0;values!=null && i<values.length;i++)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
411 {
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
412 int ord = HttpHeaderValues.CACHE.getOrdinal(values[i].trim());
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
413
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
414 if (ord != -1)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
415 {
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
416 switch(ord)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
417 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
418 case HttpHeaderValues.CLOSE_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
419 close=true;
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
420 _persistent = false;
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
421 keep_alive=false;
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
422 if (!_persistent && _contentLength == HttpTokens.UNKNOWN_CONTENT)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
423 _contentLength = HttpTokens.EOF_CONTENT;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
424 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
425
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
426 case HttpHeaderValues.KEEP_ALIVE_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
427 if (_version == HttpVersions.HTTP_1_0_ORDINAL)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
428 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
429 keep_alive = true;
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
430 _persistent = true;
877
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 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
433
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
434 default:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
435 if (connection==null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
436 connection=new StringBuilder();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
437 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
438 connection.append(',');
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
439 connection.append(values[i]);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
440 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
441 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
442 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
443 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
444 if (connection==null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
445 connection=new StringBuilder();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
446 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
447 connection.append(',');
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
448 connection.append(values[i]);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
449 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
450 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
451
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
452 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
453 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
454 case HttpHeaderValues.UPGRADE_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
455 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
456 // special case for websocket connection ordering
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
457 field.putTo(_header);
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
458 continue;
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
459 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
460 case HttpHeaderValues.CLOSE_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
461 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
462 close=true;
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
463 _persistent=false;
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
464 if (!_persistent && _contentLength == HttpTokens.UNKNOWN_CONTENT)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
465 _contentLength = HttpTokens.EOF_CONTENT;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
466 break;
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 case HttpHeaderValues.KEEP_ALIVE_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
469 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
470 if (_version == HttpVersions.HTTP_1_0_ORDINAL)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
471 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
472 keep_alive = true;
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
473 _persistent=true;
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
474 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
475 break;
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 default:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
478 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
479 if (connection==null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
480 connection=new StringBuilder();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
481 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
482 connection.append(',');
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
483 connection.append(field.getValue());
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
484 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
485 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
486
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
487 // Do NOT add yet!
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
488 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
489
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
490 case HttpHeaders.SERVER_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
491 has_server=true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
492 field.putTo(_header);
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 // write the field to the header buffer
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
497 field.putTo(_header);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
498 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
499 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
500 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
501
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
502 // Calculate how to end _content and connection, _content length and transfer encoding
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
503 // settings.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
504 // From RFC 2616 4.4:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
505 // 1. No body for 1xx, 204, 304 & HEAD response
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
506 // 2. Force _content-length?
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
507 // 3. If Transfer-Encoding!=identity && HTTP/1.1 && !HttpConnection==close then chunk
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
508 // 4. Content-Length
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
509 // 5. multipart/byteranges
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
510 // 6. close
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
511 switch ((int) _contentLength)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
512 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
513 case HttpTokens.UNKNOWN_CONTENT:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
514 // 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
515 // written yet?
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
516
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
517 // Response known not to have a body
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
518 if (_contentWritten == 0 && (_status < 200 || _status == 204 || _status == 304))
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
519 _contentLength = HttpTokens.NO_CONTENT;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
520 else if (_last)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
521 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
522 // we have seen all the _content there is
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
523 _contentLength = _contentWritten;
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
524 if (content_length == null && !_noContent)
877
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 // known length but not actually set.
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
527 _header.putQ(HttpHeaders.CONTENT_LENGTH_BYTES);
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
528 _header.putQ(HttpTokens.COLON);
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
529 _header.putQ((byte) ' ');
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
530 BufferUtil.putDecLong(_header, _contentLength);
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
531 _header.putQ(HttpTokens.CRLF);
877
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 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
534 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
535 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
536 // No idea, so we must assume that a body is coming
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
537 _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
538 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
539 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
540
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
541 case HttpTokens.NO_CONTENT:
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
542 if (content_length == null && _status >= 200 && _status != 204 && _status != 304)
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
543 _header.putQ(CONTENT_LENGTH_0);
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
544 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
545
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
546 case HttpTokens.EOF_CONTENT:
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
547 _persistent = false;
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
548 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
549
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
550 case HttpTokens.CHUNKED_CONTENT:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
551 break;
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 default:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
554 // TODO - maybe allow forced chunking by setting te ???
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
555 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
556 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
557
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
558 // Add transfer_encoding if needed
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
559 if (_contentLength == HttpTokens.CHUNKED_CONTENT)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
560 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
561 // try to use user supplied encoding as it may have other values.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
562 if (transfer_encoding != null && HttpHeaderValues.CHUNKED_ORDINAL != transfer_encoding.getValueOrdinal())
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
563 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
564 String c = transfer_encoding.getValue();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
565 if (c.endsWith(HttpHeaderValues.CHUNKED))
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
566 transfer_encoding.putTo(_header);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
567 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
568 throw new IllegalArgumentException("BAD TE");
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
569 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
570 else
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
571 _header.putQ(TRANSFER_ENCODING_CHUNKED);
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
572 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
573
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
574 // Handle connection if need be
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
575 if (_contentLength==HttpTokens.EOF_CONTENT)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
576 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
577 keep_alive=false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
578 _persistent=false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
579 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
580
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
581 if (!_persistent && (close || _version > HttpVersions.HTTP_1_0_ORDINAL))
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
582 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
583 _header.putQ(CONNECTION_CLOSE);
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
584 if (connection!=null)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
585 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
586 _header.position(_header.position()-2);
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
587 _header.putQ((byte)',');
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
588 _header.putQ(connection.toString().getBytes());
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
589 _header.putQ(CRLF);
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
590 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
591 }
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
592 else if (keep_alive)
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
593 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
594 _header.putQ(CONNECTION_KEEP_ALIVE);
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
595 if (connection!=null)
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
596 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
597 _header.position(_header.position()-2);
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
598 _header.putQ((byte)',');
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
599 _header.putQ(connection.toString().getBytes());
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
600 _header.putQ(CRLF);
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
601 }
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
602 }
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
603 else if (connection!=null)
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
604 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
605 _header.putQ(CONNECTION_);
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
606 _header.putQ(connection.toString().getBytes());
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
607 _header.putQ(CRLF);
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
608 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
609
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
610 if (!has_server && _status>199)
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
611 _header.putQ(SERVER);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
612
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
613 // end the header.
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
614 _header.putQ(HttpTokens.CRLF);
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
615 _state = STATE_CONTENT;
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 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
618 catch(ArrayIndexOutOfBoundsException e)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
619 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
620 throw new RuntimeException("Header>"+_header.remaining(),e);
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
621 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
622 }
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 /* ------------------------------------------------------------ */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
625 /**
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
626 * Complete the message.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
627 *
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
628 * @throws IOException
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
629 */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
630 public void complete() throws IOException
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 if (_state == STATE_END)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
633 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
634
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
635 complete2();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
636
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
637 if (_state < STATE_FLUSHING)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
638 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
639 _state = STATE_FLUSHING;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
640 if (_contentLength == HttpTokens.CHUNKED_CONTENT)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
641 _needEOC = true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
642 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
643
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
644 flushBuffer();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
645 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
646
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
647 public int flushBuffer() throws IOException
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
648 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
649 try
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 (_state == STATE_HEADER)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
653 throw new IllegalStateException("State==HEADER");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
654
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
655 prepareBuffers();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
656
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
657 int total= 0;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
658
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
659 int len = -1;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
660 int to_flush = flushMask();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
661 int last_flush;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
662
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
663 do
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
664 {
1059
013939bfc9e8 remove JBuffer.poke()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1058
diff changeset
665 last_flush = to_flush;
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
666 switch (to_flush)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
667 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
668 //qqq
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
669 case 7:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
670 throw new IllegalStateException(); // should never happen!
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
671 case 6:
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
672 _header.flip();
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
673 len = _endp.flush(_header, _buffer, null);
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
674 _header.compact();
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
675 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
676 case 5:
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
677 _header.flip();
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
678 len = _endp.flush(_header, _content, null);
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
679 _header.compact();
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
680 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
681 case 4:
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
682 _header.flip();
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
683 len = _endp.flush(_header);
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
684 _header.compact();
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
685 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
686 case 3:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
687 len = _endp.flush(_buffer, _content, null);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
688 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
689 case 2:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
690 len = _endp.flush(_buffer);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
691 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
692 case 1:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
693 len = _endp.flush(_content);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
694 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
695 case 0:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
696 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
697 len=0;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
698 // Nothing more we can write now.
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
699 _header.clear();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
700
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
701 _bypass = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
702 _bufferChunked = false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
703
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
704 if (_buffer != null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
705 {
1065
158d1e6ac17f fix JBuffer.compact()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1064
diff changeset
706 _buffer.clearJ();
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
707 if (_contentLength == HttpTokens.CHUNKED_CONTENT)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
708 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
709 // Special case handling for small left over buffer from
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
710 // an addContent that caused a buffer flush.
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1036
diff changeset
711 if (_content != null && _content.remaining() < _buffer.space() && _state != STATE_FLUSHING)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
712 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
713 _buffer.put(_content);
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
714 _content = null;
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
715 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
716 }
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 // Are we completely finished for now?
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
720 if (!_needCRLF && !_needEOC && (_content==null || !_content.hasRemaining()))
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
721 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
722 if (_state == STATE_FLUSHING)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
723 _state = STATE_END;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
724
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
725 if (_state==STATE_END && _persistent != null && !_persistent && _status!=100)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
726 _endp.shutdownOutput();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
727 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
728 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
729 // Try to prepare more to write.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
730 prepareBuffers();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
731 }
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
734
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
735 if (len > 0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
736 total+=len;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
737
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
738 to_flush = flushMask();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
739 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
740 // 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
741 while (len>0 || (to_flush!=0 && last_flush==0));
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
742
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
743 return total;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
744 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
745 catch (IOException e)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
746 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
747 LOG.trace("",e);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
748 throw (e instanceof EofException) ? e:new EofException(e);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
749 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
750 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
751
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
752 private int flushMask()
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
753 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
754 return ((_header.position() > 0)?4:0)
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1036
diff changeset
755 | ((_buffer != null && _buffer.remaining() > 0)?2:0)
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
756 | ((_bypass && _content != null && _content.hasRemaining())?1:0);
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
757 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
758
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
759 private void prepareBuffers()
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
760 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
761 // if we are not flushing an existing chunk
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
762 if (!_bufferChunked)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
763 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
764 // Refill buffer if possible
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
765 if (!_bypass && _content != null && _content.hasRemaining() && _buffer != null && _buffer.space() > 0)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
766 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
767 int len = _buffer.put(_content);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
768 _content.skip(len);
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
769 if (!_content.hasRemaining())
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
770 _content = null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
771 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
772
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
773 // Chunk buffer if need be
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
774 if (_contentLength == HttpTokens.CHUNKED_CONTENT)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
775 {
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1036
diff changeset
776 if (_bypass && (_buffer==null||_buffer.remaining()==0) && _content!=null)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
777 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
778 // this is a bypass write
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1036
diff changeset
779 int size = _content.remaining();
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
780 _bufferChunked = true;
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 // if we need CRLF add this to header
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
783 if (_needCRLF)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
784 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
785 if (_header.position() > 0) throw new IllegalStateException("EOC");
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
786 _header.putQ(HttpTokens.CRLF);
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
787 _needCRLF = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
788 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
789 // Add the chunk size to the header
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
790 BufferUtil.putHexInt(_header, size);
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
791 _header.putQ(HttpTokens.CRLF);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
792
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
793 // Need a CRLF after the content
983
23ec25435b8c simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 982
diff changeset
794 _needCRLF = true;
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
795 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
796 else if (_buffer!=null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
797 {
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1036
diff changeset
798 int size = _buffer.remaining();
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
799 if (size > 0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
800 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
801 // Prepare a chunk!
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
802 _bufferChunked = true;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
803
1059
013939bfc9e8 remove JBuffer.poke()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1058
diff changeset
804 if (_needCRLF)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
805 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
806 if (_header.position() > 0) throw new IllegalStateException("EOC");
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
807 _header.putQ(HttpTokens.CRLF);
1059
013939bfc9e8 remove JBuffer.poke()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1058
diff changeset
808 _needCRLF = false;
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
809 }
1059
013939bfc9e8 remove JBuffer.poke()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1058
diff changeset
810 BufferUtil.putHexInt(_header, size);
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
811 _header.putQ(HttpTokens.CRLF);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
812
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
813 // Add end chunk trailer.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
814 if (_buffer.space() >= 2)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
815 _buffer.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
816 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
817 _needCRLF = true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
818 }
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 we need EOC and everything written
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
822 if (_needEOC && (_content == null || !_content.hasRemaining()))
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
823 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
824 if (_needCRLF)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
825 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
826 if (_buffer == null && _header.remaining() >= HttpTokens.CRLF.length)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
827 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
828 _header.putQ(HttpTokens.CRLF);
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
829 _needCRLF = false;
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 else if (_buffer!=null && _buffer.space() >= HttpTokens.CRLF.length)
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 _buffer.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
834 _needCRLF = false;
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 if (!_needCRLF && _needEOC)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
839 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
840 if (_buffer == null && _header.remaining() >= LAST_CHUNK.length)
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
841 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
842 if (!_head)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
843 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
844 _header.putQ(LAST_CHUNK);
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
845 _bufferChunked=true;
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 _needEOC = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
848 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
849 else if (_buffer!=null && _buffer.space() >= LAST_CHUNK.length)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
850 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
851 if (!_head)
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 _buffer.put(LAST_CHUNK);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
854 _bufferChunked=true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
855 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
856 _needEOC = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
857 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
858 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
859 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
860 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
861 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
862
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
863 if (_content != null && !_content.hasRemaining())
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
864 _content = null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
865
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
866 }
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 @Override
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
869 public String toString()
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
870 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
871 JBuffer header = _header;
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1039
diff changeset
872 JBuffer buffer=_buffer;
1069
7dd6ec499000 fix use of HttpGenerator._content
Franklin Schmidt <fschmidt@gmail.com>
parents: 1068
diff changeset
873 JBuffer content = _content;
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
874 return String.format("%s{s=%d,h=%d,b=%d,c=%d}",
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
875 getClass().getSimpleName(),
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
876 _state,
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
877 header == null ? -1 : header.position(),
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1036
diff changeset
878 buffer == null ? -1 : buffer.remaining(),
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1036
diff changeset
879 content == null ? -1 : content.remaining());
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
880 }
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
881
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
882
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
883
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
884
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
885
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
886
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
887
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
888
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
889
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
890
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
891
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
892
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
893 // AbstractGenerator
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
894
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
895 public static final boolean LAST=true;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
896 public static final boolean MORE=false;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
897
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
898 // states
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
899 private final static int STATE_HEADER = 0;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
900 private final static int STATE_CONTENT = 2;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
901 private final static int STATE_FLUSHING = 3;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
902 private final static int STATE_END = 4;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
903
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
904 // data
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
905
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
906 private final Buffers _buffers; // source of buffers
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
907 private final EndPoint _endp;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
908
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
909 private int _state = STATE_HEADER;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
910
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
911 private int _status = 0;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
912 private int _version = HttpVersions.HTTP_1_1_ORDINAL;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
913 private JBuffer _reason;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
914
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
915 private long _contentWritten = 0;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
916 private long _contentLength = HttpTokens.UNKNOWN_CONTENT;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
917 private boolean _last = false;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
918 private boolean _head = false;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
919 private boolean _noContent = false;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
920 private Boolean _persistent = null;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
921
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
922 private final JBuffer _header; // JBuffer for HTTP header (and maybe small _content)
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1067
diff changeset
923 private final JBuffer _buffer; // JBuffer for copy of passed _content
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
924 private JBuffer _content; // JBuffer passed to addContent
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
925
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
926
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
927 public HttpGenerator(Buffers buffers, EndPoint io)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
928 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
929 this._buffers = buffers;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
930 this._endp = io;
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
931 _header = _buffers.getHeader();
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1067
diff changeset
932 _buffer = _buffers.getBuffer();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1067
diff changeset
933 _buffer.limit(0);
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
934 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
935
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
936 public final boolean isOpen()
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
937 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
938 return _endp.isOpen();
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
939 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
940
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
941 public final void resetBuffer()
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
942 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
943 if(_state>=STATE_FLUSHING)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
944 throw new IllegalStateException("Flushed");
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
945
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
946 _last = false;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
947 _persistent = null;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
948 _contentWritten = 0;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
949 _contentLength = HttpTokens.UNKNOWN_CONTENT;
1059
013939bfc9e8 remove JBuffer.poke()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1058
diff changeset
950 _content = null;
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
951 if (_buffer!=null)
1065
158d1e6ac17f fix JBuffer.compact()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1064
diff changeset
952 _buffer.clearJ();
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
953 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
954
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
955 /* ------------------------------------------------------------ */
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
956 /**
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
957 * @return Returns the contentBufferSize.
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
958 */
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
959 public final int getContentBufferSize()
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
960 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
961 return _buffer.capacity();
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
962 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
963
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
964 public final JBuffer getUncheckedBuffer()
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
965 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
966 return _buffer;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
967 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
968
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
969 public final boolean isComplete()
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
970 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
971 return _state == STATE_END;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
972 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
973
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
974 public final boolean isIdle()
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
975 {
1058
419bf9c03d84 remove HttpGenerator._method
Franklin Schmidt <fschmidt@gmail.com>
parents: 1057
diff changeset
976 return _state == STATE_HEADER && _status==0;
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
977 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
978
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
979 public final boolean isCommitted()
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
980 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
981 return _state != STATE_HEADER;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
982 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
983
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
984 public final void setContentLength(long value)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
985 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
986 if (value<0)
1059
013939bfc9e8 remove JBuffer.poke()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1058
diff changeset
987 _contentLength = HttpTokens.UNKNOWN_CONTENT;
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
988 else
1059
013939bfc9e8 remove JBuffer.poke()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1058
diff changeset
989 _contentLength = value;
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
990 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
991
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
992 public final void setHead(boolean head)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
993 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
994 _head = head;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
995 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
996
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
997 /* ------------------------------------------------------------ */
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
998 /**
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
999 * @return <code>false</code> if the connection should be closed after a request has been read,
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1000 * <code>true</code> if it should be used for additional requests.
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1001 */
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1002 public final boolean isPersistent()
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1003 {
1059
013939bfc9e8 remove JBuffer.poke()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1058
diff changeset
1004 return _persistent!=null ? _persistent.booleanValue() : _version>HttpVersions.HTTP_1_0_ORDINAL;
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1005 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1006
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1007 public final void setPersistent(boolean persistent)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1008 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1009 _persistent = persistent;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1010 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1011
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1012 /* ------------------------------------------------------------ */
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1013 /**
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1014 * @param version The version of the client the response is being sent to (NB. Not the version
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1015 * in the response, which is the version of the server).
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1016 */
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1017 public final void setVersion(int version)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1018 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1019 if (_state != STATE_HEADER)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1020 throw new IllegalStateException("STATE!=START "+_state);
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1021 _version = version;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1022 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1023
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1024 /* ------------------------------------------------------------ */
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1025 /**
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1026 * @param status The status code to send.
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1027 * @param reason the status message to send.
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1028 */
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1029 public final void setResponse(int status, String reason)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1030 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1031 if (_state != STATE_HEADER) throw new IllegalStateException("STATE!=START");
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1032 _status = status;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1033 if (reason!=null)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1034 {
1067
56b515be91e1 fix use of HttpGenerator._reason
Franklin Schmidt <fschmidt@gmail.com>
parents: 1066
diff changeset
1035 int len = reason.length();
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1036
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1037 // TODO don't hard code
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1038 if (len>1024)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1039 len=1024;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1040 _reason = BufferUtil.newBuffer(len);
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1041 for (int i=0;i<len;i++)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1042 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1043 char ch = reason.charAt(i);
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1044 if (ch!='\r'&&ch!='\n')
1067
56b515be91e1 fix use of HttpGenerator._reason
Franklin Schmidt <fschmidt@gmail.com>
parents: 1066
diff changeset
1045 _reason.putQ((byte)ch);
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1046 else
1067
56b515be91e1 fix use of HttpGenerator._reason
Franklin Schmidt <fschmidt@gmail.com>
parents: 1066
diff changeset
1047 _reason.putQ((byte)' ');
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1048 }
1067
56b515be91e1 fix use of HttpGenerator._reason
Franklin Schmidt <fschmidt@gmail.com>
parents: 1066
diff changeset
1049 _reason.flip();
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1050 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1051 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1052
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1053 public final void completeUncheckedAddContent()
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1054 {
1064
a0abb16cf6e7 remove JBuffer.readFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1059
diff changeset
1055 _contentWritten += _buffer.remaining();
a0abb16cf6e7 remove JBuffer.readFrom()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1059
diff changeset
1056 if (_head)
1065
158d1e6ac17f fix JBuffer.compact()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1064
diff changeset
1057 _buffer.clearJ();
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1058 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1059
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1060 private boolean isBufferFull2()
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1061 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1062 if (_buffer != null && _buffer.space()==0)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1063 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1064 if (_buffer.remaining()==0)
1065
158d1e6ac17f fix JBuffer.compact()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1064
diff changeset
1065 _buffer.limit(0);
1057
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1066 return _buffer.space()==0;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1067 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1068
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1069 return _content!=null && _content.remaining()>0;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1070 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1071
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1072 public final boolean isWritten()
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1073 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1074 return _contentWritten>0;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1075 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1076
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1077 public final boolean isAllContentWritten()
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1078 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1079 return _contentLength>=0 && _contentWritten>=_contentLength;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1080 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1081
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1082
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1083 private void complete2() throws IOException
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1084 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1085 if (_state == STATE_HEADER)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1086 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1087 throw new IllegalStateException("State==HEADER");
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1088 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1089
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1090 if (_contentLength >= 0 && _contentLength != _contentWritten && !_head)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1091 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1092 if (LOG.isDebugEnabled())
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1093 LOG.debug("ContentLength written=="+_contentWritten+" != contentLength=="+_contentLength);
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1094 _persistent = false;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1095 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1096 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1097
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1098
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1099 public final void flush(long maxIdleTime) throws IOException
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1100 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1101 // block until everything is flushed
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1102 long now=System.currentTimeMillis();
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1103 long end=now+maxIdleTime;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1104 JBuffer content = _content;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1105 JBuffer buffer = _buffer;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1106 if (content!=null && content.remaining()>0 || buffer!=null && buffer.remaining()>0 || isBufferFull())
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1107 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1108 flushBuffer();
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1109
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1110 while (now<end && (content!=null && content.remaining()>0 ||buffer!=null && buffer.remaining()>0) && _endp.isOpen()&& !_endp.isOutputShutdown())
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1111 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1112 blockForOutput(end-now);
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1113 now=System.currentTimeMillis();
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1114 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1115 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1116 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1117
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1118 /* ------------------------------------------------------------ */
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1119 /**
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1120 * Utility method to send an error response. If the builder is not committed, this call is
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1121 * equivalent to a setResponse, addContent and complete call.
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1122 *
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1123 * @param code The error code
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1124 * @param reason The error reason
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1125 * @param content Contents of the error page
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1126 * @param close True if the connection should be closed
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1127 * @throws IOException if there is a problem flushing the response
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1128 */
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1129 public final void sendError(int code, String reason, String content, boolean close) throws IOException
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1130 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1131 if (close)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1132 _persistent=false;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1133 if (isCommitted())
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1134 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1135 LOG.debug("sendError on committed: {} {}",code,reason);
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1136 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1137 else
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1138 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1139 LOG.debug("sendError: {} {}",code,reason);
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1140 setResponse(code, reason);
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1141 if (content != null)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1142 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1143 completeHeader(null, false);
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1144 addContent(BufferUtil.wrap(content), LAST);
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1145 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1146 else if (code>=400)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1147 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1148 completeHeader(null, false);
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1149 addContent(BufferUtil.wrap("Error: "+(reason==null?(""+code):reason)), LAST);
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1150 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1151 else
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1152 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1153 completeHeader(null, true);
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1154 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1155 complete();
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1156 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1157 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1158
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1159 public final long getContentWritten()
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1160 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1161 return _contentWritten;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1162 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1163
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1164
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1165 public final void blockForOutput(long maxIdleTime) throws IOException
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1166 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1167 if (_endp.isBlocking())
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1168 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1169 try
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1170 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1171 flushBuffer();
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1172 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1173 catch(IOException e)
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1174 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1175 _endp.close();
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1176 throw e;
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1177 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1178 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1179 else
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1180 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1181 if (!_endp.blockWritable(maxIdleTime))
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1182 {
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1183 _endp.close();
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1184 throw new EofException("timeout");
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1185 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1186
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1187 flushBuffer();
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1188 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1189 }
afc9610dc12e remove AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 1048
diff changeset
1190
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1191 }