annotate src/org/eclipse/jetty/http/HttpGenerator.java @ 879:a3775d0c6985

remove ShutdownThread
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 04 Oct 2016 15:55:02 -0600
parents fef4392f4905
children cb78ee27b0e0
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.BufferCache.CachedBuffer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 import org.eclipse.jetty.io.BufferUtil;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 import org.eclipse.jetty.io.Buffers;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 import org.eclipse.jetty.io.ByteArrayBuffer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 import org.eclipse.jetty.io.EndPoint;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 import org.eclipse.jetty.io.EofException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 import org.eclipse.jetty.util.StringUtil;
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 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 public class HttpGenerator extends AbstractGenerator
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 _reason;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
50 Buffer _schemeCode;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
51 Buffer _responseLine;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
52 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
53 private static final Status[] __status = new Status[HttpStatus.MAX_CODE+1];
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
54 static
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
55 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
56 int versionLength=HttpVersions.HTTP_1_1_BUFFER.length();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
58 for (int i=0;i<__status.length;i++)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
59 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
60 HttpStatus.Code code = HttpStatus.getCode(i);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
61 if (code==null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
62 continue;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
63 String reason=code.getMessage();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
64 byte[] bytes=new byte[versionLength+5+reason.length()+2];
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
65 HttpVersions.HTTP_1_1_BUFFER.peek(0,bytes, 0, versionLength);
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]._reason=new ByteArrayBuffer(bytes,versionLength+5,bytes.length-versionLength-7,Buffer.IMMUTABLE);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
78 __status[i]._schemeCode=new ByteArrayBuffer(bytes,0,versionLength+5,Buffer.IMMUTABLE);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
79 __status[i]._responseLine=new ByteArrayBuffer(bytes,0,bytes.length,Buffer.IMMUTABLE);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
80 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
81 }
802
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 /* ------------------------------------------------------------------------------- */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 public static Buffer getReasonBuffer(int code)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
86 Status status = code<__status.length?__status[code]:null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
87 if (status!=null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
88 return status._reason;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
89 return null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
90 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
93 // common _content
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
94 private static final byte[] LAST_CHUNK =
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
95 { (byte) '0', (byte) '\015', (byte) '\012', (byte) '\015', (byte) '\012'};
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
96 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
97 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
98 private static final byte[] CONNECTION_CLOSE = StringUtil.getBytes("Connection: close\015\012");
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
99 private static final byte[] CONNECTION_ = StringUtil.getBytes("Connection: ");
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
100 private static final byte[] CRLF = StringUtil.getBytes("\015\012");
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
101 private static final byte[] TRANSFER_ENCODING_CHUNKED = StringUtil.getBytes("Transfer-Encoding: chunked\015\012");
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102 private static byte[] SERVER = StringUtil.getBytes("Server: Jetty(7.0.x)\015\012");
802
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 // other statics
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
105 private static final int CHUNK_SPACE = 12;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
106
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 public static void setServerVersion(String version)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
108 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
109 SERVER=StringUtil.getBytes("Server: Jetty("+version+")\015\012");
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
110 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
111
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 // data
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113 protected boolean _bypass = false; // True if _content buffer can be written directly to endp and bypass the content buffer
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 private boolean _needCRLF = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
115 private boolean _needEOC = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
116 private boolean _bufferChunked = false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
118
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
119 /* ------------------------------------------------------------------------------- */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
120 /**
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
121 * Constructor.
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 * @param buffers buffer pool
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
124 * @param io the end point to use
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
126 public HttpGenerator(Buffers buffers, EndPoint io)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
127 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
128 super(buffers,io);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
129 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
130
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
131 /* ------------------------------------------------------------------------------- */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
132 @Override
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
133 public void reset()
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
134 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
135 if (_persistent!=null && !_persistent && _endp!=null && !_endp.isOutputShutdown())
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
136 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
137 try
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
138 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
139 _endp.shutdownOutput();
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 catch(IOException e)
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 LOG.trace("",e);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
144 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
145 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
146 super.reset();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
147 if (_buffer!=null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
148 _buffer.clear();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
149 if (_header!=null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
150 _header.clear();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
151 if (_content!=null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
152 _content=null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
153 _bypass = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
154 _needCRLF = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 _needEOC = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 _bufferChunked=false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 _method=null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
158 _uri=null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
159 _noContent=false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
160 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
161
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
162 /* ------------------------------------------------------------ */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 /**
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
164 * Add content.
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 * @param content
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
167 * @param last
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
168 * @throws IllegalArgumentException if <code>content</code> is {@link Buffer#isImmutable immutable}.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
169 * @throws IllegalStateException If the request is not expecting any more content,
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
170 * or if the buffers are full and cannot be flushed.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
171 * @throws IOException if there is a problem flushing the buffers.
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 public void addContent(Buffer content, boolean last) throws IOException
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
175 if (_noContent)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
176 throw new IllegalStateException("NO CONTENT");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
178 if (_last || _state==STATE_END)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
180 LOG.warn("Ignoring extra content {}",content);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
181 content.clear();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 return;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
183 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
184 _last = last;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
185
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 // Handle any unfinished business?
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 if (_content!=null && _content.length()>0 || _bufferChunked)
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 if (_endp.isOutputShutdown())
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 throw new EofException();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
191 flushBuffer();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
192 if (_content != null && _content.length()>0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
193 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
194 if (_bufferChunked)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
195 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 Buffer nc=_buffers.getBuffer(_content.length()+CHUNK_SPACE+content.length());
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 nc.put(_content);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 nc.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 BufferUtil.putHexInt(nc, content.length());
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
200 nc.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 nc.put(content);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
202 content=nc;
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
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 Buffer nc=_buffers.getBuffer(_content.length()+content.length());
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 nc.put(_content);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
208 nc.put(content);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
209 content=nc;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
210 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
211 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
212 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
213
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
214 _content = content;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
215 _contentWritten += content.length();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
216
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
217 // Handle the _content
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 if (_head)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
219 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
220 content.clear();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
221 _content=null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
223 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
224 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
225 _bypass = true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
226 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
227 else if (!_bufferChunked)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
228 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
229 // Yes - so we better check we have a buffer
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 if (_buffer == null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
231 _buffer = _buffers.getBuffer();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
232
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
233 // Copy _content to buffer;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
234 int len=_buffer.put(_content);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
235 _content.skip(len);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236 if (_content.length() == 0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
237 _content = null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 }
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 /* ------------------------------------------------------------ */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
242 /**
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
243 * send complete response.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 *
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
245 * @param response
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
246 */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
247 public void sendResponse(Buffer response) throws IOException
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
248 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
249 if (_noContent || _state!=STATE_HEADER || _content!=null && _content.length()>0 || _bufferChunked || _head )
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
250 throw new IllegalStateException();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
251
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
252 _last = true;
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 _content = response;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
255 _bypass = true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
256 _state = STATE_FLUSHING;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
257
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
258 // TODO this is not exactly right, but should do.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
259 _contentLength =_contentWritten = response.length();
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
262
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
263 /* ------------------------------------------------------------ */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
264 /** Prepare buffer for unchecked writes.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
265 * Prepare the generator buffer to receive unchecked writes
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
266 * @return the available space in the buffer.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
267 * @throws IOException
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
268 */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
269 @Override
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
270 public int prepareUncheckedAddContent() throws IOException
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
271 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
272 if (_noContent)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
273 return -1;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
274
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
275 if (_last || _state==STATE_END)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
276 return -1;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
277
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
278 // Handle any unfinished business?
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 Buffer content = _content;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
280 if (content != null && content.length()>0 || _bufferChunked)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
281 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
282 flushBuffer();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
283 if (content != null && content.length()>0 || _bufferChunked)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284 throw new IllegalStateException("FULL");
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
285 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
286
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
287 // we better check we have a buffer
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
288 if (_buffer == null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
289 _buffer = _buffers.getBuffer();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
290
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
291 _contentWritten-=_buffer.length();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
292
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
293 // Handle the _content
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
294 if (_head)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
295 return Integer.MAX_VALUE;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
296
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
297 return _buffer.space()-(_contentLength == HttpTokens.CHUNKED_CONTENT?CHUNK_SPACE:0);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
298 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
299
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 @Override
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
302 public boolean isBufferFull()
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
304 // Should we flush the buffers?
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
305 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
306 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
307
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
308 /* ------------------------------------------------------------ */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309 public void send1xx(int code) throws IOException
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
311 if (_state != STATE_HEADER)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
312 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
313
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
314 if (code<100||code>199)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
315 throw new IllegalArgumentException("!1xx");
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
316 Status status=__status[code];
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
317 if (status==null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
318 throw new IllegalArgumentException(code+"?");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
319
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
320 // get a header buffer
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
321 if (_header == null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
322 _header = _buffers.getHeader();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
323
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
324 _header.put(status._responseLine);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
325 _header.put(HttpTokens.CRLF);
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 try
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
328 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
329 // nasty semi busy flush!
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
330 while(_header.length()>0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
331 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
332 int len = _endp.flush(_header);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
333 if (len<0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
334 throw new EofException();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
335 if (len==0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
336 Thread.sleep(100);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
337 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
338 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
339 catch(InterruptedException e)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
340 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
341 LOG.debug("",e);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342 throw new InterruptedIOException(e.toString());
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
343 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
344 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
345
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346 /* ------------------------------------------------------------ */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
347 @Override
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
348 public boolean isRequest()
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
349 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
350 return _method!=null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
351 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
352
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
353 /* ------------------------------------------------------------ */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
354 @Override
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
355 public boolean isResponse()
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
356 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
357 return _method==null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
358 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
359
877
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 @Override
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
362 public void completeHeader(HttpFields fields, boolean allContentAdded) throws IOException
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
363 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
364 if (_state != STATE_HEADER)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
365 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
366
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
367 // handle a reset
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
368 if (isResponse() && _status==0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
369 throw new EofException();
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 if (_last && !allContentAdded)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
372 throw new IllegalStateException("last?");
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
373 _last = _last | allContentAdded;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
374
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
375 // get a header buffer
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
376 if (_header == null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
377 _header = _buffers.getHeader();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
378
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
379 boolean has_server = false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
380
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
381 try
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
382 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
383 if (isRequest())
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
384 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
385 _persistent=true;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
386
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
387 if (_version == HttpVersions.HTTP_0_9_ORDINAL)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
388 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
389 _contentLength = HttpTokens.NO_CONTENT;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
390 _header.put(_method);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
391 _header.put((byte)' ');
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
392 _header.put(_uri.getBytes("UTF-8")); // TODO check
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
393 _header.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
394 _state = STATE_FLUSHING;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
395 _noContent=true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
396 return;
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 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
399 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
400 _header.put(_method);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
401 _header.put((byte)' ');
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
402 _header.put(_uri.getBytes("UTF-8")); // TODO check
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
403 _header.put((byte)' ');
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
404 _header.put(_version==HttpVersions.HTTP_1_0_ORDINAL?HttpVersions.HTTP_1_0_BUFFER:HttpVersions.HTTP_1_1_BUFFER);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
405 _header.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
406 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
407 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
408 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
409 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
410 // Responses
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
411 if (_version == HttpVersions.HTTP_0_9_ORDINAL)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
412 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
413 _persistent = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
414 _contentLength = HttpTokens.EOF_CONTENT;
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 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
419 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
420 if (_persistent==null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
421 _persistent= (_version > HttpVersions.HTTP_1_0_ORDINAL);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
422
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
423 // add response line
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
424 Status status = _status<__status.length?__status[_status]:null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
425
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
426 if (status==null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
427 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
428 _header.put(HttpVersions.HTTP_1_1_BUFFER);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
429 _header.put((byte) ' ');
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
430 _header.put((byte) ('0' + _status / 100));
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
431 _header.put((byte) ('0' + (_status % 100) / 10));
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
432 _header.put((byte) ('0' + (_status % 10)));
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
433 _header.put((byte) ' ');
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
434 if (_reason==null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
435 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
436 _header.put((byte) ('0' + _status / 100));
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
437 _header.put((byte) ('0' + (_status % 100) / 10));
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
438 _header.put((byte) ('0' + (_status % 10)));
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
439 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
440 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
441 _header.put(_reason);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
442 _header.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
443 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
444 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
445 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
446 if (_reason==null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
447 _header.put(status._responseLine);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
448 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
449 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
450 _header.put(status._schemeCode);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
451 _header.put(_reason);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
452 _header.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
453 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
454 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
455
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
456 if (_status<200 && _status>=100 )
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
457 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
458 _noContent=true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
459 _content=null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
460 if (_buffer!=null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
461 _buffer.clear();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
462 // end the header.
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 if (_status!=101 )
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
465 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
466 _header.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
467 _state = STATE_CONTENT;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
468 return;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
469 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
470 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
471 else if (_status==204 || _status==304)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
472 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
473 _noContent=true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
474 _content=null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
475 if (_buffer!=null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
476 _buffer.clear();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
477 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
478 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
479 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
480
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
481 // Add headers
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
482 if (_status>=200 && _date!=null)
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 _header.put(HttpHeaders.DATE_BUFFER);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
485 _header.put((byte)':');
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
486 _header.put((byte)' ');
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
487 _header.put(_date);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
488 _header.put(CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
489 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
490
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
491 // key field values
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
492 HttpFields.Field content_length = null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
493 HttpFields.Field transfer_encoding = null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
494 boolean keep_alive = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
495 boolean close=false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
496 boolean content_type=false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
497 StringBuilder connection = null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
498
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
499 if (fields != null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
500 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
501 int s=fields.size();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
502 for (int f=0;f<s;f++)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
503 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
504 HttpFields.Field field = fields.getField(f);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
505 if (field==null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
506 continue;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
507
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
508 switch (field.getNameOrdinal())
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
509 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
510 case HttpHeaders.CONTENT_LENGTH_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
511 content_length = field;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
512 _contentLength = field.getLongValue();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
513
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
514 if (_contentLength < _contentWritten || _last && _contentLength != _contentWritten)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
515 content_length = null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
516
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
517 // write the field to the header buffer
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
518 field.putTo(_header);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
519 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
520
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
521 case HttpHeaders.CONTENT_TYPE_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
522 if (BufferUtil.isPrefix(MimeTypes.MULTIPART_BYTERANGES_BUFFER, field.getValueBuffer())) _contentLength = HttpTokens.SELF_DEFINING_CONTENT;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
523
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
524 // write the field to the header buffer
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
525 content_type=true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
526 field.putTo(_header);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
527 break;
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 case HttpHeaders.TRANSFER_ENCODING_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
530 if (_version == HttpVersions.HTTP_1_1_ORDINAL)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
531 transfer_encoding = field;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
532 // Do NOT add yet!
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
533 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
534
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
535 case HttpHeaders.CONNECTION_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
536 if (isRequest())
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
537 field.putTo(_header);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
538
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
539 int connection_value = field.getValueOrdinal();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
540 switch (connection_value)
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 case -1:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
543 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
544 String[] values = field.getValue().split(",");
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
545 for (int i=0;values!=null && i<values.length;i++)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
546 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
547 CachedBuffer cb = HttpHeaderValues.CACHE.get(values[i].trim());
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
548
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
549 if (cb!=null)
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 switch(cb.getOrdinal())
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 case HttpHeaderValues.CLOSE_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
554 close=true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
555 if (isResponse())
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
556 _persistent=false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
557 keep_alive=false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
558 if (!_persistent && isResponse() && _contentLength == HttpTokens.UNKNOWN_CONTENT)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
559 _contentLength = HttpTokens.EOF_CONTENT;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
560 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
561
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
562 case HttpHeaderValues.KEEP_ALIVE_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
563 if (_version == HttpVersions.HTTP_1_0_ORDINAL)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
564 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
565 keep_alive = true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
566 if (isResponse())
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
567 _persistent = true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
568 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
569 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
570
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
571 default:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
572 if (connection==null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
573 connection=new StringBuilder();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
574 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
575 connection.append(',');
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
576 connection.append(values[i]);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
577 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
578 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
579 else
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 if (connection==null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
582 connection=new StringBuilder();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
583 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
584 connection.append(',');
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
585 connection.append(values[i]);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
586 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
587 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
588
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
589 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
590 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
591 case HttpHeaderValues.UPGRADE_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
592 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
593 // special case for websocket connection ordering
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
594 if (isResponse())
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
595 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
596 field.putTo(_header);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
597 continue;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
598 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
599 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
600 case HttpHeaderValues.CLOSE_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
601 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
602 close=true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
603 if (isResponse())
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
604 _persistent=false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
605 if (!_persistent && isResponse() && _contentLength == HttpTokens.UNKNOWN_CONTENT)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
606 _contentLength = HttpTokens.EOF_CONTENT;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
607 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
608 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
609 case HttpHeaderValues.KEEP_ALIVE_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
610 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
611 if (_version == HttpVersions.HTTP_1_0_ORDINAL)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
612 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
613 keep_alive = true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
614 if (isResponse())
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
615 _persistent=true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
616 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
617 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
618 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
619 default:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
620 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
621 if (connection==null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
622 connection=new StringBuilder();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
623 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
624 connection.append(',');
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
625 connection.append(field.getValue());
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
626 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
627 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
628
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
629 // Do NOT add yet!
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
630 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
631
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
632 case HttpHeaders.SERVER_ORDINAL:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
633 has_server=true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
634 field.putTo(_header);
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 default:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
638 // write the field to the header buffer
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
639 field.putTo(_header);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
640 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
641 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
642 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
643
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
644 // Calculate how to end _content and connection, _content length and transfer encoding
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
645 // settings.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
646 // From RFC 2616 4.4:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
647 // 1. No body for 1xx, 204, 304 & HEAD response
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
648 // 2. Force _content-length?
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
649 // 3. If Transfer-Encoding!=identity && HTTP/1.1 && !HttpConnection==close then chunk
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
650 // 4. Content-Length
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
651 // 5. multipart/byteranges
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
652 // 6. close
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
653 switch ((int) _contentLength)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
654 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
655 case HttpTokens.UNKNOWN_CONTENT:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
656 // 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
657 // written yet?
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
658
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
659 // Response known not to have a body
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
660 if (_contentWritten == 0 && isResponse() && (_status < 200 || _status == 204 || _status == 304))
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
661 _contentLength = HttpTokens.NO_CONTENT;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
662 else if (_last)
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 // we have seen all the _content there is
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
665 _contentLength = _contentWritten;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
666 if (content_length == null && (isResponse() || _contentLength>0 || content_type ) && !_noContent)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
667 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
668 // known length but not actually set.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
669 _header.put(HttpHeaders.CONTENT_LENGTH_BUFFER);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
670 _header.put(HttpTokens.COLON);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
671 _header.put((byte) ' ');
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
672 BufferUtil.putDecLong(_header, _contentLength);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
673 _header.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
674 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
675 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
676 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
677 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
678 // No idea, so we must assume that a body is coming
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
679 _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
680 if (isRequest() && _contentLength==HttpTokens.EOF_CONTENT)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
681 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
682 _contentLength=HttpTokens.NO_CONTENT;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
683 _noContent=true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
684 }
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 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
687
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
688 case HttpTokens.NO_CONTENT:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
689 if (content_length == null && isResponse() && _status >= 200 && _status != 204 && _status != 304)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
690 _header.put(CONTENT_LENGTH_0);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
691 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
692
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
693 case HttpTokens.EOF_CONTENT:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
694 _persistent = isRequest();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
695 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
696
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
697 case HttpTokens.CHUNKED_CONTENT:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
698 break;
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 default:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
701 // TODO - maybe allow forced chunking by setting te ???
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
702 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
703 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
704
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
705 // Add transfer_encoding if needed
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
706 if (_contentLength == HttpTokens.CHUNKED_CONTENT)
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 // try to use user supplied encoding as it may have other values.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
709 if (transfer_encoding != null && HttpHeaderValues.CHUNKED_ORDINAL != transfer_encoding.getValueOrdinal())
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
710 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
711 String c = transfer_encoding.getValue();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
712 if (c.endsWith(HttpHeaderValues.CHUNKED))
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
713 transfer_encoding.putTo(_header);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
714 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
715 throw new IllegalArgumentException("BAD TE");
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
716 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
717 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
718 _header.put(TRANSFER_ENCODING_CHUNKED);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
719 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
720
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
721 // Handle connection if need be
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
722 if (_contentLength==HttpTokens.EOF_CONTENT)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
723 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
724 keep_alive=false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
725 _persistent=false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
726 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
727
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
728 if (isResponse())
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 if (!_persistent && (close || _version > HttpVersions.HTTP_1_0_ORDINAL))
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
731 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
732 _header.put(CONNECTION_CLOSE);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
733 if (connection!=null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
734 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
735 _header.setPutIndex(_header.putIndex()-2);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
736 _header.put((byte)',');
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
737 _header.put(connection.toString().getBytes());
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
738 _header.put(CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
739 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
740 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
741 else if (keep_alive)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
742 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
743 _header.put(CONNECTION_KEEP_ALIVE);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
744 if (connection!=null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
745 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
746 _header.setPutIndex(_header.putIndex()-2);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
747 _header.put((byte)',');
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
748 _header.put(connection.toString().getBytes());
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
749 _header.put(CRLF);
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 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
752 else if (connection!=null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
753 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
754 _header.put(CONNECTION_);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
755 _header.put(connection.toString().getBytes());
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
756 _header.put(CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
757 }
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 if (!has_server && _status>199)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
761 _header.put(SERVER);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
762
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
763 // end the header.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
764 _header.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
765 _state = STATE_CONTENT;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
766
877
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 catch(ArrayIndexOutOfBoundsException e)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
769 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
770 throw new RuntimeException("Header>"+_header.capacity(),e);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
771 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
772 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
773
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
774 /* ------------------------------------------------------------ */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
775 /**
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
776 * Complete the message.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
777 *
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
778 * @throws IOException
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
779 */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
780 @Override
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
781 public void complete() throws IOException
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
782 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
783 if (_state == STATE_END)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
784 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
785
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
786 super.complete();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
787
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
788 if (_state < STATE_FLUSHING)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
789 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
790 _state = STATE_FLUSHING;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
791 if (_contentLength == HttpTokens.CHUNKED_CONTENT)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
792 _needEOC = true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
793 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
794
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
795 flushBuffer();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
796 }
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 /* ------------------------------------------------------------ */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
799 @Override
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
800 public int flushBuffer() throws IOException
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
801 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
802 try
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
803 {
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
804
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
805 if (_state == STATE_HEADER)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
806 throw new IllegalStateException("State==HEADER");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
807
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
808 prepareBuffers();
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 if (_endp == null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
811 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
812 if (_needCRLF && _buffer!=null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
813 _buffer.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
814 if (_needEOC && _buffer!=null && !_head)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
815 _buffer.put(LAST_CHUNK);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
816 _needCRLF=false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
817 _needEOC=false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
818 return 0;
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 int total= 0;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
822
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
823 int len = -1;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
824 int to_flush = flushMask();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
825 int last_flush;
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 do
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
828 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
829 last_flush=to_flush;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
830 switch (to_flush)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
831 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
832 case 7:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
833 throw new IllegalStateException(); // should never happen!
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
834 case 6:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
835 len = _endp.flush(_header, _buffer, null);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
836 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
837 case 5:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
838 len = _endp.flush(_header, _content, null);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
839 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
840 case 4:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
841 len = _endp.flush(_header);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
842 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
843 case 3:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
844 len = _endp.flush(_buffer, _content, null);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
845 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
846 case 2:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
847 len = _endp.flush(_buffer);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
848 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
849 case 1:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
850 len = _endp.flush(_content);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
851 break;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
852 case 0:
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
853 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
854 len=0;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
855 // Nothing more we can write now.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
856 if (_header != null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
857 _header.clear();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
858
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
859 _bypass = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
860 _bufferChunked = false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
861
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
862 if (_buffer != null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
863 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
864 _buffer.clear();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
865 if (_contentLength == HttpTokens.CHUNKED_CONTENT)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
866 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
867 // reserve some space for the chunk header
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
868 _buffer.setPutIndex(CHUNK_SPACE);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
869 _buffer.setGetIndex(CHUNK_SPACE);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
870
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
871 // Special case handling for small left over buffer from
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
872 // an addContent that caused a buffer flush.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
873 if (_content != null && _content.length() < _buffer.space() && _state != STATE_FLUSHING)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
874 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
875 _buffer.put(_content);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
876 _content.clear();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
877 _content=null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
878 }
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
881
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
882 // Are we completely finished for now?
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
883 if (!_needCRLF && !_needEOC && (_content==null || _content.length()==0))
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
884 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
885 if (_state == STATE_FLUSHING)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
886 _state = STATE_END;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
887
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
888 if (_state==STATE_END && _persistent != null && !_persistent && _status!=100 && _method==null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
889 _endp.shutdownOutput();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
890 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
891 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
892 // Try to prepare more to write.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
893 prepareBuffers();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
894 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
895
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
896 }
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 if (len > 0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
899 total+=len;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
900
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
901 to_flush = flushMask();
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 // 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
904 while (len>0 || (to_flush!=0 && last_flush==0));
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
905
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
906 return total;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
907 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
908 catch (IOException e)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
909 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
910 LOG.trace("",e);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
911 throw (e instanceof EofException) ? e:new EofException(e);
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
914
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
915 /* ------------------------------------------------------------ */
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
916 private int flushMask()
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
917 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
918 return ((_header != null && _header.length() > 0)?4:0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
919 | ((_buffer != null && _buffer.length() > 0)?2:0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
920 | ((_bypass && _content != null && _content.length() > 0)?1:0);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
921 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
922
877
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 private void prepareBuffers()
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
925 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
926 // if we are not flushing an existing chunk
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
927 if (!_bufferChunked)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
928 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
929 // Refill buffer if possible
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
930 if (!_bypass && _content != null && _content.length() > 0 && _buffer != null && _buffer.space() > 0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
931 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
932 int len = _buffer.put(_content);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
933 _content.skip(len);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
934 if (_content.length() == 0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
935 _content = null;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
936 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
937
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
938 // Chunk buffer if need be
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
939 if (_contentLength == HttpTokens.CHUNKED_CONTENT)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
940 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
941 if (_bypass && (_buffer==null||_buffer.length()==0) && _content!=null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
942 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
943 // this is a bypass write
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
944 int size = _content.length();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
945 _bufferChunked = true;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
946
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
947 if (_header == null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
948 _header = _buffers.getHeader();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
949
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
950 // if we need CRLF add this to header
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
951 if (_needCRLF)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
952 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
953 if (_header.length() > 0) throw new IllegalStateException("EOC");
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
954 _header.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
955 _needCRLF = false;
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 // Add the chunk size to the header
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
958 BufferUtil.putHexInt(_header, size);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
959 _header.put(HttpTokens.CRLF);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
960
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
961 // Need a CRLF after the content
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
962 _needCRLF=true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
963 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
964 else if (_buffer!=null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
965 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
966 int size = _buffer.length();
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
967 if (size > 0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
968 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
969 // Prepare a chunk!
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
970 _bufferChunked = true;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
971
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
972 // Did we leave space at the start of the buffer.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
973 //noinspection ConstantConditions
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
974 if (_buffer.getIndex() == CHUNK_SPACE)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
975 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
976 // Oh yes, goodie! let's use it then!
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
977 _buffer.poke(_buffer.getIndex() - 2, HttpTokens.CRLF, 0, 2);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
978 _buffer.setGetIndex(_buffer.getIndex() - 2);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
979 BufferUtil.prependHexInt(_buffer, size);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
980
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
981 if (_needCRLF)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
982 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
983 _buffer.poke(_buffer.getIndex() - 2, HttpTokens.CRLF, 0, 2);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
984 _buffer.setGetIndex(_buffer.getIndex() - 2);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
985 _needCRLF = false;
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 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
988 else
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 // No space so lets use a header buffer.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
991 if (_header == null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
992 _header = _buffers.getHeader();
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 (_needCRLF)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
995 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
996 if (_header.length() > 0) throw new IllegalStateException("EOC");
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
997 _header.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
998 _needCRLF = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
999 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1000 BufferUtil.putHexInt(_header, size);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1001 _header.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1002 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1003
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1004 // Add end chunk trailer.
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1005 if (_buffer.space() >= 2)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1006 _buffer.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1007 else
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1008 _needCRLF = true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1009 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1010 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1011
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1012 // If we need EOC and everything written
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1013 if (_needEOC && (_content == null || _content.length() == 0))
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1014 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1015 if (_header == null && _buffer == null)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1016 _header = _buffers.getHeader();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1017
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1018 if (_needCRLF)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1019 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1020 if (_buffer == null && _header != null && _header.space() >= HttpTokens.CRLF.length)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1021 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1022 _header.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1023 _needCRLF = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1024 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1025 else if (_buffer!=null && _buffer.space() >= HttpTokens.CRLF.length)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1026 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1027 _buffer.put(HttpTokens.CRLF);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1028 _needCRLF = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1029 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1030 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1031
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1032 if (!_needCRLF && _needEOC)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1033 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1034 if (_buffer == null && _header != null && _header.space() >= LAST_CHUNK.length)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1035 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1036 if (!_head)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1037 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1038 _header.put(LAST_CHUNK);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1039 _bufferChunked=true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1040 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1041 _needEOC = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1042 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1043 else if (_buffer!=null && _buffer.space() >= LAST_CHUNK.length)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1044 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1045 if (!_head)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1046 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1047 _buffer.put(LAST_CHUNK);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1048 _bufferChunked=true;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1049 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1050 _needEOC = false;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1051 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1052 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1053 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1054 }
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1055 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1056
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1057 if (_content != null && _content.length() == 0)
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1058 _content = null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1059
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1060 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1061
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1062 public int getBytesBuffered()
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1063 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1064 return(_header==null?0:_header.length())+
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1065 (_buffer==null?0:_buffer.length())+
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1066 (_content==null?0:_content.length());
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1067 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1068
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1069 public boolean isEmpty()
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1070 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1071 return (_header==null||_header.length()==0) &&
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1072 (_buffer==null||_buffer.length()==0) &&
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1073 (_content==null||_content.length()==0);
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1074 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1075
877
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1076 @Override
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1077 public String toString()
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1078 {
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1079 Buffer header=_header;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1080 Buffer buffer=_buffer;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1081 Buffer content=_content;
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1082 return String.format("%s{s=%d,h=%d,b=%d,c=%d}",
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1083 getClass().getSimpleName(),
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1084 _state,
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1085 header == null ? -1 : header.length(),
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1086 buffer == null ? -1 : buffer.length(),
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1087 content == null ? -1 : content.length());
fef4392f4905 remove sendServerVersion
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1088 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1089 }