@@ -5,6 +5,7 @@ use super::{Body, HttpClient, Request, Response};
5
5
use futures:: future:: BoxFuture ;
6
6
use futures:: prelude:: * ;
7
7
8
+ use std:: convert:: TryFrom ;
8
9
use std:: io;
9
10
use std:: pin:: Pin ;
10
11
use std:: task:: { Context , Poll } ;
@@ -33,17 +34,19 @@ impl HttpClient for WasmClient {
33
34
34
35
fn send ( & self , req : Request ) -> BoxFuture < ' static , Result < Response , Self :: Error > > {
35
36
let fut = Box :: pin ( async move {
36
- let url = format ! ( "{}" , req. uri( ) ) ;
37
- let req = fetch:: new ( req. method ( ) . as_str ( ) , & url) ;
37
+ let req = fetch:: new ( req. method ( ) , req. url ( ) ) ;
38
38
let mut res = req. send ( ) . await ?;
39
39
40
40
let body = res. body_bytes ( ) ;
41
- let mut response = Response :: new ( Body :: from ( body ) ) ;
42
- * response . status_mut ( ) = http :: StatusCode :: from_u16 ( res. status ( ) ) . unwrap ( ) ;
43
-
41
+ let mut response =
42
+ Response :: new ( http_types :: StatusCode :: try_from ( res. status ( ) ) . unwrap ( ) ) ;
43
+ response . set_body ( Body :: from ( body ) ) ;
44
44
for ( name, value) in res. headers ( ) {
45
- let name: http:: header:: HeaderName = name. parse ( ) . unwrap ( ) ;
46
- response. headers_mut ( ) . insert ( name, value. parse ( ) . unwrap ( ) ) ;
45
+ let name: http_types:: headers:: HeaderName = name. parse ( ) . unwrap ( ) ;
46
+ response. insert_header (
47
+ & name,
48
+ value. parse :: < http_types:: headers:: HeaderValue > ( ) . unwrap ( ) ,
49
+ ) ;
47
50
}
48
51
49
52
Ok ( response)
0 commit comments