annotate src/org/eclipse/jetty/http/HttpGenerator.java @ 1021:e350c11242be

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