annotate src/org/eclipse/jetty/http/HttpParser.java @ 1019:f126d30e04a4

start replacing BufferCache with StringCache
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 31 Oct 2016 03:33:42 -0600
parents d2c3ff33387c
children 6be43ef1eb96
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
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 import org.eclipse.jetty.io.Buffer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 import org.eclipse.jetty.io.BufferCache.CachedBuffer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 import org.eclipse.jetty.io.BufferUtil;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 import org.eclipse.jetty.io.Buffers;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 import org.eclipse.jetty.io.ByteArrayBuffer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 import org.eclipse.jetty.io.EndPoint;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 import org.eclipse.jetty.io.EofException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 import org.eclipse.jetty.io.View;
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
979
c8cd3e96db5f remove Parser
Franklin Schmidt <fschmidt@gmail.com>
parents: 873
diff changeset
35 public final class HttpParser
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 {
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
37 private static final Logger LOG = LoggerFactory.getLogger(HttpParser.class);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
39 // States
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
40 private static final int STATE_START=-14;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
41 private static final int STATE_FIELD0=-13;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
42 private static final int STATE_SPACE1=-12;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
43 private static final int STATE_STATUS=-11;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
44 private static final int STATE_URI=-10;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
45 private static final int STATE_SPACE2=-9;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
46 private static final int STATE_END0=-8;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
47 private static final int STATE_END1=-7;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
48 private static final int STATE_FIELD2=-6;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
49 private static final int STATE_HEADER=-5;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
50 private static final int STATE_HEADER_NAME=-4;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
51 private static final int STATE_HEADER_IN_NAME=-3;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
52 private static final int STATE_HEADER_VALUE=-2;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
53 private static final int STATE_HEADER_IN_VALUE=-1;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
54 private static final int STATE_END=0;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
55 private static final int STATE_EOF_CONTENT=1;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
56 private static final int STATE_CONTENT=2;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
57 private static final int STATE_CHUNKED_CONTENT=3;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
58 private static final int STATE_CHUNK_SIZE=4;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
59 private static final int STATE_CHUNK_PARAMS=5;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
60 private static final int STATE_CHUNK=6;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
61 private static final int STATE_SEEKING_EOF=7;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
63 private final EventHandler _handler;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
64 private final Buffers _buffers; // source of buffers
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
65 private final EndPoint _endp;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
66 private Buffer _header; // Buffer for header data (and small _content)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
67 private Buffer _body; // Buffer for large content
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
68 private Buffer _buffer; // The current buffer in use (either _header or _content)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
69 private CachedBuffer _cached;
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
70 private String _tok0; // Saved token: header name, request method or response version
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 1002
diff changeset
71 private final View.CaseInsensitive _tok1 = new View.CaseInsensitive(); // Saved token: header value, request URI or response code
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
72 private String _multiLineValue;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73 private int _responseStatus; // If >0 then we are parsing a response
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
74 private boolean _persistent;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
75
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
76 protected final View _contentView = new View(); // View of the content in the buffer for {@link Input}
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
77 protected int _state = STATE_START;
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
78 protected byte _eol;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
79 protected int _length;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
80 protected long _contentLength;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
81 protected long _contentPosition;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
82 protected int _chunkLength;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
83 protected int _chunkPosition;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 private boolean _headResponse;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
85
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
86 public HttpParser(Buffers buffers, EndPoint endp, EventHandler handler)
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
87 {
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
88 _buffers = buffers;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
89 _endp = endp;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
90 _handler = handler;
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
91 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
93 public long getContentLength()
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
94 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
95 return _contentLength;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
96 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
97
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
98 public long getContentRead()
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
99 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
100 return _contentPosition;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
101 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
102
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
103 /* ------------------------------------------------------------ */
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
104 /** Set if a HEAD response is expected
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
105 * @param head
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
106 */
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 public void setHeadResponse(boolean head)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
108 {
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
109 _headResponse = head;
873
220ad4853cda remove StreamEndPoint
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
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 public boolean isChunking()
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 return _contentLength==HttpTokens.CHUNKED_CONTENT;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
115 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
117 public boolean isIdle()
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
118 {
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
119 return _state==STATE_START;
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
120 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
122 public boolean isComplete()
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
123 {
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
124 return _state==STATE_END;
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
126
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
127 public boolean isPersistent()
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
128 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
129 return _persistent;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
130 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
132 public void setPersistent(boolean persistent)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
133 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
134 _persistent = persistent;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
135 if (!_persistent &&(_state==STATE_END || _state==STATE_START))
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
136 _state=STATE_SEEKING_EOF;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
137 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
138
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
139 /* ------------------------------------------------------------------------------- */
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
140 /**
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
141 * Parse until END state.
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
142 * This method will parse any remaining content in the current buffer as long as there is
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
143 * no unconsumed content. It does not care about the {@link #getState current state} of the parser.
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
144 * @see #parse
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
145 * @see #parseNext
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
146 */
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
147 public boolean parseAvailable() throws IOException
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
148 {
1001
Franklin Schmidt <fschmidt@gmail.com>
parents: 980
diff changeset
149 boolean progress = parseNext() > 0;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
150
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
151 // continue parsing
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
152 while (!isComplete() && _buffer!=null && _buffer.length()>0 && !_contentView.hasContent())
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
153 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
154 progress |= parseNext()>0;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 return progress;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
159
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
160 /* ------------------------------------------------------------------------------- */
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 /**
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
162 * Parse until next Event.
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 * @return an indication of progress <0 EOF, 0 no progress, >0 progress.
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
164 */
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
165 private int parseNext() throws IOException
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
166 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
167 try
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
168 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
169 int progress=0;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
170
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
171 if (_state == STATE_END)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
172 return 0;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
173
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174 if (_buffer==null)
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
175 _buffer = getHeaderBuffer();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
176
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
178 if (_state == STATE_CONTENT && _contentPosition == _contentLength)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
180 _state=STATE_END;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
181 _handler.messageComplete(_contentPosition);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 return 1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
183 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
184
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 int length=_buffer.length();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
186
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 // Fill buffer if we can
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
188 if (length == 0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
189 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 int filled=-1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
191 IOException ex=null;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
192 try
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
193 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
194 filled=fill();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
195 LOG.debug("filled {}/{}",filled,_buffer.length());
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 catch(IOException e)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 LOG.debug(this.toString(),e);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
200 ex=e;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
202
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
203 if (filled > 0 )
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
204 progress++;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
205 else if (filled < 0 )
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
206 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 _persistent=false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
208
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
209 // do we have content to deliver?
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
210 if (_state>STATE_END)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
211 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
212 if (_buffer.length()>0 && !_headResponse)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
213 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
214 Buffer chunk=_buffer.get(_buffer.length());
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
215 _contentPosition += chunk.length();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
216 _contentView.update(chunk);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
217 _handler.content(chunk); // May recurse here
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
219 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
220
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
221 // was this unexpected?
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 switch(_state)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
223 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
224 case STATE_END:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
225 case STATE_SEEKING_EOF:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
226 _state=STATE_END;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
227 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
228
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
229 case STATE_EOF_CONTENT:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 _state=STATE_END;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
231 _handler.messageComplete(_contentPosition);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
232 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
233
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
234 default:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
235 _state=STATE_END;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236 if (!_headResponse)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
237 _handler.earlyEOF();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 _handler.messageComplete(_contentPosition);
220ad4853cda remove StreamEndPoint
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
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 if (ex!=null)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
242 throw ex;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
243
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 if (!isComplete() && !isIdle())
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
245 throw new EofException();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
246
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
247 return -1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
248 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
249 length=_buffer.length();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
250 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
251
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
252
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
253 // Handle header states
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
254 byte ch;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
255 byte[] array=_buffer.array();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
256 int last=_state;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
257 while (_state<STATE_END && length-->0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
258 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
259 if (last!=_state)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
260 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
261 progress++;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
262 last=_state;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
263 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
264
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
265 ch=_buffer.get();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
266
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
267 if (_eol == HttpTokens.CARRIAGE_RETURN)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
268 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
269 if (ch == HttpTokens.LINE_FEED)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
270 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
271 _eol=HttpTokens.LINE_FEED;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
272 continue;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
273 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
274 throw new HttpException(HttpStatus.BAD_REQUEST_400);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
275 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
276 _eol=0;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
277
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
278 switch (_state)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
280 case STATE_START:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
281 _contentLength=HttpTokens.UNKNOWN_CONTENT;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
282 _cached=null;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
283 if (ch > HttpTokens.SPACE || ch<0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
285 _buffer.mark();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
286 _state=STATE_FIELD0;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
287 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
288 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
289
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
290 case STATE_FIELD0:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
291 if (ch == HttpTokens.SPACE)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
292 {
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
293 //System.out.println("qqqqqqqqqqqqqqqq a "+_tok0);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
294 // _tok0.update(_buffer.markIndex(), _buffer.getIndex() - 1);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
295 _tok0 = _buffer.peek(_buffer.markIndex(), _buffer.getIndex() - 1 - _buffer.markIndex()).toString();
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
296 //System.out.println("qqqqqqqqqqqqqqqq b "+_tok0);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
297 _responseStatus = !HttpVersions.CACHE.contains(_tok0)?-1:0;
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
298 _state=STATE_SPACE1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
299 continue;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
300 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
301 else if (ch < HttpTokens.SPACE && ch>=0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
302 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303 throw new HttpException(HttpStatus.BAD_REQUEST_400);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
304 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
305 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
306
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
307 case STATE_SPACE1:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
308 if (ch > HttpTokens.SPACE || ch<0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310 _buffer.mark();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
311 if (_responseStatus>=0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
312 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
313 _state=STATE_STATUS;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
314 _responseStatus=ch-'0';
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
315 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
316 else
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
317 _state=STATE_URI;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
318 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
319 else if (ch < HttpTokens.SPACE)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
320 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
321 throw new HttpException(HttpStatus.BAD_REQUEST_400);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
322 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
323 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
324
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
325 case STATE_STATUS:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
326 if (ch == HttpTokens.SPACE)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
327 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
328 _tok1.update(_buffer.markIndex(), _buffer.getIndex() - 1);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
329 _state=STATE_SPACE2;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
330 continue;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
331 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
332 else if (ch>='0' && ch<='9')
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
333 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
334 _responseStatus=_responseStatus*10+(ch-'0');
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
335 continue;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
336 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
337 else if (ch < HttpTokens.SPACE && ch>=0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
338 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
339 _eol=ch;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
340 _state=STATE_HEADER;
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
341 // _tok0.setPutIndex(_tok0.getIndex());
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
342 _tok0 = "";
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
343 _tok1.setPutIndex(_tok1.getIndex());
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
344 _multiLineValue=null;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
345 continue;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
347 // not a digit, so must be a URI
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
348 _state=STATE_URI;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
349 _responseStatus=-1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
350 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
351
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
352 case STATE_URI:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
353 if (ch == HttpTokens.SPACE)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
354 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
355 _tok1.update(_buffer.markIndex(), _buffer.getIndex() - 1);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
356 _state=STATE_SPACE2;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
357 continue;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
358 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
359 else if (ch < HttpTokens.SPACE && ch>=0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
360 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
361 // HTTP/0.9
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
362 _handler.startRequest(_tok0, _buffer.sliceFromMark(), null);
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
363 _persistent=false;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
364 _state=STATE_SEEKING_EOF;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
365 _handler.headerComplete();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
366 _handler.messageComplete(_contentPosition);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
367 return 1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
368 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
369 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
370
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
371 case STATE_SPACE2:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
372 if (ch > HttpTokens.SPACE || ch<0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
373 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
374 _buffer.mark();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
375 _state=STATE_FIELD2;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
376 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
377 else if (ch < HttpTokens.SPACE)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
378 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
379 if (_responseStatus>0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
380 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
381 _eol=ch;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
382 _state=STATE_HEADER;
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
383 // _tok0.setPutIndex(_tok0.getIndex());
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
384 _tok0 = "";
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
385 _tok1.setPutIndex(_tok1.getIndex());
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
386 _multiLineValue=null;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
387 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
388 else
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
389 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
390 // HTTP/0.9
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
391 _handler.startRequest(_tok0, _tok1, null);
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
392 _persistent=false;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
393 _state=STATE_SEEKING_EOF;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
394 _handler.headerComplete();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
395 _handler.messageComplete(_contentPosition);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
396 return 1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
397 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
398 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
399 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
400
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
401 case STATE_FIELD2:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
402 if (ch == HttpTokens.CARRIAGE_RETURN || ch == HttpTokens.LINE_FEED)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
403 {
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
404 String version;
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
405 if (_responseStatus > 0)
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
406 // _handler.startResponse(version=HttpVersions.CACHE.lookup(_tok0), _responseStatus,_buffer.sliceFromMark());
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
407 version = _tok0;
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
408 else
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
409 _handler.startRequest(_tok0, _tok1, version=_buffer.sliceFromMark().toString());
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
410 _eol=ch;
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
411 _persistent = HttpVersions.CACHE.getOrdinal(version) >= HttpVersions.HTTP_1_1_ORDINAL;
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
412 _state=STATE_HEADER;
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
413 // _tok0.setPutIndex(_tok0.getIndex());
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
414 _tok0 = "";
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
415 _tok1.setPutIndex(_tok1.getIndex());
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
416 _multiLineValue=null;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
417 continue;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
418 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
419 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
420
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
421 case STATE_HEADER:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
422 switch(ch)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
423 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
424 case HttpTokens.COLON:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
425 case HttpTokens.SPACE:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
426 case HttpTokens.TAB:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
427 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
428 // header value without name - continuation?
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
429 _length=-1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
430 _state=STATE_HEADER_VALUE;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
431 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
432 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
433
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
434 default:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
435 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
436 // handler last header if any
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
437 if (_cached!=null || _tok0.length() > 0 || _tok1.length() > 0 || _multiLineValue != null)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
438 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
439 Buffer header=_cached!=null?_cached:HttpHeaders.CACHE.lookup(_tok0);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
440 _cached=null;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
441 Buffer value=_multiLineValue == null ? _tok1 : new ByteArrayBuffer(_multiLineValue);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
442
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
443 int ho=HttpHeaders.CACHE.getOrdinal(header);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
444 if (ho >= 0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
445 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
446 int vo;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
447
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
448 switch (ho)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
449 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
450 case HttpHeaders.CONTENT_LENGTH_ORDINAL:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
451 if (_contentLength != HttpTokens.CHUNKED_CONTENT )
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
452 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
453 try
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
454 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
455 _contentLength=BufferUtil.toLong(value);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
456 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
457 catch(NumberFormatException e)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
458 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
459 LOG.trace("",e);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
460 throw new HttpException(HttpStatus.BAD_REQUEST_400);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
461 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
462 if (_contentLength <= 0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
463 _contentLength=HttpTokens.NO_CONTENT;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
464 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
465 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
466
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
467 case HttpHeaders.TRANSFER_ENCODING_ORDINAL:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
468 value=HttpHeaderValues.CACHE.lookup(value);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
469 vo=HttpHeaderValues.CACHE.getOrdinal(value);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
470 if (HttpHeaderValues.CHUNKED_ORDINAL == vo)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
471 _contentLength=HttpTokens.CHUNKED_CONTENT;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
472 else
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
473 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
474 String c=value.toString(StringUtil.__ISO_8859_1);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
475 if (c.endsWith(HttpHeaderValues.CHUNKED))
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
476 _contentLength=HttpTokens.CHUNKED_CONTENT;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
477
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
478 else if (c.indexOf(HttpHeaderValues.CHUNKED) >= 0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
479 throw new HttpException(400,null);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
480 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
481 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
482
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
483 case HttpHeaders.CONNECTION_ORDINAL:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
484 switch(HttpHeaderValues.CACHE.getOrdinal(value))
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
485 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
486 case HttpHeaderValues.CLOSE_ORDINAL:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
487 _persistent=false;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
488 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
489
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
490 case HttpHeaderValues.KEEP_ALIVE_ORDINAL:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
491 _persistent=true;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
492 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
493
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
494 case -1: // No match, may be multi valued
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
495 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
496 for (String v : value.toString().split(","))
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
497 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
498 switch(HttpHeaderValues.CACHE.getOrdinal(v.trim()))
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
499 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
500 case HttpHeaderValues.CLOSE_ORDINAL:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
501 _persistent=false;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
502 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
503
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
504 case HttpHeaderValues.KEEP_ALIVE_ORDINAL:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
505 _persistent=true;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
506 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
507 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
508 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
509 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
510 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
511 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
512 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
513 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
514
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
515 _handler.parsedHeader(header, value);
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
516 // _tok0.setPutIndex(_tok0.getIndex());
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
517 _tok0 = "";
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
518 _tok1.setPutIndex(_tok1.getIndex());
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
519 _multiLineValue=null;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
520 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
521 _buffer.setMarkIndex(-1);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
522
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
523 // now handle ch
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
524 if (ch == HttpTokens.CARRIAGE_RETURN || ch == HttpTokens.LINE_FEED)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
525 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
526 // is it a response that cannot have a body?
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
527 if (_responseStatus > 0 && // response
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
528 (_responseStatus == 304 || // not-modified response
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
529 _responseStatus == 204 || // no-content response
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
530 _responseStatus < 200)) // 1xx response
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
531 _contentLength=HttpTokens.NO_CONTENT; // ignore any other headers set
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
532 // else if we don't know framing
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
533 else if (_contentLength == HttpTokens.UNKNOWN_CONTENT)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
534 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
535 if (_responseStatus == 0 // request
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
536 || _responseStatus == 304 // not-modified response
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
537 || _responseStatus == 204 // no-content response
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
538 || _responseStatus < 200) // 1xx response
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
539 _contentLength=HttpTokens.NO_CONTENT;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
540 else
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
541 _contentLength=HttpTokens.EOF_CONTENT;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
542 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
543
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
544 _contentPosition=0;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
545 _eol=ch;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
546 if (_eol==HttpTokens.CARRIAGE_RETURN && _buffer.hasContent() && _buffer.peek()==HttpTokens.LINE_FEED)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
547 _eol=_buffer.get();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
548
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
549 // We convert _contentLength to an int for this switch statement because
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
550 // we don't care about the amount of data available just whether there is some.
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
551 switch (_contentLength > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) _contentLength)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
552 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
553 case HttpTokens.EOF_CONTENT:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
554 _state=STATE_EOF_CONTENT;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
555 _handler.headerComplete(); // May recurse here !
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
556 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
557
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
558 case HttpTokens.CHUNKED_CONTENT:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
559 _state=STATE_CHUNKED_CONTENT;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
560 _handler.headerComplete(); // May recurse here !
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
561 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
562
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
563 case HttpTokens.NO_CONTENT:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
564 _handler.headerComplete();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
565 _state=_persistent||(_responseStatus>=100&&_responseStatus<200)?STATE_END:STATE_SEEKING_EOF;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
566 _handler.messageComplete(_contentPosition);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
567 return 1;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
568
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
569 default:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
570 _state=STATE_CONTENT;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
571 _handler.headerComplete(); // May recurse here !
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
572 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
573 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
574 return 1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
575 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
576 else
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
577 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
578 // New header
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
579 _length=1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
580 _buffer.mark();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
581 _state=STATE_HEADER_NAME;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
582
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
583 // try cached name!
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
584 if (array!=null)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
585 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
586 _cached=HttpHeaders.CACHE.getBest(array, _buffer.markIndex(), length+1);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
587
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
588 if (_cached!=null)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
589 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
590 _length=_cached.length();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
591 _buffer.setGetIndex(_buffer.markIndex()+_length);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
592 length=_buffer.length();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
593 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
594 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
595 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
596 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
597 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
598
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
599 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
600
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
601 case STATE_HEADER_NAME:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
602 switch(ch)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
603 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
604 case HttpTokens.CARRIAGE_RETURN:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
605 case HttpTokens.LINE_FEED:
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
606 if (_length > 0) {
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
607 //System.out.println("qqqqqqqqqqqqqqqq c "+_tok0);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
608 // _tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
609 _tok0 = _buffer.peek(_buffer.markIndex(), _length).toString();
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
610 //System.out.println("qqqqqqqqqqqqqqqq d "+_tok0);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
611 }
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
612 _eol=ch;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
613 _state=STATE_HEADER;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
614 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
615 case HttpTokens.COLON:
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
616 if (_length > 0 && _cached==null) {
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
617 //System.out.println("qqqqqqqqqqqqqqqq e "+_tok0);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
618 // _tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
619 _tok0 = _buffer.peek(_buffer.markIndex(), _length).toString();
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
620 //System.out.println("qqqqqqqqqqqqqqqq f "+_tok0);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
621 }
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
622 _length=-1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
623 _state=STATE_HEADER_VALUE;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
624 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
625 case HttpTokens.SPACE:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
626 case HttpTokens.TAB:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
627 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
628 default:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
629 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
630 _cached=null;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
631 if (_length == -1)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
632 _buffer.mark();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
633 _length=_buffer.getIndex() - _buffer.markIndex();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
634 _state=STATE_HEADER_IN_NAME;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
635 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
636 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
637
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
638 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
639
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
640 case STATE_HEADER_IN_NAME:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
641 switch(ch)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
642 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
643 case HttpTokens.CARRIAGE_RETURN:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
644 case HttpTokens.LINE_FEED:
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
645 if (_length > 0) {
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
646 //System.out.println("qqqqqqqqqqqqqqqq g "+_tok0);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
647 // _tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
648 _tok0 = _buffer.peek(_buffer.markIndex(),_length).toString();
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
649 //System.out.println("qqqqqqqqqqqqqqqq h "+_tok0);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
650 }
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
651 _eol=ch;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
652 _state=STATE_HEADER;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
653 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
654 case HttpTokens.COLON:
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
655 if (_length > 0 && _cached==null) {
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
656 //System.out.println("qqqqqqqqqqqqqqqq i "+_tok0);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
657 // _tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
658 _tok0 = _buffer.peek(_buffer.markIndex(),_length).toString();
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
659 //System.out.println("qqqqqqqqqqqqqqqq j "+_tok0);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
660 }
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
661 _length=-1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
662 _state=STATE_HEADER_VALUE;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
663 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
664 case HttpTokens.SPACE:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
665 case HttpTokens.TAB:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
666 _state=STATE_HEADER_NAME;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
667 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
668 default:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
669 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
670 _cached=null;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
671 _length++;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
672 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
673 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
674 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
675
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
676 case STATE_HEADER_VALUE:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
677 switch(ch)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
678 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
679 case HttpTokens.CARRIAGE_RETURN:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
680 case HttpTokens.LINE_FEED:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
681 if (_length > 0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
682 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
683 if (_tok1.length() == 0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
684 _tok1.update(_buffer.markIndex(), _buffer.markIndex() + _length);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
685 else
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
686 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
687 // Continuation line!
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
688 if (_multiLineValue == null) _multiLineValue=_tok1.toString(StringUtil.__ISO_8859_1);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
689 _tok1.update(_buffer.markIndex(), _buffer.markIndex() + _length);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
690 _multiLineValue += " " + _tok1.toString(StringUtil.__ISO_8859_1);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
691 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
692 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
693 _eol=ch;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
694 _state=STATE_HEADER;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
695 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
696 case HttpTokens.SPACE:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
697 case HttpTokens.TAB:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
698 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
699 default:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
700 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
701 if (_length == -1)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
702 _buffer.mark();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
703 _length=_buffer.getIndex() - _buffer.markIndex();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
704 _state=STATE_HEADER_IN_VALUE;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
705 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
706 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
707 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
708
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
709 case STATE_HEADER_IN_VALUE:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
710 switch(ch)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
711 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
712 case HttpTokens.CARRIAGE_RETURN:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
713 case HttpTokens.LINE_FEED:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
714 if (_length > 0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
715 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
716 if (_tok1.length() == 0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
717 _tok1.update(_buffer.markIndex(), _buffer.markIndex() + _length);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
718 else
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
719 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
720 // Continuation line!
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
721 if (_multiLineValue == null) _multiLineValue=_tok1.toString(StringUtil.__ISO_8859_1);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
722 _tok1.update(_buffer.markIndex(), _buffer.markIndex() + _length);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
723 _multiLineValue += " " + _tok1.toString(StringUtil.__ISO_8859_1);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
724 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
725 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
726 _eol=ch;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
727 _state=STATE_HEADER;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
728 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
729 case HttpTokens.SPACE:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
730 case HttpTokens.TAB:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
731 _state=STATE_HEADER_VALUE;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
732 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
733 default:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
734 _length++;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
735 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
736 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
737 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
738 } // end of HEADER states loop
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
739
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
740 // ==========================
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
741
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
742 // Handle HEAD response
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
743 if (_responseStatus>0 && _headResponse)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
744 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
745 _state=_persistent||(_responseStatus>=100&&_responseStatus<200)?STATE_END:STATE_SEEKING_EOF;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
746 _handler.messageComplete(_contentLength);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
747 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
748
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
749
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
750 // ==========================
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
751
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
752 // Handle _content
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
753 length=_buffer.length();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
754 Buffer chunk;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
755 last=_state;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
756 while (_state > STATE_END && length > 0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
757 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
758 if (last!=_state)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
759 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
760 progress++;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
761 last=_state;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
762 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
763
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
764 if (_eol == HttpTokens.CARRIAGE_RETURN && _buffer.peek() == HttpTokens.LINE_FEED)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
765 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
766 _eol=_buffer.get();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
767 length=_buffer.length();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
768 continue;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
769 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
770 _eol=0;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
771 switch (_state)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
772 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
773 case STATE_EOF_CONTENT:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
774 chunk=_buffer.get(_buffer.length());
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
775 _contentPosition += chunk.length();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
776 _contentView.update(chunk);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
777 _handler.content(chunk); // May recurse here
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
778 // TODO adjust the _buffer to keep unconsumed content
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
779 return 1;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
780
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
781 case STATE_CONTENT:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
782 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
783 long remaining=_contentLength - _contentPosition;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
784 if (remaining == 0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
785 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
786 _state=_persistent?STATE_END:STATE_SEEKING_EOF;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
787 _handler.messageComplete(_contentPosition);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
788 return 1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
789 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
790
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
791 if (length > remaining)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
792 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
793 // We can cast reamining to an int as we know that it is smaller than
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
794 // or equal to length which is already an int.
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
795 length=(int)remaining;
220ad4853cda remove StreamEndPoint
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
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
798 chunk=_buffer.get(length);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
799 _contentPosition += chunk.length();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
800 _contentView.update(chunk);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
801 _handler.content(chunk); // May recurse here
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
802
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
803 if(_contentPosition == _contentLength)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
804 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
805 _state=_persistent?STATE_END:STATE_SEEKING_EOF;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
806 _handler.messageComplete(_contentPosition);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
807 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
808 // TODO adjust the _buffer to keep unconsumed content
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
809 return 1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
810 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
811
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
812 case STATE_CHUNKED_CONTENT:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
813 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
814 ch=_buffer.peek();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
815 if (ch == HttpTokens.CARRIAGE_RETURN || ch == HttpTokens.LINE_FEED)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
816 _eol=_buffer.get();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
817 else if (ch <= HttpTokens.SPACE)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
818 _buffer.get();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
819 else
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
820 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
821 _chunkLength=0;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
822 _chunkPosition=0;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
823 _state=STATE_CHUNK_SIZE;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
824 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
825 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
826 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
827
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
828 case STATE_CHUNK_SIZE:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
829 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
830 ch=_buffer.get();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
831 if (ch == HttpTokens.CARRIAGE_RETURN || ch == HttpTokens.LINE_FEED)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
832 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
833 _eol=ch;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
834
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
835 if (_chunkLength == 0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
836 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
837 if (_eol==HttpTokens.CARRIAGE_RETURN && _buffer.hasContent() && _buffer.peek()==HttpTokens.LINE_FEED)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
838 _eol=_buffer.get();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
839 _state=_persistent?STATE_END:STATE_SEEKING_EOF;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
840 _handler.messageComplete(_contentPosition);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
841 return 1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
842 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
843 else
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
844 _state=STATE_CHUNK;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
845 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
846 else if (ch <= HttpTokens.SPACE || ch == HttpTokens.SEMI_COLON)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
847 _state=STATE_CHUNK_PARAMS;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
848 else if (ch >= '0' && ch <= '9')
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
849 _chunkLength=_chunkLength * 16 + (ch - '0');
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
850 else if (ch >= 'a' && ch <= 'f')
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
851 _chunkLength=_chunkLength * 16 + (10 + ch - 'a');
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
852 else if (ch >= 'A' && ch <= 'F')
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
853 _chunkLength=_chunkLength * 16 + (10 + ch - 'A');
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
854 else
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
855 throw new IOException("bad chunk char: " + ch);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
856 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
857 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
858
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
859 case STATE_CHUNK_PARAMS:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
860 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
861 ch=_buffer.get();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
862 if (ch == HttpTokens.CARRIAGE_RETURN || ch == HttpTokens.LINE_FEED)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
863 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
864 _eol=ch;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
865 if (_chunkLength == 0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
866 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
867 if (_eol==HttpTokens.CARRIAGE_RETURN && _buffer.hasContent() && _buffer.peek()==HttpTokens.LINE_FEED)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
868 _eol=_buffer.get();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
869 _state=_persistent?STATE_END:STATE_SEEKING_EOF;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
870 _handler.messageComplete(_contentPosition);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
871 return 1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
872 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
873 else
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
874 _state=STATE_CHUNK;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
875 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
876 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
877 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
878
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
879 case STATE_CHUNK:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
880 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
881 int remaining=_chunkLength - _chunkPosition;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
882 if (remaining == 0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
883 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
884 _state=STATE_CHUNKED_CONTENT;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
885 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
886 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
887 else if (length > remaining)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
888 length=remaining;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
889 chunk=_buffer.get(length);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
890 _contentPosition += chunk.length();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
891 _chunkPosition += chunk.length();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
892 _contentView.update(chunk);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
893 _handler.content(chunk); // May recurse here
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
894 // TODO adjust the _buffer to keep unconsumed content
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
895 return 1;
220ad4853cda remove StreamEndPoint
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
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
898 case STATE_SEEKING_EOF:
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
899 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
900 // Close if there is more data than CRLF
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
901 if (_buffer.length()>2)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
902 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
903 _state=STATE_END;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
904 _endp.close();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
905 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
906 else
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
907 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
908 // or if the data is not white space
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
909 while (_buffer.length()>0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
910 if (!Character.isWhitespace(_buffer.get()))
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
911 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
912 _state=STATE_END;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
913 _endp.close();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
914 _buffer.clear();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
915 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
916 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
917
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
918 _buffer.clear();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
919 break;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
920 }
220ad4853cda remove StreamEndPoint
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
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
923 length=_buffer.length();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
924 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
925
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
926 return progress;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
927 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
928 catch(HttpException e)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
929 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
930 _persistent=false;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
931 _state=STATE_SEEKING_EOF;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
932 throw e;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
933 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
934 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
935
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
936 /* ------------------------------------------------------------------------------- */
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
937 /** fill the buffers from the endpoint
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
938 *
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
939 */
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
940 private int fill() throws IOException
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
941 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
942 // Do we have a buffer?
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
943 if (_buffer==null)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
944 _buffer=getHeaderBuffer();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
945
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
946 // Is there unconsumed content in body buffer
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
947 if (_state>STATE_END && _buffer==_header && _header!=null && !_header.hasContent() && _body!=null && _body.hasContent())
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
948 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
949 _buffer=_body;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
950 return _buffer.length();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
951 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
952
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
953 // Shall we switch to a body buffer?
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
954 if (_buffer==_header && _state>STATE_END && _header.length()==0 && ((_contentLength-_contentPosition)>_header.capacity()) && (_body!=null||_buffers!=null))
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
955 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
956 if (_body==null)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
957 _body=_buffers.getBuffer();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
958 _buffer=_body;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
959 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
960
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
961 // Shall we compact the body?
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
962 if (_buffer==_body || _state>STATE_END)
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
963 {
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
964 _buffer.compact();
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
965 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
966
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
967 // Are we full?
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
968 if (_buffer.space() == 0)
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
969 {
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
970 LOG.warn("HttpParser Full for {} ",_endp);
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
971 _buffer.clear();
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
972 throw new HttpException(HttpStatus.REQUEST_ENTITY_TOO_LARGE_413, "Request Entity Too Large: "+(_buffer==_body?"body":"head"));
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
973 }
1002
35d04ac3fd0b simplify ssl
Franklin Schmidt <fschmidt@gmail.com>
parents: 1001
diff changeset
974 /* why?
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
975 try
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
976 {
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
977 int filled = _endp.fill(_buffer);
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
978 return filled;
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
979 }
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
980 catch(IOException e)
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
981 {
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
982 LOG.debug("",e);
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
983 throw (e instanceof EofException) ? e:new EofException(e);
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
984 }
1002
35d04ac3fd0b simplify ssl
Franklin Schmidt <fschmidt@gmail.com>
parents: 1001
diff changeset
985 */
35d04ac3fd0b simplify ssl
Franklin Schmidt <fschmidt@gmail.com>
parents: 1001
diff changeset
986 return _endp.fill(_buffer);
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
987 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
988
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
989 public void reset()
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
990 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
991 // reset state
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
992 _contentView.setGetIndex(_contentView.putIndex());
1017
Franklin Schmidt <fschmidt@gmail.com>
parents: 1016
diff changeset
993 _state = _persistent?STATE_START:(_endp.isInputShutdown()?STATE_END:STATE_SEEKING_EOF);
Franklin Schmidt <fschmidt@gmail.com>
parents: 1016
diff changeset
994 _contentLength = HttpTokens.UNKNOWN_CONTENT;
Franklin Schmidt <fschmidt@gmail.com>
parents: 1016
diff changeset
995 _contentPosition = 0;
Franklin Schmidt <fschmidt@gmail.com>
parents: 1016
diff changeset
996 _length = 0;
Franklin Schmidt <fschmidt@gmail.com>
parents: 1016
diff changeset
997 _responseStatus = 0;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
998
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
999 // Consume LF if CRLF
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1000 if (_eol == HttpTokens.CARRIAGE_RETURN && _buffer!=null && _buffer.hasContent() && _buffer.peek() == HttpTokens.LINE_FEED)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1001 _eol=_buffer.get();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1002
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1003 if (_body!=null && _body.hasContent())
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1004 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1005 // There is content in the body after the end of the request.
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1006 // This is probably a pipelined header of the next request, so we need to
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1007 // copy it to the header buffer.
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1008 if (_header==null)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1009 getHeaderBuffer();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1010 else
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1011 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1012 _header.setMarkIndex(-1);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1013 _header.compact();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1014 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1015 int take=_header.space();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1016 if (take>_body.length())
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1017 take=_body.length();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1018 _body.peek(_body.getIndex(),take);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1019 _body.skip(_header.put(_body.peek(_body.getIndex(),take)));
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1020 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1021
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1022 if (_header!=null)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1023 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1024 _header.setMarkIndex(-1);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1025 _header.compact();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1026 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1027 if (_body!=null)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1028 _body.setMarkIndex(-1);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1029
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1030 _buffer=_header;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1031 returnBuffers();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1032 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1033
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1034
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1035 public void returnBuffers()
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1036 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1037 if (_body!=null && !_body.hasContent() && _body.markIndex()==-1 && _buffers!=null)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1038 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1039 if (_buffer==_body)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1040 _buffer=_header;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1041 _body=null;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1042 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1043
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1044 if (_header!=null && !_header.hasContent() && _header.markIndex()==-1 && _buffers!=null)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1045 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1046 if (_buffer==_header)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1047 _buffer=null;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1048 _header=null;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1049 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1050 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1051
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1052 @Override
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1053 public String toString()
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1054 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1055 return String.format("%s{s=%d,l=%d,c=%d}",
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1056 getClass().getSimpleName(),
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1057 _state,
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1058 _length,
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1059 _contentLength);
220ad4853cda remove StreamEndPoint
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
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1062 public Buffer getHeaderBuffer()
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1063 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1064 if (_header == null)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1065 {
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
1066 _header = _buffers.getHeader();
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
1067 //System.out.println("qqqqqqqqqqqqqqqq k "+_tok0);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
1068 // _tok0.update(_header);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
1069 _tok0 = "";
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
1070 //System.out.println("qqqqqqqqqqqqqqqq l "+_tok0);
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1071 _tok1.update(_header);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1072 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1073 return _header;
220ad4853cda remove StreamEndPoint
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
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1076 public Buffer blockForContent(long maxIdleTime) throws IOException
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1077 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1078 if (_contentView.length()>0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1079 return _contentView;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1080
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
1081 if (_state <= STATE_END || _state==STATE_SEEKING_EOF)
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1082 return null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1083
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1084 try
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1085 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1086 parseNext();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1087
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1088 // parse until some progress is made (or IOException thrown for timeout)
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
1089 while(_contentView.length() == 0 && !(_state==STATE_END||_state==STATE_SEEKING_EOF) && _endp.isOpen())
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1090 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1091 if (!_endp.isBlocking())
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1092 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1093 if (parseNext()>0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1094 continue;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1095
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1096 if (!_endp.blockReadable(maxIdleTime))
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1097 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1098 _endp.close();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1099 throw new EofException("timeout");
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1100 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1101 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1102
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1103 parseNext();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1104 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1105 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1106 catch(IOException e)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1107 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1108 // TODO is this needed?
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1109 _endp.close();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1110 throw e;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1111 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1112
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1113 return _contentView.length()>0?_contentView:null;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1114 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1115
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1116 /* ------------------------------------------------------------ */
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1117 /* (non-Javadoc)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1118 * @see java.io.InputStream#available()
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1119 */
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1120 public int available() throws IOException
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1121 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1122 if (_contentView!=null && _contentView.length()>0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1123 return _contentView.length();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1124
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1125 if (_endp.isBlocking())
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1126 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1127 return 0;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1128 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1129
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1130 parseNext();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1131 return _contentView==null?0:_contentView.length();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1132 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1133
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
1134
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
1135 public interface EventHandler
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1136 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1137 public abstract void content(Buffer ref) throws IOException;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1138
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
1139 public void headerComplete() throws IOException;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1140
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
1141 public void messageComplete(long contentLength) throws IOException;
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1142
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1143 /**
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1144 * This is the method called by parser when a HTTP Header name and value is found
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1145 */
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
1146 public void parsedHeader(Buffer name, Buffer value) throws IOException;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1147
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1148 /**
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1149 * This is the method called by parser when the HTTP request line is parsed
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1150 */
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1017
diff changeset
1151 public abstract void startRequest(String method, Buffer url, String version)
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1152 throws IOException;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1153
980
bd26bd9320e2 simplify HttpParser
Franklin Schmidt <fschmidt@gmail.com>
parents: 979
diff changeset
1154 public void earlyEOF();
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1155 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1156
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1157
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1158
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1159
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1160 }