@@ -8,9 +8,9 @@ use std::mem;
8
8
#[ cfg( any( test, feature = "server" , feature = "ffi" ) ) ]
9
9
use bytes:: Bytes ;
10
10
use bytes:: BytesMut ;
11
- use http:: header:: { self , Entry , HeaderName , HeaderValue } ;
12
11
#[ cfg( feature = "server" ) ]
13
12
use http:: header:: ValueIter ;
13
+ use http:: header:: { self , Entry , HeaderName , HeaderValue } ;
14
14
use http:: { HeaderMap , Method , StatusCode , Version } ;
15
15
16
16
use crate :: body:: DecodedLength ;
@@ -29,46 +29,35 @@ const AVERAGE_HEADER_SIZE: usize = 30; // totally scientific
29
29
30
30
macro_rules! header_name {
31
31
( $bytes: expr) => { {
32
- #[ cfg( debug_assertions) ]
33
32
{
34
33
match HeaderName :: from_bytes( $bytes) {
35
34
Ok ( name) => name,
36
- Err ( _) => panic!(
37
- "illegal header name from httparse: {:?}" ,
38
- :: bytes:: Bytes :: copy_from_slice( $bytes)
39
- ) ,
40
- }
41
- }
42
-
43
- #[ cfg( not( debug_assertions) ) ]
44
- {
45
- match HeaderName :: from_bytes( $bytes) {
46
- Ok ( name) => name,
47
- Err ( _) => panic!( "illegal header name from httparse: {:?}" , $bytes) ,
35
+ Err ( e) => maybe_panic!( e) ,
48
36
}
49
37
}
50
38
} } ;
51
39
}
52
40
53
41
macro_rules! header_value {
54
42
( $bytes: expr) => { {
55
- #[ cfg( debug_assertions) ]
56
43
{
57
- let __hvb: :: bytes:: Bytes = $bytes;
58
- match HeaderValue :: from_maybe_shared( __hvb. clone( ) ) {
59
- Ok ( name) => name,
60
- Err ( _) => panic!( "illegal header value from httparse: {:?}" , __hvb) ,
61
- }
62
- }
63
-
64
- #[ cfg( not( debug_assertions) ) ]
65
- {
66
- // Unsafe: httparse already validated header value
67
44
unsafe { HeaderValue :: from_maybe_shared_unchecked( $bytes) }
68
45
}
69
46
} } ;
70
47
}
71
48
49
+ macro_rules! maybe_panic {
50
+ ( $( $arg: tt) * ) => ( {
51
+ let _err = ( $( $arg) * ) ;
52
+ if cfg!( debug_assertions) {
53
+ panic!( "{:?}" , _err) ;
54
+ } else {
55
+ error!( "Internal Hyper error, please report {:?}" , _err) ;
56
+ return Err ( Parse :: Internal )
57
+ }
58
+ } )
59
+ }
60
+
72
61
pub ( super ) fn parse_headers < T > (
73
62
bytes : & mut BytesMut ,
74
63
ctx : ParseContext < ' _ > ,
@@ -891,8 +880,7 @@ impl Http1Transaction for Client {
891
880
) ;
892
881
let mut res = httparse:: Response :: new ( & mut headers) ;
893
882
let bytes = buf. as_ref ( ) ;
894
- match ctx. h1_parser_config . parse_response ( & mut res, bytes)
895
- {
883
+ match ctx. h1_parser_config . parse_response ( & mut res, bytes) {
896
884
Ok ( httparse:: Status :: Complete ( len) ) => {
897
885
trace ! ( "Response.parse Complete({})" , len) ;
898
886
let status = StatusCode :: from_u16 ( res. code . unwrap ( ) ) ?;
0 commit comments