| OLD | NEW |
| 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 if (byte == _CharCode.CR || byte == _CharCode.LF) { | 306 if (byte == _CharCode.CR || byte == _CharCode.LF) { |
| 307 throw new HttpParserException("Invalid response reason phrase"); | 307 throw new HttpParserException("Invalid response reason phrase"); |
| 308 } | 308 } |
| 309 _uri_or_reason_phrase.addCharCode(byte); | 309 _uri_or_reason_phrase.addCharCode(byte); |
| 310 } | 310 } |
| 311 break; | 311 break; |
| 312 | 312 |
| 313 case _State.RESPONSE_LINE_ENDING: | 313 case _State.RESPONSE_LINE_ENDING: |
| 314 _expect(byte, _CharCode.LF); | 314 _expect(byte, _CharCode.LF); |
| 315 _messageType == _MessageType.RESPONSE; | 315 _messageType == _MessageType.RESPONSE; |
| 316 int statusCode = Math.parseInt(_method_or_status_code.toString()); | 316 int statusCode = parseInt(_method_or_status_code.toString()); |
| 317 if (statusCode < 100 || statusCode > 599) { | 317 if (statusCode < 100 || statusCode > 599) { |
| 318 throw new HttpParserException("Invalid response status code"); | 318 throw new HttpParserException("Invalid response status code"); |
| 319 } else { | 319 } else { |
| 320 // Check whether this response will never have a body. | 320 // Check whether this response will never have a body. |
| 321 _noMessageBody = | 321 _noMessageBody = |
| 322 statusCode <= 199 || statusCode == 204 || statusCode == 304; | 322 statusCode <= 199 || statusCode == 204 || statusCode == 304; |
| 323 } | 323 } |
| 324 if (responseStart != null) { | 324 if (responseStart != null) { |
| 325 responseStart(statusCode, _uri_or_reason_phrase.toString(), versio
n); | 325 responseStart(statusCode, _uri_or_reason_phrase.toString(), versio
n); |
| 326 } | 326 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 case _State.HEADER_VALUE_FOLD_OR_END: | 376 case _State.HEADER_VALUE_FOLD_OR_END: |
| 377 if (byte == _CharCode.SP || byte == _CharCode.HT) { | 377 if (byte == _CharCode.SP || byte == _CharCode.HT) { |
| 378 _state = _State.HEADER_VALUE_START; | 378 _state = _State.HEADER_VALUE_START; |
| 379 } else { | 379 } else { |
| 380 String headerField = _headerField.toString(); | 380 String headerField = _headerField.toString(); |
| 381 String headerValue =_headerValue.toString(); | 381 String headerValue =_headerValue.toString(); |
| 382 bool reportHeader = true; | 382 bool reportHeader = true; |
| 383 if (headerField == "content-length" && !_chunked) { | 383 if (headerField == "content-length" && !_chunked) { |
| 384 // Ignore the Content-Length header if Transfer-Encoding | 384 // Ignore the Content-Length header if Transfer-Encoding |
| 385 // is chunked (RFC 2616 section 4.4) | 385 // is chunked (RFC 2616 section 4.4) |
| 386 _contentLength = Math.parseInt(headerValue); | 386 _contentLength = parseInt(headerValue); |
| 387 } else if (headerField == "connection") { | 387 } else if (headerField == "connection") { |
| 388 List<String> tokens = _tokenizeFieldValue(headerValue); | 388 List<String> tokens = _tokenizeFieldValue(headerValue); |
| 389 for (int i = 0; i < tokens.length; i++) { | 389 for (int i = 0; i < tokens.length; i++) { |
| 390 String token = tokens[i].toLowerCase(); | 390 String token = tokens[i].toLowerCase(); |
| 391 if (token == "keep-alive") { | 391 if (token == "keep-alive") { |
| 392 _persistentConnection = true; | 392 _persistentConnection = true; |
| 393 } else if (token == "close") { | 393 } else if (token == "close") { |
| 394 _persistentConnection = false; | 394 _persistentConnection = false; |
| 395 } else if (token == "upgrade") { | 395 } else if (token == "upgrade") { |
| 396 _connectionUpgrade = true; | 396 _connectionUpgrade = true; |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 Function dataEnd; | 717 Function dataEnd; |
| 718 Function error; | 718 Function error; |
| 719 } | 719 } |
| 720 | 720 |
| 721 | 721 |
| 722 class HttpParserException implements Exception { | 722 class HttpParserException implements Exception { |
| 723 const HttpParserException([String this.message = ""]); | 723 const HttpParserException([String this.message = ""]); |
| 724 String toString() => "HttpParserException: $message"; | 724 String toString() => "HttpParserException: $message"; |
| 725 final String message; | 725 final String message; |
| 726 } | 726 } |
| OLD | NEW |