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