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