| 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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 _headerField.addCharCode(_toLowerCase(byte)); | 412 _headerField.addCharCode(_toLowerCase(byte)); |
| 413 _state = _State.HEADER_FIELD; | 413 _state = _State.HEADER_FIELD; |
| 414 } | 414 } |
| 415 } | 415 } |
| 416 break; | 416 break; |
| 417 | 417 |
| 418 case _State.HEADER_ENDING: | 418 case _State.HEADER_ENDING: |
| 419 _expect(byte, _CharCode.LF); | 419 _expect(byte, _CharCode.LF); |
| 420 if (_connectionUpgrade) { | 420 if (_connectionUpgrade) { |
| 421 _state = _State.UPGRADED; | 421 _state = _State.UPGRADED; |
| 422 _unparsedData = |
| 423 buffer.getRange(index + 1, count - (index + 1 - offset)); |
| 422 if (headersComplete != null) headersComplete(); | 424 if (headersComplete != null) headersComplete(); |
| 423 } else { | 425 } else { |
| 424 if (headersComplete != null) headersComplete(); | 426 if (headersComplete != null) headersComplete(); |
| 425 if (_chunked) { | 427 if (_chunked) { |
| 426 _state = _State.CHUNK_SIZE; | 428 _state = _State.CHUNK_SIZE; |
| 427 _remainingContent = 0; | 429 _remainingContent = 0; |
| 428 } else if (_contentLength == 0 || | 430 } else if (_contentLength == 0 || |
| 429 (_messageType == _MessageType.REQUEST && | 431 (_messageType == _MessageType.REQUEST && |
| 430 _contentLength == -1) || | 432 _contentLength == -1) || |
| 431 (_messageType == _MessageType.RESPONSE && | 433 (_messageType == _MessageType.RESPONSE && |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 | 601 |
| 600 int get messageType() => _messageType; | 602 int get messageType() => _messageType; |
| 601 int get contentLength() => _contentLength; | 603 int get contentLength() => _contentLength; |
| 602 bool get upgrade() => _connectionUpgrade && _state == _State.UPGRADED; | 604 bool get upgrade() => _connectionUpgrade && _state == _State.UPGRADED; |
| 603 bool get persistentConnection() => _persistentConnection; | 605 bool get persistentConnection() => _persistentConnection; |
| 604 | 606 |
| 605 void set responseToMethod(String method) => _responseToMethod = method; | 607 void set responseToMethod(String method) => _responseToMethod = method; |
| 606 | 608 |
| 607 bool get isIdle() => _state == _State.START; | 609 bool get isIdle() => _state == _State.START; |
| 608 | 610 |
| 611 List<int> get unparsedData() => _unparsedData; |
| 612 |
| 609 void _bodyEnd() { | 613 void _bodyEnd() { |
| 610 if (dataEnd != null) { | 614 if (dataEnd != null) { |
| 611 dataEnd(_messageType == _MessageType.RESPONSE && !_persistentConnection); | 615 dataEnd(_messageType == _MessageType.RESPONSE && !_persistentConnection); |
| 612 } | 616 } |
| 613 } | 617 } |
| 614 | 618 |
| 615 _reset() { | 619 _reset() { |
| 616 _state = _State.START; | 620 _state = _State.START; |
| 617 _messageType = _MessageType.UNDETERMINED; | 621 _messageType = _MessageType.UNDETERMINED; |
| 618 _headerField = new StringBuffer(); | 622 _headerField = new StringBuffer(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 int _httpVersion; | 692 int _httpVersion; |
| 689 int _contentLength; | 693 int _contentLength; |
| 690 bool _persistentConnection; | 694 bool _persistentConnection; |
| 691 bool _connectionUpgrade; | 695 bool _connectionUpgrade; |
| 692 bool _chunked; | 696 bool _chunked; |
| 693 | 697 |
| 694 bool _noMessageBody; | 698 bool _noMessageBody; |
| 695 String _responseToMethod; // Indicates the method used for the request. | 699 String _responseToMethod; // Indicates the method used for the request. |
| 696 int _remainingContent; | 700 int _remainingContent; |
| 697 | 701 |
| 702 List<int> _unparsedData; // Unparsed data after connection upgrade. |
| 698 // Callbacks. | 703 // Callbacks. |
| 699 Function requestStart; | 704 Function requestStart; |
| 700 Function responseStart; | 705 Function responseStart; |
| 701 Function headerReceived; | 706 Function headerReceived; |
| 702 Function headersComplete; | 707 Function headersComplete; |
| 703 Function dataReceived; | 708 Function dataReceived; |
| 704 Function dataEnd; | 709 Function dataEnd; |
| 705 Function error; | 710 Function error; |
| 706 } | 711 } |
| 707 | 712 |
| 708 | 713 |
| 709 class HttpParserException implements Exception { | 714 class HttpParserException implements Exception { |
| 710 const HttpParserException([String this.message = ""]); | 715 const HttpParserException([String this.message = ""]); |
| 711 String toString() => "HttpParserException: $message"; | 716 String toString() => "HttpParserException: $message"; |
| 712 final String message; | 717 final String message; |
| 713 } | 718 } |
| OLD | NEW |