@@ -400,10 +400,10 @@ class _HttpParser extends Stream<_HttpIncoming> {
400400 assert (! _parserCalled);
401401 _parserCalled = true ;
402402 if (_state == _State .CLOSED ) {
403- throw new HttpException ("Data on closed connection" );
403+ throw HttpException ("Data on closed connection" );
404404 }
405405 if (_state == _State .FAILURE ) {
406- throw new HttpException ("Data on failed connection" );
406+ throw HttpException ("Data on failed connection" );
407407 }
408408 while (_buffer != null &&
409409 _index < _buffer! .length &&
@@ -427,11 +427,11 @@ class _HttpParser extends Stream<_HttpIncoming> {
427427 } else {
428428 // Start parsing method.
429429 if (! _isTokenChar (byte)) {
430- throw new HttpException ("Invalid request method" );
430+ throw HttpException ("Invalid request method" );
431431 }
432432 _method.add (byte);
433433 if (! _requestParser) {
434- throw new HttpException ("Invalid response line" );
434+ throw HttpException ("Invalid response line" );
435435 }
436436 _state = _State .REQUEST_LINE_METHOD ;
437437 }
@@ -449,7 +449,7 @@ class _HttpParser extends Stream<_HttpIncoming> {
449449 // method anymore.
450450 _httpVersionIndex = httpVersionIndex + 1 ;
451451 if (_requestParser) {
452- throw new HttpException ("Invalid request line" );
452+ throw HttpException ("Invalid request line" );
453453 }
454454 _state = _State .RESPONSE_HTTP_VERSION ;
455455 } else {
@@ -463,7 +463,7 @@ class _HttpParser extends Stream<_HttpIncoming> {
463463 _method.add (byte);
464464 _httpVersion = _HttpVersion .UNDETERMINED ;
465465 if (! _requestParser) {
466- throw new HttpException ("Invalid response line" );
466+ throw HttpException ("Invalid response line" );
467467 }
468468 _state = _State .REQUEST_LINE_METHOD ;
469469 }
@@ -493,7 +493,8 @@ class _HttpParser extends Stream<_HttpIncoming> {
493493 // HTTP version parsed.
494494 _state = _State .RESPONSE_LINE_STATUS_CODE ;
495495 } else {
496- throw new HttpException ("Invalid response line" );
496+ throw HttpException (
497+ "Invalid response line, failed to parse HTTP version" );
497498 }
498499 break ;
499500
@@ -504,7 +505,7 @@ class _HttpParser extends Stream<_HttpIncoming> {
504505 if (_Const .SEPARATOR_MAP [byte] ||
505506 byte == _CharCode .CR ||
506507 byte == _CharCode .LF ) {
507- throw new HttpException ("Invalid request method" );
508+ throw HttpException ("Invalid request method" );
508509 }
509510 _method.add (byte);
510511 }
@@ -513,13 +514,13 @@ class _HttpParser extends Stream<_HttpIncoming> {
513514 case _State .REQUEST_LINE_URI :
514515 if (byte == _CharCode .SP ) {
515516 if (_uriOrReasonPhrase.length == 0 ) {
516- throw new HttpException ("Invalid request URI" );
517+ throw HttpException ("Invalid request, empty URI" );
517518 }
518519 _state = _State .REQUEST_LINE_HTTP_VERSION ;
519520 _httpVersionIndex = 0 ;
520521 } else {
521522 if (byte == _CharCode .CR || byte == _CharCode .LF ) {
522- throw new HttpException ("Invalid request URI" );
523+ throw HttpException ("Invalid request, unexpected $ byte in URI" );
523524 }
524525 _uriOrReasonPhrase.add (byte);
525526 }
@@ -542,7 +543,7 @@ class _HttpParser extends Stream<_HttpIncoming> {
542543 _persistentConnection = false ;
543544 _httpVersionIndex = httpVersionIndex + 1 ;
544545 } else {
545- throw new HttpException ("Invalid response line " );
546+ throw HttpException ("Invalid response, invalid HTTP version " );
546547 }
547548 } else {
548549 if (byte == _CharCode .CR ) {
@@ -570,8 +571,11 @@ class _HttpParser extends Stream<_HttpIncoming> {
570571 _state = _State .RESPONSE_LINE_ENDING ;
571572 } else {
572573 _statusCodeLength++ ;
573- if (byte < 0x30 || byte > 0x39 || _statusCodeLength > 3 ) {
574- throw new HttpException ("Invalid response status code" );
574+ if (byte < 0x30 || byte > 0x39 ) {
575+ throw HttpException ("Invalid response status code with $byte " );
576+ } else if (_statusCodeLength > 3 ) {
577+ throw HttpException (
578+ "Invalid response, status code is over 3 digits" );
575579 } else {
576580 _statusCode = _statusCode * 10 + byte - 0x30 ;
577581 }
@@ -583,7 +587,8 @@ class _HttpParser extends Stream<_HttpIncoming> {
583587 _state = _State .RESPONSE_LINE_ENDING ;
584588 } else {
585589 if (byte == _CharCode .CR || byte == _CharCode .LF ) {
586- throw new HttpException ("Invalid response reason phrase" );
590+ throw HttpException (
591+ "Invalid response, unexpected $byte in reason phrase" );
587592 }
588593 _uriOrReasonPhrase.add (byte);
589594 }
@@ -592,15 +597,9 @@ class _HttpParser extends Stream<_HttpIncoming> {
592597 case _State .RESPONSE_LINE_ENDING :
593598 _expect (byte, _CharCode .LF );
594599 _messageType == _MessageType .RESPONSE ;
595- if (_statusCode < 100 || _statusCode > 599 ) {
596- throw new HttpException ("Invalid response status code" );
597- } else {
598- // Check whether this response will never have a body.
599- if (_statusCode <= 199 ||
600- _statusCode == 204 ||
601- _statusCode == 304 ) {
602- _noMessageBody = true ;
603- }
600+ // Check whether this response will never have a body.
601+ if (_statusCode <= 199 || _statusCode == 204 || _statusCode == 304 ) {
602+ _noMessageBody = true ;
604603 }
605604 _state = _State .HEADER_START ;
606605 break ;
@@ -624,7 +623,7 @@ class _HttpParser extends Stream<_HttpIncoming> {
624623 _state = _State .HEADER_VALUE_START ;
625624 } else {
626625 if (! _isTokenChar (byte)) {
627- throw new HttpException ("Invalid header field name" );
626+ throw HttpException ("Invalid header field name, with $ byte " );
628627 }
629628 _headerField.add (_toLowerCaseByte (byte));
630629 }
@@ -706,10 +705,8 @@ class _HttpParser extends Stream<_HttpIncoming> {
706705 _expect (byte, _CharCode .LF );
707706 if (_headersEnd ()) {
708707 return ;
709- } else {
710- break ;
711708 }
712- return ;
709+ break ;
713710
714711 case _State .CHUNK_SIZE_STARTING_CR :
715712 _expect (byte, _CharCode .CR );
@@ -886,9 +883,7 @@ class _HttpParser extends Stream<_HttpIncoming> {
886883 bool get upgrade => _connectionUpgrade && _state == _State .UPGRADED ;
887884 bool get persistentConnection => _persistentConnection;
888885
889- void set isHead (bool value) {
890- if (value) _noMessageBody = true ;
891- }
886+ void set isHead (bool value) => _noMessageBody = value ?? false ;
892887
893888 _HttpDetachedIncoming detachIncoming () {
894889 // Simulate detached by marking as upgraded.
@@ -982,8 +977,7 @@ class _HttpParser extends Stream<_HttpIncoming> {
982977
983978 void _expect (int val1, int val2) {
984979 if (val1 != val2) {
985- throw new HttpException (
986- "Failed to parse HTTP, $val1 does not match $val2 " );
980+ throw HttpException ("Failed to parse HTTP, $val1 does not match $val2 " );
987981 }
988982 }
989983
@@ -995,8 +989,8 @@ class _HttpParser extends Stream<_HttpIncoming> {
995989 } else if (0x61 <= byte && byte <= 0x66 ) {
996990 return byte - 0x61 + 10 ; // a - f
997991 } else {
998- throw new HttpException (
999- "Failed to parse HTTP, $byte should be a Hex digit" );
992+ throw HttpException (
993+ "Failed to parse HTTP, $byte is expected to be a Hex digit" );
1000994 }
1001995 }
1002996
0 commit comments