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

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

Issue 11411121: Generate an error for active connections when the HTTP client is shutdown (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed long line Created 8 years, 1 month 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) 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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 575
576 void streamData(List<int> buffer) { 576 void streamData(List<int> buffer) {
577 assert(_buffer == null); 577 assert(_buffer == null);
578 _buffer = buffer; 578 _buffer = buffer;
579 _index = 0; 579 _index = 0;
580 _lastIndex = buffer.length; 580 _lastIndex = buffer.length;
581 _parse(); 581 _parse();
582 } 582 }
583 583
584 void streamDone() { 584 void streamDone() {
585 String type() => _requestParser ? "request" : "response";
586
585 // If the connection is idle the HTTP stream is closed. 587 // If the connection is idle the HTTP stream is closed.
586 if (_state == _State.START) { 588 if (_state == _State.START) {
587 if (_requestParser) { 589 if (_requestParser) {
588 closed(); 590 closed();
589 } else { 591 } else {
590 error( 592 error(
591 new HttpParserException( 593 new HttpParserException(
592 "Connection closed before full header was received")); 594 "Connection closed before full ${type()} header was received"));
593 } 595 }
594 return; 596 return;
595 } 597 }
596 598
597 if (_state < _State.FIRST_BODY_STATE) { 599 if (_state < _State.FIRST_BODY_STATE) {
598 _state = _State.FAILURE; 600 _state = _State.FAILURE;
599 // Report the error through the error callback if any. Otherwise 601 // Report the error through the error callback if any. Otherwise
600 // throw the error. 602 // throw the error.
601 error( 603 error(
602 new HttpParserException( 604 new HttpParserException(
603 "Connection closed before full header was received")); 605 "Connection closed before full ${type()} header was received"));
604 return; 606 return;
605 } 607 }
606 608
607 if (!_chunked && _contentLength == -1) { 609 if (!_chunked && _contentLength == -1) {
608 dataEnd(true); 610 dataEnd(true);
609 _state = _State.CLOSED; 611 _state = _State.CLOSED;
610 closed(); 612 closed();
611 } else { 613 } else {
612 _state = _State.FAILURE; 614 _state = _State.FAILURE;
613 // Report the error through the error callback if any. Otherwise 615 // Report the error through the error callback if any. Otherwise
614 // throw the error. 616 // throw the error.
615 error( 617 error(
616 new HttpParserException( 618 new HttpParserException(
617 "Connection closed before full body was received")); 619 "Connection closed before full ${type()} body was received"));
618 } 620 }
619 } 621 }
620 622
621 void streamError(e) { 623 void streamError(e) {
622 // Don't report errors when HTTP parser is in idle state. Clients 624 // Don't report errors when HTTP parser is in idle state. Clients
623 // can close the connection and cause a connection reset by peer 625 // can close the connection and cause a connection reset by peer
624 // error which is OK. 626 // error which is OK.
625 if (_state == _State.START) { 627 if (_state == _State.START) {
626 closed(); 628 closed();
627 return; 629 return;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 Function error; 768 Function error;
767 Function closed; 769 Function closed;
768 } 770 }
769 771
770 772
771 class HttpParserException implements Exception { 773 class HttpParserException implements Exception {
772 const HttpParserException([String this.message = ""]); 774 const HttpParserException([String this.message = ""]);
773 String toString() => "HttpParserException: $message"; 775 String toString() => "HttpParserException: $message";
774 final String message; 776 final String message;
775 } 777 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698