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