Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: runtime/bin/http_parser.dart

Issue 10449020: Support using the HEAD request in the HTTP library (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/http_impl.dart ('k') | tests/standalone/io/http_head_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Global constants. 5 // Global constants.
6 class _Const { 6 class _Const {
7 // Bytes for "HTTP". 7 // Bytes for "HTTP".
8 static final HTTP = const [72, 84, 84, 80]; 8 static final HTTP = const [72, 84, 84, 80];
9 // Bytes for "HTTP/1.". 9 // Bytes for "HTTP/1.".
10 static final HTTP1DOT = const [72, 84, 84, 80, 47, 49, 46]; 10 static final HTTP1DOT = const [72, 84, 84, 80, 47, 49, 46];
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 try { 141 try {
142 if (_state == _State.CLOSED) { 142 if (_state == _State.CLOSED) {
143 throw new HttpParserException("Data on closed connection"); 143 throw new HttpParserException("Data on closed connection");
144 } 144 }
145 if (_state == _State.UPGRADED) { 145 if (_state == _State.UPGRADED) {
146 throw new HttpParserException("Data on upgraded connection"); 146 throw new HttpParserException("Data on upgraded connection");
147 } 147 }
148 if (_state == _State.FAILURE) { 148 if (_state == _State.FAILURE) {
149 throw new HttpParserException("Data on failed connection"); 149 throw new HttpParserException("Data on failed connection");
150 } 150 }
151 while ((index < lastIndex) && _state != _State.FAILURE && _state != _State .UPGRADED) { 151 while ((index < lastIndex) &&
152 _state != _State.FAILURE &&
153 _state != _State.UPGRADED) {
152 int byte = buffer[index]; 154 int byte = buffer[index];
153 switch (_state) { 155 switch (_state) {
154 case _State.START: 156 case _State.START:
155 if (byte == _Const.HTTP[0]) { 157 if (byte == _Const.HTTP[0]) {
156 // Start parsing method or HTTP version. 158 // Start parsing method or HTTP version.
157 _httpVersionIndex = 1; 159 _httpVersionIndex = 1;
158 _state = _State.METHOD_OR_RESPONSE_HTTP_VERSION; 160 _state = _State.METHOD_OR_RESPONSE_HTTP_VERSION;
159 } else { 161 } else {
160 // Start parsing method. 162 // Start parsing method.
161 if (!_isTokenChar(byte)) { 163 if (!_isTokenChar(byte)) {
162 throw new HttpParserException("Invalid request method"); 164 throw new HttpParserException("Invalid request method");
163 } 165 }
164 _method_or_status_code.addCharCode(byte); 166 _method_or_status_code.addCharCode(byte);
165 _state = _State.REQUEST_LINE_METHOD; 167 _state = _State.REQUEST_LINE_METHOD;
166 } 168 }
167 break; 169 break;
168 170
169 case _State.METHOD_OR_RESPONSE_HTTP_VERSION: 171 case _State.METHOD_OR_RESPONSE_HTTP_VERSION:
170 if (_httpVersionIndex < _Const.HTTP.length && 172 if (_httpVersionIndex < _Const.HTTP.length &&
171 byte == _Const.HTTP[_httpVersionIndex]) { 173 byte == _Const.HTTP[_httpVersionIndex]) {
172 // Continue parsing HTTP version. 174 // Continue parsing HTTP version.
173 _httpVersionIndex++; 175 _httpVersionIndex++;
174 } else if (_httpVersionIndex == _Const.HTTP.length && 176 } else if (_httpVersionIndex == _Const.HTTP.length &&
175 byte == _CharCode.SLASH) { 177 byte == _CharCode.SLASH) {
176 // HTTP/ parsed. As method is a token this cannot be a method anym ore. 178 // HTTP/ parsed. As method is a token this cannot be a
179 // method anymore.
177 _httpVersionIndex++; 180 _httpVersionIndex++;
178 _state = _State.RESPONSE_HTTP_VERSION; 181 _state = _State.RESPONSE_HTTP_VERSION;
179 } else { 182 } else {
180 // Did not parse HTTP version. Expect method instead. 183 // Did not parse HTTP version. Expect method instead.
181 for (int i = 0; i < _httpVersionIndex; i++) { 184 for (int i = 0; i < _httpVersionIndex; i++) {
182 _method_or_status_code.addCharCode(_Const.HTTP[i]); 185 _method_or_status_code.addCharCode(_Const.HTTP[i]);
183 } 186 }
184 //_method_or_status_code.addCharCode(byte); 187 if (byte == _CharCode.SP) {
185 _httpVersion = _HttpVersion.UNDETERMINED; 188 _state = _State.REQUEST_LINE_URI;
186 _state = _State.REQUEST_LINE_URI; 189 } else {
190 _method_or_status_code.addCharCode(byte);
191 _httpVersion = _HttpVersion.UNDETERMINED;
192 _state = _State.REQUEST_LINE_METHOD;
193 }
187 } 194 }
188 break; 195 break;
189 196
190 case _State.RESPONSE_HTTP_VERSION: 197 case _State.RESPONSE_HTTP_VERSION:
191 if (_httpVersionIndex < _Const.HTTP1DOT.length) { 198 if (_httpVersionIndex < _Const.HTTP1DOT.length) {
192 // Continue parsing HTTP version. 199 // Continue parsing HTTP version.
193 _expect(byte, _Const.HTTP1DOT[_httpVersionIndex]); 200 _expect(byte, _Const.HTTP1DOT[_httpVersionIndex]);
194 _httpVersionIndex++; 201 _httpVersionIndex++;
195 } else if (_httpVersionIndex == _Const.HTTP1DOT.length && 202 } else if (_httpVersionIndex == _Const.HTTP1DOT.length &&
196 byte == _CharCode.ONE) { 203 byte == _CharCode.ONE) {
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 Function dataEnd; 716 Function dataEnd;
710 Function error; 717 Function error;
711 } 718 }
712 719
713 720
714 class HttpParserException implements Exception { 721 class HttpParserException implements Exception {
715 const HttpParserException([String this.message = ""]); 722 const HttpParserException([String this.message = ""]);
716 String toString() => "HttpParserException: $message"; 723 String toString() => "HttpParserException: $message";
717 final String message; 724 final String message;
718 } 725 }
OLDNEW
« no previous file with comments | « runtime/bin/http_impl.dart ('k') | tests/standalone/io/http_head_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698