File tree 5 files changed +22
-9
lines changed
5 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ cookie = "0.12.0"
35
35
infer = " 0.1.2"
36
36
omnom = " 2.1.1"
37
37
pin-project-lite = " 0.1.0"
38
- url = " 2.1.0 "
38
+ url = " 2.1.1 "
39
39
serde_json = " 1.0.51"
40
40
serde = { version = " 1.0.106" , features = [" derive" ] }
41
41
serde_urlencoded = " 0.6.1"
Original file line number Diff line number Diff line change @@ -120,8 +120,7 @@ impl From<Request> for http::Request<Body> {
120
120
impl From < http:: Response < Body > > for Response {
121
121
fn from ( res : http:: Response < Body > ) -> Self {
122
122
let ( parts, body) = res. into_parts ( ) ;
123
- let status = parts. status . into ( ) ;
124
- let mut res = Response :: new ( status) ;
123
+ let mut res = Response :: new ( parts. status ) ;
125
124
res. set_body ( body) ;
126
125
res. set_version ( Some ( parts. version . into ( ) ) ) ;
127
126
hyperium_headers_to_headers ( parts. headers , res. as_mut ( ) ) ;
Original file line number Diff line number Diff line change 1
1
use async_std:: io:: { self , BufRead , Read } ;
2
2
use async_std:: sync;
3
3
4
- use std:: convert:: Into ;
4
+ use std:: convert:: { Into , TryInto } ;
5
5
use std:: mem;
6
6
use std:: ops:: Index ;
7
7
use std:: pin:: Pin ;
@@ -45,7 +45,12 @@ pin_project_lite::pin_project! {
45
45
46
46
impl Request {
47
47
/// Create a new request.
48
- pub fn new ( method : Method , url : Url ) -> Self {
48
+ pub fn new < U > ( method : Method , url : U ) -> Self
49
+ where
50
+ U : TryInto < Url > ,
51
+ U :: Error : std:: fmt:: Debug ,
52
+ {
53
+ let url = url. try_into ( ) . expect ( "Could not convert into a valid url" ) ;
49
54
let ( sender, receiver) = sync:: channel ( 1 ) ;
50
55
Self {
51
56
method,
@@ -687,7 +692,8 @@ mod tests {
687
692
use super :: * ;
688
693
689
694
fn build_test_request ( ) -> Request {
690
- Request :: new ( Method :: Get , "http://irrelevant/" . parse ( ) . unwrap ( ) )
695
+ let url = Url :: parse ( "http://irrelevant/" ) . unwrap ( ) ;
696
+ Request :: new ( Method :: Get , url)
691
697
}
692
698
693
699
fn set_x_forwarded_for ( request : & mut Request , client : & ' static str ) {
Original file line number Diff line number Diff line change 1
1
use async_std:: io:: { self , BufRead , Read } ;
2
2
use async_std:: sync;
3
3
4
- use std:: convert:: Into ;
4
+ use std:: convert:: { Into , TryInto } ;
5
+ use std:: fmt:: Debug ;
5
6
use std:: mem;
6
7
use std:: ops:: Index ;
7
8
use std:: pin:: Pin ;
@@ -48,7 +49,14 @@ pin_project_lite::pin_project! {
48
49
49
50
impl Response {
50
51
/// Create a new response.
51
- pub fn new ( status : StatusCode ) -> Self {
52
+ pub fn new < S > ( status : S ) -> Self
53
+ where
54
+ S : TryInto < StatusCode > ,
55
+ S :: Error : Debug ,
56
+ {
57
+ let status = status
58
+ . try_into ( )
59
+ . expect ( "Could not convert into a valid `StatusCode`" ) ;
52
60
let ( sender, receiver) = sync:: channel ( 1 ) ;
53
61
Self {
54
62
status,
Original file line number Diff line number Diff line change @@ -121,7 +121,7 @@ impl Trailers {
121
121
}
122
122
123
123
/// Get a reference to a header.
124
- pub fn get ( & self , name : & impl Into < HeaderName > ) -> Option < & HeaderValues > {
124
+ pub fn get ( & self , name : impl Into < HeaderName > ) -> Option < & HeaderValues > {
125
125
self . headers . get ( name)
126
126
}
127
127
You can’t perform that action at this time.
0 commit comments