annotate src/org/eclipse/jetty/http/HttpParser.java @ 1034:563458c4dc93

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