| 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 const HTTP = const [72, 84, 84, 80]; | 8 static const HTTP = const [72, 84, 84, 80]; |
| 9 // Bytes for "HTTP/1.". | 9 // Bytes for "HTTP/1.". |
| 10 static const HTTP1DOT = const [72, 84, 84, 80, 47, 49, 46]; | 10 static const HTTP1DOT = const [72, 84, 84, 80, 47, 49, 46]; |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 } else { | 421 } else { |
| 422 // Start of new header field. | 422 // Start of new header field. |
| 423 _headerField.addCharCode(_toLowerCase(byte)); | 423 _headerField.addCharCode(_toLowerCase(byte)); |
| 424 _state = _State.HEADER_FIELD; | 424 _state = _State.HEADER_FIELD; |
| 425 } | 425 } |
| 426 } | 426 } |
| 427 break; | 427 break; |
| 428 | 428 |
| 429 case _State.HEADER_ENDING: | 429 case _State.HEADER_ENDING: |
| 430 _expect(byte, _CharCode.LF); | 430 _expect(byte, _CharCode.LF); |
| 431 // If a request message has neither Content-Length nor |
| 432 // Transfer-Encoding the message must not have a body (RFC |
| 433 // 2616 section 4.3). |
| 434 if (_messageType == _MessageType.REQUEST && |
| 435 _contentLength < 0 && |
| 436 _chunked == false) { |
| 437 _contentLength = 0; |
| 438 } |
| 431 if (_connectionUpgrade) { | 439 if (_connectionUpgrade) { |
| 432 _state = _State.UPGRADED; | 440 _state = _State.UPGRADED; |
| 433 _unparsedData = | 441 _unparsedData = |
| 434 buffer.getRange(index + 1, count - (index + 1 - offset)); | 442 buffer.getRange(index + 1, count - (index + 1 - offset)); |
| 435 if (headersComplete != null) headersComplete(); | 443 if (headersComplete != null) headersComplete(); |
| 436 } else { | 444 } else { |
| 437 if (headersComplete != null) headersComplete(); | 445 if (headersComplete != null) headersComplete(); |
| 438 if (_chunked) { | 446 if (_chunked) { |
| 439 _state = _State.CHUNK_SIZE; | 447 _state = _State.CHUNK_SIZE; |
| 440 _remainingContent = 0; | 448 _remainingContent = 0; |
| 441 } else if (_contentLength == 0 || | 449 } else if (_contentLength == 0 || |
| 442 (_messageType == _MessageType.REQUEST && | |
| 443 _contentLength == -1) || | |
| 444 (_messageType == _MessageType.RESPONSE && | 450 (_messageType == _MessageType.RESPONSE && |
| 445 (_noMessageBody || _responseToMethod == "HEAD"))) { | 451 (_noMessageBody || _responseToMethod == "HEAD"))) { |
| 446 // If there is no message body get ready to process the | 452 // If there is no message body get ready to process the |
| 447 // next request. | 453 // next request. |
| 448 _bodyEnd(); | 454 _bodyEnd(); |
| 449 _reset(); | 455 _reset(); |
| 450 } else if (_contentLength > 0) { | 456 } else if (_contentLength > 0) { |
| 451 _remainingContent = _contentLength; | 457 _remainingContent = _contentLength; |
| 452 _state = _State.BODY; | 458 _state = _State.BODY; |
| 453 } else { | 459 } else { |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 Function dataEnd; | 724 Function dataEnd; |
| 719 Function error; | 725 Function error; |
| 720 } | 726 } |
| 721 | 727 |
| 722 | 728 |
| 723 class HttpParserException implements Exception { | 729 class HttpParserException implements Exception { |
| 724 const HttpParserException([String this.message = ""]); | 730 const HttpParserException([String this.message = ""]); |
| 725 String toString() => "HttpParserException: $message"; | 731 String toString() => "HttpParserException: $message"; |
| 726 final String message; | 732 final String message; |
| 727 } | 733 } |
| OLD | NEW |