@@ -14,58 +14,25 @@ use std::net::SocketAddr;
14
14
15
15
use conduit:: { Extensions , HeaderMap , Host , Method , RequestExt , Scheme , StartInstant , Version } ;
16
16
use http:: request:: Parts as HttpParts ;
17
+ use http:: Request ;
17
18
use hyper:: body:: Bytes ;
18
19
19
- /// Owned data consumed by the background thread
20
- ///
21
- /// `ConduitRequest` cannot be sent between threads, so the needed request data
22
- /// is extracted from hyper on a core thread and taken by the background thread.
23
- pub ( crate ) struct RequestInfo ( Option < ( Parts , Bytes ) > ) ;
24
-
25
- impl RequestInfo {
26
- /// Save the request info that can be sent between threads
27
- pub ( crate ) fn new ( parts : HttpParts , body : Bytes ) -> Self {
28
- let tuple = ( Parts ( parts) , body) ;
29
- Self ( Some ( tuple) )
30
- }
31
-
32
- /// Take back the request info
33
- ///
34
- /// Call this from the background thread to obtain ownership of the `Send` data.
35
- ///
36
- /// # Panics
37
- ///
38
- /// Panics if called more than once on a value.
39
- fn take ( & mut self ) -> ( Parts , Bytes ) {
40
- self . 0 . take ( ) . expect ( "called take multiple times" )
41
- }
42
- }
43
-
44
- #[ derive( Debug ) ]
45
- pub ( crate ) struct Parts ( HttpParts ) ;
46
-
47
- impl Parts {
48
- fn headers ( & self ) -> & HeaderMap {
49
- & self . 0 . headers
50
- }
51
- }
52
-
53
20
pub ( crate ) struct ConduitRequest {
54
- parts : Parts ,
21
+ parts : HttpParts ,
55
22
path : String ,
56
23
remote_addr : SocketAddr ,
57
24
body : Cursor < Bytes > ,
58
25
}
59
26
60
27
impl ConduitRequest {
61
- pub ( crate ) fn new ( info : & mut RequestInfo , remote_addr : SocketAddr , now : StartInstant ) -> Self {
62
- let ( mut parts, body) = info . take ( ) ;
63
- let path = parts. 0 . uri . path ( ) . as_bytes ( ) ;
28
+ pub ( crate ) fn new ( request : Request < Bytes > , remote_addr : SocketAddr , now : StartInstant ) -> Self {
29
+ let ( mut parts, body) = request . into_parts ( ) ;
30
+ let path = parts. uri . path ( ) . as_bytes ( ) ;
64
31
let path = percent_encoding:: percent_decode ( path)
65
32
. decode_utf8_lossy ( )
66
33
. into_owned ( ) ;
67
34
68
- parts. 0 . extensions . insert ( now) ;
35
+ parts. extensions . insert ( now) ;
69
36
70
37
Self {
71
38
parts,
@@ -76,7 +43,7 @@ impl ConduitRequest {
76
43
}
77
44
78
45
fn parts ( & self ) -> & HttpParts {
79
- & self . parts . 0
46
+ & self . parts
80
47
}
81
48
}
82
49
@@ -95,7 +62,7 @@ impl RequestExt for ConduitRequest {
95
62
}
96
63
97
64
fn headers ( & self ) -> & HeaderMap {
98
- self . parts . headers ( )
65
+ & self . parts . headers
99
66
}
100
67
101
68
/// Returns the length of the buffered body
@@ -121,19 +88,18 @@ impl RequestExt for ConduitRequest {
121
88
}
122
89
123
90
fn extensions ( & self ) -> & Extensions {
124
- & self . parts . 0 . extensions
91
+ & self . parts . extensions
125
92
}
126
93
127
94
fn mut_extensions ( & mut self ) -> & mut Extensions {
128
- & mut self . parts . 0 . extensions
95
+ & mut self . parts . extensions
129
96
}
130
97
131
98
/// Returns the value of the `Host` header
132
99
///
133
100
/// If the header is not present or is invalid UTF-8, then the empty string is returned
134
101
fn host ( & self ) -> Host < ' _ > {
135
102
let host = self
136
- . parts
137
103
. headers ( )
138
104
. get ( http:: header:: HOST )
139
105
. map ( |h| h. to_str ( ) . unwrap_or ( "" ) )
0 commit comments