@@ -72,13 +72,24 @@ pub(super) enum Parse {
7272 #[ cfg( feature = "http1" ) ]
7373 VersionH2 ,
7474 Uri ,
75- Header ,
75+ Header ( Header ) ,
7676 TooLarge ,
7777 Status ,
7878 #[ cfg_attr( debug_assertions, allow( unused) ) ]
7979 Internal ,
8080}
8181
82+ #[ derive( Debug ) ]
83+ pub ( super ) enum Header {
84+ Token ,
85+ #[ cfg( feature = "http1" ) ]
86+ ContentLengthInvalid ,
87+ #[ cfg( feature = "http1" ) ]
88+ TransferEncodingInvalid ,
89+ #[ cfg( feature = "http1" ) ]
90+ TransferEncodingUnexpected ,
91+ }
92+
8293#[ derive( Debug ) ]
8394pub ( super ) enum User {
8495 /// Error calling user's HttpBody::poll_data().
@@ -375,7 +386,19 @@ impl Error {
375386 #[ cfg( feature = "http1" ) ]
376387 Kind :: Parse ( Parse :: VersionH2 ) => "invalid HTTP version parsed (found HTTP2 preface)" ,
377388 Kind :: Parse ( Parse :: Uri ) => "invalid URI" ,
378- Kind :: Parse ( Parse :: Header ) => "invalid HTTP header parsed" ,
389+ Kind :: Parse ( Parse :: Header ( Header :: Token ) ) => "invalid HTTP header parsed" ,
390+ #[ cfg( feature = "http1" ) ]
391+ Kind :: Parse ( Parse :: Header ( Header :: ContentLengthInvalid ) ) => {
392+ "invalid content-length parsed"
393+ }
394+ #[ cfg( feature = "http1" ) ]
395+ Kind :: Parse ( Parse :: Header ( Header :: TransferEncodingInvalid ) ) => {
396+ "invalid transfer-encoding parsed"
397+ }
398+ #[ cfg( feature = "http1" ) ]
399+ Kind :: Parse ( Parse :: Header ( Header :: TransferEncodingUnexpected ) ) => {
400+ "unexpected transfer-encoding parsed"
401+ }
379402 Kind :: Parse ( Parse :: TooLarge ) => "message head is too large" ,
380403 Kind :: Parse ( Parse :: Status ) => "invalid HTTP status-code parsed" ,
381404 Kind :: Parse ( Parse :: Internal ) => {
@@ -475,13 +498,28 @@ impl From<Parse> for Error {
475498 }
476499}
477500
501+ #[ cfg( feature = "http1" ) ]
502+ impl Parse {
503+ pub ( crate ) fn content_length_invalid ( ) -> Self {
504+ Parse :: Header ( Header :: ContentLengthInvalid )
505+ }
506+
507+ pub ( crate ) fn transfer_encoding_invalid ( ) -> Self {
508+ Parse :: Header ( Header :: TransferEncodingInvalid )
509+ }
510+
511+ pub ( crate ) fn transfer_encoding_unexpected ( ) -> Self {
512+ Parse :: Header ( Header :: TransferEncodingUnexpected )
513+ }
514+ }
515+
478516impl From < httparse:: Error > for Parse {
479517 fn from ( err : httparse:: Error ) -> Parse {
480518 match err {
481519 httparse:: Error :: HeaderName
482520 | httparse:: Error :: HeaderValue
483521 | httparse:: Error :: NewLine
484- | httparse:: Error :: Token => Parse :: Header ,
522+ | httparse:: Error :: Token => Parse :: Header ( Header :: Token ) ,
485523 httparse:: Error :: Status => Parse :: Status ,
486524 httparse:: Error :: TooManyHeaders => Parse :: TooLarge ,
487525 httparse:: Error :: Version => Parse :: Version ,
0 commit comments