@@ -5,6 +5,8 @@ use crate::server::RemoteMock;
55use crate :: server:: State ;
66use crate :: Request ;
77use crate :: { Error , ErrorKind } ;
8+ use hyper:: header:: IntoHeaderName ;
9+ use hyper:: HeaderMap ;
810use hyper:: StatusCode ;
911use rand:: distributions:: Alphanumeric ;
1012use rand:: { thread_rng, Rng } ;
@@ -22,7 +24,7 @@ pub struct InnerMock {
2224 pub ( crate ) id : String ,
2325 pub ( crate ) method : String ,
2426 pub ( crate ) path : PathAndQueryMatcher ,
25- pub ( crate ) headers : Vec < ( String , Matcher ) > ,
27+ pub ( crate ) headers : HeaderMap < Matcher > ,
2628 pub ( crate ) body : Matcher ,
2729 pub ( crate ) response : Response ,
2830 pub ( crate ) hits : usize ,
@@ -40,8 +42,8 @@ impl fmt::Display for InnerMock {
4042 formatted. push ( ' ' ) ;
4143 formatted. push_str ( & self . path . to_string ( ) ) ;
4244
43- for & ( ref key, ref value) in & self . headers {
44- formatted. push_str ( key) ;
45+ for ( key, value) in & self . headers {
46+ formatted. push_str ( key. as_str ( ) ) ;
4547 formatted. push_str ( ": " ) ;
4648 formatted. push_str ( & value. to_string ( ) ) ;
4749 formatted. push_str ( "\r \n " ) ;
@@ -110,7 +112,7 @@ impl Mock {
110112 . collect ( ) ,
111113 method : method. to_owned ( ) . to_uppercase ( ) ,
112114 path : PathAndQueryMatcher :: Unified ( path. into ( ) ) ,
113- headers : Vec :: new ( ) ,
115+ headers : HeaderMap :: < Matcher > :: default ( ) ,
114116 body : Matcher :: Any ,
115117 response : Response :: default ( ) ,
116118 hits : 0 ,
@@ -200,10 +202,8 @@ impl Mock {
200202 /// .match_header("authorization", "password");
201203 /// ```
202204 ///
203- pub fn match_header < M : Into < Matcher > > ( mut self , field : & str , value : M ) -> Self {
204- self . inner
205- . headers
206- . push ( ( field. to_owned ( ) . to_lowercase ( ) , value. into ( ) ) ) ;
205+ pub fn match_header < T : IntoHeaderName , M : Into < Matcher > > ( mut self , field : T , value : M ) -> Self {
206+ self . inner . headers . append ( field, value. into ( ) ) ;
207207
208208 self
209209 }
@@ -283,11 +283,8 @@ impl Mock {
283283 /// s.mock("GET", "/").with_header("content-type", "application/json");
284284 /// ```
285285 ///
286- pub fn with_header ( mut self , field : & str , value : & str ) -> Self {
287- self . inner
288- . response
289- . headers
290- . push ( ( field. to_owned ( ) , value. to_owned ( ) ) ) ;
286+ pub fn with_header < T : IntoHeaderName > ( mut self , field : T , value : & str ) -> Self {
287+ self . inner . response . headers . append ( field, value. to_owned ( ) ) ;
291288
292289 self
293290 }
0 commit comments