Skip to content

Commit 284d9ee

Browse files
committed
http_get test shows request headers work
1 parent e51745f commit 284d9ee

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

examples/http_get.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
use std::error::Error;
2-
use wstd::http::{Client, Method, Request};
2+
use wstd::http::{Client, HeaderValue, Method, Request};
33
use wstd::io::AsyncRead;
44

55
#[wstd::main]
66
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+
812
let mut response = Client::new().send(request).await?;
913

1014
let content_type = response
@@ -29,5 +33,15 @@ async fn main() -> Result<(), Box<dyn Error>> {
2933
"expected body url to contain the authority and path, got: {body_url}"
3034
);
3135

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+
3246
Ok(())
3347
}

0 commit comments

Comments
 (0)