@@ -13,10 +13,9 @@ use std::io::{Cursor, Read};
1313use std:: net:: SocketAddr ;
1414use std:: path:: { Component , Path , PathBuf } ;
1515
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 ;
2019
2120/// Owned data consumed by the background thread
2221///
@@ -52,44 +51,6 @@ impl Parts {
5251 }
5352}
5453
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-
9354pub ( crate ) struct ConduitRequest {
9455 parts : Parts ,
9556 path : String ,
@@ -141,44 +102,22 @@ impl ConduitRequest {
141102 }
142103}
143104
144- impl Request for ConduitRequest {
105+ impl RequestExt for ConduitRequest {
145106 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
154108 }
155109
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
173112 }
174113
175114 /// Always returns Http
176115 fn scheme ( & self ) -> Scheme {
177116 Scheme :: Http
178117 }
179118
180- fn headers ( & self ) -> & dyn Headers {
181- & self . parts
119+ fn headers ( & self ) -> & HeaderMap {
120+ & self . parts . headers ( )
182121 }
183122
184123 /// Returns the length of the buffered body
@@ -228,13 +167,3 @@ impl Request for ConduitRequest {
228167 & mut self . body
229168 }
230169}
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