Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/http/wasi/simple_fetch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[package]
name = "simple_fetch"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
publish = false

Expand Down
15 changes: 13 additions & 2 deletions examples/http/wasi/simple_fetch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,19 @@ async fn main(request: Request<Body>) -> anyhow::Result<Response<Body>> {

println!("Fetching: {target_url}");

let upstream_req = Request::get(&target_url)
.header("accept", "application/json")
let mut builder = Request::get(&target_url).header("accept", "application/json");

if let Some(fetch_header) = request
.headers()
.get("x-fetch-header")
.and_then(|v| v.to_str().ok())
{
if let Some((key, value)) = fetch_header.split_once(':') {
builder = builder.header(key.trim(), value.trim());
}
}
Comment on lines +31 to +39

let upstream_req = builder
.body(Body::empty())
.map_err(|e| anyhow!("failed to build request: {e}"))?;

Expand Down
Loading