@@ -364,12 +364,12 @@ public void setHeaderCacheCaseSensitive(boolean headerCacheCaseSensitive)
364364 _fieldCache .setCaseSensitive (headerCacheCaseSensitive );
365365 }
366366
367- protected void checkViolation (Violation violation ) throws BadMessageException
367+ protected void checkViolation (Violation violation ) throws HttpException . RuntimeException
368368 {
369369 if (violation .isAllowedBy (_complianceMode ))
370370 reportComplianceViolation (violation , violation .getDescription ());
371371 else
372- throw new BadMessageException ( violation .getDescription ());
372+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , violation .getDescription ());
373373 }
374374
375375 protected void reportComplianceViolation (Violation violation )
@@ -503,7 +503,7 @@ private HttpTokens.Token next(ByteBuffer buffer)
503503
504504 case CR :
505505 if (_cr )
506- throw new BadMessageException ( "Bad EOL" );
506+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "Bad EOL" );
507507
508508 if (buffer .hasRemaining ())
509509 {
@@ -514,7 +514,7 @@ private HttpTokens.Token next(ByteBuffer buffer)
514514 {
515515 case CNTL -> throw new IllegalCharacterException (_state , t , buffer );
516516 case LF -> EOL_CRLF ;
517- default -> throw new BadMessageException ( "Bad EOL" );
517+ default -> throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "Bad EOL" );
518518 };
519519 }
520520 _cr = true ;
@@ -529,7 +529,7 @@ private HttpTokens.Token next(ByteBuffer buffer)
529529 case OTEXT :
530530 case COLON :
531531 if (_cr )
532- throw new BadMessageException ( "Bad EOL" );
532+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "Bad EOL" );
533533 break ;
534534
535535 default :
@@ -547,9 +547,9 @@ private void addAndCheckHeadersSize(int delta)
547547 if (_headerBytes > _maxHeaderBytes )
548548 {
549549 if (_state == State .URI )
550- throw new BadMessageException (HttpStatus .URI_TOO_LONG_414 );
550+ throw new HttpException . RuntimeException (HttpStatus .URI_TOO_LONG_414 );
551551 if (_requestParser )
552- throw new BadMessageException (HttpStatus .REQUEST_HEADER_FIELDS_TOO_LARGE_431 );
552+ throw new HttpException . RuntimeException (HttpStatus .REQUEST_HEADER_FIELDS_TOO_LARGE_431 );
553553 throw new HttpException .RuntimeException (_responseStatus , "Response Header Bytes Too Large" );
554554 }
555555 }
@@ -786,7 +786,7 @@ else if (Violation.CASE_INSENSITIVE_METHOD.isAllowedBy(_complianceMode))
786786 break ;
787787
788788 case EOL :
789- throw new BadMessageException ( "No URI" );
789+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "No URI" );
790790
791791 case ALPHA :
792792 case DIGIT :
@@ -818,7 +818,7 @@ else if (Violation.CASE_INSENSITIVE_METHOD.isAllowedBy(_complianceMode))
818818 _string .append (t .getChar ());
819819 break ;
820820 case EOL :
821- throw new BadMessageException ( "No Status" );
821+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "No Status" );
822822 default :
823823 throw new IllegalCharacterException (_state , t , buffer );
824824 }
@@ -838,7 +838,7 @@ else if (Violation.CASE_INSENSITIVE_METHOD.isAllowedBy(_complianceMode))
838838 if (!_requestParser )
839839 {
840840 if (t .getType () != HttpTokens .Type .DIGIT || t .getByte () == '0' )
841- throw new BadMessageException ( "Bad status" );
841+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "Bad status" );
842842 setState (State .STATUS );
843843 setResponseStatus (t .getByte () - '0' );
844844 }
@@ -873,7 +873,7 @@ else if (Violation.CASE_INSENSITIVE_METHOD.isAllowedBy(_complianceMode))
873873
874874 default :
875875 if (_requestParser )
876- throw new BadMessageException ( "No URI" );
876+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "No URI" );
877877 else
878878 throw new HttpException .RuntimeException (_responseStatus , "No Status" );
879879 }
@@ -885,14 +885,14 @@ else if (Violation.CASE_INSENSITIVE_METHOD.isAllowedBy(_complianceMode))
885885 {
886886 case SPACE :
887887 if (_responseStatus < 100 )
888- throw new BadMessageException ( "Bad status" );
888+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "Bad status" );
889889 setState (State .SPACE2 );
890890 break ;
891891
892892 case DIGIT :
893893 _responseStatus = _responseStatus * 10 + (t .getByte () - '0' );
894894 if (_responseStatus >= 1000 )
895- throw new BadMessageException ( "Bad status" );
895+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "Bad status" );
896896 break ;
897897
898898 case EOL :
@@ -902,7 +902,7 @@ else if (Violation.CASE_INSENSITIVE_METHOD.isAllowedBy(_complianceMode))
902902 break ;
903903
904904 default :
905- throw new BadMessageException ( "Bad status" );
905+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "Bad status" );
906906 }
907907 break ;
908908
@@ -1154,7 +1154,7 @@ private void parsedHeader()
11541154 {
11551155 checkViolation (MULTIPLE_CONTENT_LENGTHS );
11561156 if (contentLength != _contentLength )
1157- throw new BadMessageException ( MULTIPLE_CONTENT_LENGTHS .getDescription ());
1157+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , MULTIPLE_CONTENT_LENGTHS .getDescription ());
11581158 }
11591159 _hasContentLength = true ;
11601160
@@ -1173,7 +1173,7 @@ private void parsedHeader()
11731173
11741174 // we encountered another Transfer-Encoding header, but chunked was already set
11751175 if (_endOfContent == EndOfContent .CHUNKED_CONTENT )
1176- throw new BadMessageException ( "Bad Transfer-Encoding, chunked not last" );
1176+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "Bad Transfer-Encoding, chunked not last" );
11771177
11781178 if (HttpHeaderValue .CHUNKED .is (_valueString ))
11791179 {
@@ -1190,7 +1190,7 @@ private void parsedHeader()
11901190 if (HttpHeaderValue .CHUNKED .is (values .get (i )))
11911191 {
11921192 if (chunked != -1 )
1193- throw new BadMessageException ( "Bad Transfer-Encoding, multiple chunked tokens" );
1193+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "Bad Transfer-Encoding, multiple chunked tokens" );
11941194 chunked = i ;
11951195 // declared chunked
11961196 _endOfContent = EndOfContent .CHUNKED_CONTENT ;
@@ -1199,7 +1199,7 @@ private void parsedHeader()
11991199 // we have a non-chunked token after a declared chunked token
12001200 else if (_endOfContent == EndOfContent .CHUNKED_CONTENT )
12011201 {
1202- throw new BadMessageException ( "Bad Transfer-Encoding, chunked not last" );
1202+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "Bad Transfer-Encoding, chunked not last" );
12031203 }
12041204 }
12051205 }
@@ -1287,7 +1287,7 @@ private void parsedTrailer()
12871287 private long convertContentLength (String valueString )
12881288 {
12891289 if (valueString == null || valueString .isEmpty ())
1290- throw new BadMessageException ( "Invalid Content-Length Value" , new NumberFormatException ());
1290+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "Invalid Content-Length Value" , new NumberFormatException ());
12911291
12921292 long value = 0 ;
12931293 int length = valueString .length ();
@@ -1296,7 +1296,7 @@ private long convertContentLength(String valueString)
12961296 {
12971297 char c = valueString .charAt (i );
12981298 if (c < '0' || c > '9' )
1299- throw new BadMessageException ( "Invalid Content-Length Value" , new NumberFormatException ());
1299+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "Invalid Content-Length Value" , new NumberFormatException ());
13001300
13011301 value = Math .addExact (Math .multiplyExact (value , 10 ), c - '0' );
13021302 }
@@ -1370,14 +1370,14 @@ protected boolean parseFields(ByteBuffer buffer)
13701370 {
13711371 // Transfer-Encoding chunked not specified
13721372 // https://tools.ietf.org/html/rfc7230#section-3.3.1
1373- throw new BadMessageException ( "Bad Transfer-Encoding, chunked not last" );
1373+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "Bad Transfer-Encoding, chunked not last" );
13741374 }
13751375 }
13761376
13771377 // Was there a required host header?
13781378 if (_parsedHost == null && _version == HttpVersion .HTTP_1_1 && _requestParser )
13791379 {
1380- throw new BadMessageException ( "No Host" );
1380+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "No Host" );
13811381 }
13821382
13831383 // is it a response that cannot have a body?
@@ -1803,7 +1803,7 @@ else if (isTerminated())
18031803 LOG .debug ("{} EOF in {}" , this , _state );
18041804 setState (State .CLOSED );
18051805 if (_requestParser )
1806- _handler .badMessage (new BadMessageException (HttpStatus .BAD_REQUEST_400 , "Early EOF" ));
1806+ _handler .badMessage (new HttpException . RuntimeException (HttpStatus .BAD_REQUEST_400 , "Early EOF" ));
18071807 else
18081808 _handler .badMessage (new HttpException .RuntimeException (_responseStatus , "Early EOF" ));
18091809 break ;
@@ -1821,7 +1821,7 @@ else if (isTerminated())
18211821 else
18221822 {
18231823 if (_requestParser )
1824- bad = new BadMessageException ( "Bad Request" , x );
1824+ bad = new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , "Bad Request" , x );
18251825 else
18261826 bad = new HttpException .RuntimeException (_responseStatus , "Bad Response" , x );
18271827 }
@@ -1968,7 +1968,7 @@ protected boolean parseContent(ByteBuffer buffer)
19681968 if (t .isHexDigit ())
19691969 {
19701970 if (_chunkLength > MAX_CHUNK_LENGTH )
1971- throw new BadMessageException (HttpStatus .PAYLOAD_TOO_LARGE_413 );
1971+ throw new HttpException . RuntimeException (HttpStatus .PAYLOAD_TOO_LARGE_413 );
19721972 _chunkLength = _chunkLength * 16 + t .getHexDigit ();
19731973 }
19741974 else if (t .getChar () == ';' )
@@ -2256,11 +2256,11 @@ public interface ResponseHandler extends HttpHandler
22562256 void startResponse (HttpVersion version , int status , String reason );
22572257 }
22582258
2259- private static class IllegalCharacterException extends BadMessageException
2259+ private static class IllegalCharacterException extends HttpException . RuntimeException
22602260 {
22612261 private IllegalCharacterException (State state , HttpTokens .Token token , ByteBuffer buffer )
22622262 {
2263- super (String .format ("Illegal character %s" , token ));
2263+ super (HttpStatus . BAD_REQUEST_400 , String .format ("Illegal character %s" , token ));
22642264 if (LOG .isDebugEnabled ())
22652265 LOG .debug (String .format ("Illegal character %s in state=%s for buffer %s" , token , state , BufferUtil .toDetailString (buffer )));
22662266 }
@@ -2381,7 +2381,7 @@ protected void onComplianceViolation(ComplianceViolation violation, String value
23812381 if (_complianceMode .allows (violation ))
23822382 _handler .onViolation (new ComplianceViolation .Event (_complianceMode , violation , value ));
23832383 else
2384- throw new BadMessageException ( violation .toString ());
2384+ throw new HttpException . RuntimeException ( HttpStatus . BAD_REQUEST_400 , violation .toString ());
23852385 }
23862386 };
23872387 }
0 commit comments