@@ -72,13 +72,24 @@ pub(super) enum Parse {
72
72
#[ cfg( feature = "http1" ) ]
73
73
VersionH2 ,
74
74
Uri ,
75
- Header ,
75
+ Header ( Header ) ,
76
76
TooLarge ,
77
77
Status ,
78
78
#[ cfg_attr( debug_assertions, allow( unused) ) ]
79
79
Internal ,
80
80
}
81
81
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
+
82
93
#[ derive( Debug ) ]
83
94
pub ( super ) enum User {
84
95
/// Error calling user's HttpBody::poll_data().
@@ -375,7 +386,19 @@ impl Error {
375
386
#[ cfg( feature = "http1" ) ]
376
387
Kind :: Parse ( Parse :: VersionH2 ) => "invalid HTTP version parsed (found HTTP2 preface)" ,
377
388
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
+ }
379
402
Kind :: Parse ( Parse :: TooLarge ) => "message head is too large" ,
380
403
Kind :: Parse ( Parse :: Status ) => "invalid HTTP status-code parsed" ,
381
404
Kind :: Parse ( Parse :: Internal ) => {
@@ -475,13 +498,28 @@ impl From<Parse> for Error {
475
498
}
476
499
}
477
500
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
+
478
516
impl From < httparse:: Error > for Parse {
479
517
fn from ( err : httparse:: Error ) -> Parse {
480
518
match err {
481
519
httparse:: Error :: HeaderName
482
520
| httparse:: Error :: HeaderValue
483
521
| httparse:: Error :: NewLine
484
- | httparse:: Error :: Token => Parse :: Header ,
522
+ | httparse:: Error :: Token => Parse :: Header ( Header :: Token ) ,
485
523
httparse:: Error :: Status => Parse :: Status ,
486
524
httparse:: Error :: TooManyHeaders => Parse :: TooLarge ,
487
525
httparse:: Error :: Version => Parse :: Version ,
0 commit comments