File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 1
1
use std:: error:: Error ;
2
- use wstd:: http:: { Client , Method , Request } ;
2
+ use wstd:: http:: { Client , HeaderValue , Method , Request } ;
3
3
use wstd:: io:: AsyncRead ;
4
4
5
5
#[ wstd:: main]
6
6
async fn main ( ) -> Result < ( ) , Box < dyn Error > > {
7
- let request = Request :: new ( Method :: GET , "https://postman-echo.com/get" . parse ( ) ?) ;
7
+ let mut request = Request :: new ( Method :: GET , "https://postman-echo.com/get" . parse ( ) ?) ;
8
+ request
9
+ . headers_mut ( )
10
+ . insert ( "my-header" , HeaderValue :: from_str ( "my-value" ) ?) ;
11
+
8
12
let mut response = Client :: new ( ) . send ( request) . await ?;
9
13
10
14
let content_type = response
@@ -29,5 +33,15 @@ async fn main() -> Result<(), Box<dyn Error>> {
29
33
"expected body url to contain the authority and path, got: {body_url}"
30
34
) ;
31
35
36
+ assert_eq ! (
37
+ val. get( "headers" )
38
+ . ok_or_else( || "body json has headers" ) ?
39
+ . get( "my-header" )
40
+ . ok_or_else( || "headers contains my-header" ) ?
41
+ . as_str( )
42
+ . ok_or_else( || "my-header is a str" ) ?,
43
+ "my-value"
44
+ ) ;
45
+
32
46
Ok ( ( ) )
33
47
}
You can’t perform that action at this time.
0 commit comments