@@ -13,10 +13,9 @@ use std::io::{Cursor, Read};
13
13
use std:: net:: SocketAddr ;
14
14
use std:: path:: { Component , Path , PathBuf } ;
15
15
16
- use conduit:: { Extensions , Headers , Host , Method , Request , Scheme } ;
17
- use http:: { request:: Parts as HttpParts , HeaderMap } ;
18
- use hyper:: { body:: Bytes , Method as HyperMethod , Version as HttpVersion } ;
19
- use semver:: Version ;
16
+ use conduit:: { Extensions , HeaderMap , Host , Method , RequestExt , Scheme , Version } ;
17
+ use http:: request:: Parts as HttpParts ;
18
+ use hyper:: body:: Bytes ;
20
19
21
20
/// Owned data consumed by the background thread
22
21
///
@@ -52,44 +51,6 @@ impl Parts {
52
51
}
53
52
}
54
53
55
- impl Headers for Parts {
56
- /// Find all values associated with a header, or None.
57
- ///
58
- /// If the value of a header is not valid UTF-8, that value
59
- /// is replaced with the emtpy string.
60
- fn find ( & self , key : & str ) -> Option < Vec < & str > > {
61
- let values = self
62
- . headers ( )
63
- . get_all ( key)
64
- . iter ( )
65
- . map ( |v| v. to_str ( ) . unwrap_or ( "" ) )
66
- . collect :: < Vec < _ > > ( ) ;
67
-
68
- if values. is_empty ( ) {
69
- None
70
- } else {
71
- Some ( values)
72
- }
73
- }
74
-
75
- fn has ( & self , key : & str ) -> bool {
76
- self . headers ( ) . contains_key ( key)
77
- }
78
-
79
- /// Returns a representation of all headers
80
- fn all ( & self ) -> Vec < ( & str , Vec < & str > ) > {
81
- let mut all = Vec :: new ( ) ;
82
- for key in self . headers ( ) . keys ( ) {
83
- let key = key. as_str ( ) ;
84
- let values = self
85
- . find ( key)
86
- . expect ( "all keys should have at least one value" ) ;
87
- all. push ( ( key, values) ) ;
88
- }
89
- all
90
- }
91
- }
92
-
93
54
pub ( crate ) struct ConduitRequest {
94
55
parts : Parts ,
95
56
path : String ,
@@ -141,44 +102,22 @@ impl ConduitRequest {
141
102
}
142
103
}
143
104
144
- impl Request for ConduitRequest {
105
+ impl RequestExt for ConduitRequest {
145
106
fn http_version ( & self ) -> Version {
146
- match self . parts ( ) . version {
147
- HttpVersion :: HTTP_09 => version ( 0 , 9 ) ,
148
- HttpVersion :: HTTP_10 => version ( 1 , 0 ) ,
149
- HttpVersion :: HTTP_11 => version ( 1 , 1 ) ,
150
- HttpVersion :: HTTP_2 => version ( 2 , 0 ) ,
151
- HttpVersion :: HTTP_3 => version ( 3 , 0 ) ,
152
- _ => version ( 0 , 0 ) ,
153
- }
107
+ self . parts ( ) . version
154
108
}
155
109
156
- fn conduit_version ( & self ) -> Version {
157
- version ( 0 , 1 )
158
- }
159
-
160
- fn method ( & self ) -> Method {
161
- match self . parts ( ) . method {
162
- HyperMethod :: CONNECT => Method :: Connect ,
163
- HyperMethod :: DELETE => Method :: Delete ,
164
- HyperMethod :: GET => Method :: Get ,
165
- HyperMethod :: HEAD => Method :: Head ,
166
- HyperMethod :: OPTIONS => Method :: Options ,
167
- HyperMethod :: PATCH => Method :: Patch ,
168
- HyperMethod :: POST => Method :: Post ,
169
- HyperMethod :: PUT => Method :: Put ,
170
- HyperMethod :: TRACE => Method :: Trace ,
171
- _ => Method :: Other ( self . parts ( ) . method . to_string ( ) ) ,
172
- }
110
+ fn method ( & self ) -> & Method {
111
+ & self . parts ( ) . method
173
112
}
174
113
175
114
/// Always returns Http
176
115
fn scheme ( & self ) -> Scheme {
177
116
Scheme :: Http
178
117
}
179
118
180
- fn headers ( & self ) -> & dyn Headers {
181
- & self . parts
119
+ fn headers ( & self ) -> & HeaderMap {
120
+ & self . parts . headers ( )
182
121
}
183
122
184
123
/// Returns the length of the buffered body
@@ -228,13 +167,3 @@ impl Request for ConduitRequest {
228
167
& mut self . body
229
168
}
230
169
}
231
-
232
- fn version ( major : u64 , minor : u64 ) -> Version {
233
- Version {
234
- major,
235
- minor,
236
- patch : 0 ,
237
- pre : vec ! [ ] ,
238
- build : vec ! [ ] ,
239
- }
240
- }
0 commit comments