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

Side by Side Diff: sdk/lib/io/http_parser.dart

Issue 12314065: Reset http-parser instead of only setting _state, when we have handled a full request-response conv… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of dart.io; 5 part of dart.io;
6 6
7 // Global constants. 7 // Global constants.
8 class _Const { 8 class _Const {
9 // Bytes for "HTTP". 9 // Bytes for "HTTP".
10 static const HTTP = const [72, 84, 84, 80]; 10 static const HTTP = const [72, 84, 84, 80];
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 _incoming.upgraded = true; 559 _incoming.upgraded = true;
560 _controller.add(_incoming); 560 _controller.add(_incoming);
561 break; 561 break;
562 } 562 }
563 if (_chunked) { 563 if (_chunked) {
564 _state = _State.CHUNK_SIZE; 564 _state = _State.CHUNK_SIZE;
565 _remainingContent = 0; 565 _remainingContent = 0;
566 } else if (_transferLength == 0 || 566 } else if (_transferLength == 0 ||
567 (_messageType == _MessageType.RESPONSE && 567 (_messageType == _MessageType.RESPONSE &&
568 (_noMessageBody || _responseToMethod == "HEAD"))) { 568 (_noMessageBody || _responseToMethod == "HEAD"))) {
569 _state = _State.START; 569 _reset();
570 var tmp = _incoming; 570 var tmp = _incoming;
571 _closeIncoming(); 571 _closeIncoming();
572 _controller.add(tmp); 572 _controller.add(tmp);
573 break; 573 break;
574 } else if (_transferLength > 0) { 574 } else if (_transferLength > 0) {
575 _remainingContent = _transferLength; 575 _remainingContent = _transferLength;
576 _state = _State.BODY; 576 _state = _State.BODY;
577 } else { 577 } else {
578 // Neither chunked nor content length. End of body 578 // Neither chunked nor content length. End of body
579 // indicated by close. 579 // indicated by close.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 } 618 }
619 break; 619 break;
620 620
621 case _State.CHUNKED_BODY_DONE_CR: 621 case _State.CHUNKED_BODY_DONE_CR:
622 _expect(byte, _CharCode.CR); 622 _expect(byte, _CharCode.CR);
623 _state = _State.CHUNKED_BODY_DONE_LF; 623 _state = _State.CHUNKED_BODY_DONE_LF;
624 break; 624 break;
625 625
626 case _State.CHUNKED_BODY_DONE_LF: 626 case _State.CHUNKED_BODY_DONE_LF:
627 _expect(byte, _CharCode.LF); 627 _expect(byte, _CharCode.LF);
628 _state = _State.START; 628 _reset();
629 _closeIncoming(); 629 _closeIncoming();
630 break; 630 break;
631 631
632 case _State.BODY: 632 case _State.BODY:
633 // The body is not handled one byte at a time but in blocks. 633 // The body is not handled one byte at a time but in blocks.
634 _index--; 634 _index--;
635 int dataAvailable = _buffer.length - _index; 635 int dataAvailable = _buffer.length - _index;
636 List<int> data; 636 List<int> data;
637 if (_remainingContent == null || 637 if (_remainingContent == null ||
638 dataAvailable <= _remainingContent) { 638 dataAvailable <= _remainingContent) {
639 data = new Uint8List(dataAvailable); 639 data = new Uint8List(dataAvailable);
640 data.setRange(0, dataAvailable, _buffer, _index); 640 data.setRange(0, dataAvailable, _buffer, _index);
641 } else { 641 } else {
642 data = new Uint8List(_remainingContent); 642 data = new Uint8List(_remainingContent);
643 data.setRange(0, _remainingContent, _buffer, _index); 643 data.setRange(0, _remainingContent, _buffer, _index);
644 } 644 }
645 645
646 _bodyController.add(data); 646 _bodyController.add(data);
647 if (_remainingContent != null) { 647 if (_remainingContent != null) {
648 _remainingContent -= data.length; 648 _remainingContent -= data.length;
649 } 649 }
650 _index += data.length; 650 _index += data.length;
651 if (_remainingContent == 0) { 651 if (_remainingContent == 0) {
652 if (!_chunked) { 652 if (!_chunked) {
653 _state = _State.START; 653 _reset();
654 _closeIncoming(); 654 _closeIncoming();
655 } else { 655 } else {
656 _state = _State.CHUNK_SIZE_STARTING_CR; 656 _state = _State.CHUNK_SIZE_STARTING_CR;
657 } 657 }
658 } 658 }
659 break; 659 break;
660 660
661 case _State.FAILURE: 661 case _State.FAILURE:
662 // Should be unreachable. 662 // Should be unreachable.
663 assert(false); 663 assert(false);
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 StreamController<_HttpIncoming> _controller; 956 StreamController<_HttpIncoming> _controller;
957 StreamController<List<int>> _bodyController; 957 StreamController<List<int>> _bodyController;
958 } 958 }
959 959
960 960
961 class HttpParserException implements Exception { 961 class HttpParserException implements Exception {
962 const HttpParserException([String this.message = ""]); 962 const HttpParserException([String this.message = ""]);
963 String toString() => "HttpParserException: $message"; 963 String toString() => "HttpParserException: $message";
964 final String message; 964 final String message;
965 } 965 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/http_keep_alive_test.dart » ('j') | tests/standalone/io/http_keep_alive_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698