Skip to content

Commit

Permalink
Copy through the authority unmodified to Host (#8563) (#8577)
Browse files Browse the repository at this point in the history
Fixes #8430

Co-authored-by: Trevor Elliott <[email protected]>
  • Loading branch information
alexcrichton and elliottt authored May 7, 2024
1 parent 2a23b42 commit 89af353
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
17 changes: 5 additions & 12 deletions crates/wasi-http/src/http_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,16 @@ impl<T: WasiHttpView> outgoing_handler::Host for T {
},
});

let (use_tls, scheme, port) = match req.scheme.unwrap_or(Scheme::Https) {
Scheme::Http => (false, http::uri::Scheme::HTTP, 80),
Scheme::Https => (true, http::uri::Scheme::HTTPS, 443),
let (use_tls, scheme) = match req.scheme.unwrap_or(Scheme::Https) {
Scheme::Http => (false, http::uri::Scheme::HTTP),
Scheme::Https => (true, http::uri::Scheme::HTTPS),

// We can only support http/https
Scheme::Other(_) => return Err(types::ErrorCode::HttpProtocolError.into()),
};

let authority = if let Some(authority) = req.authority {
if authority.find(':').is_some() {
authority
} else {
format!("{}:{port}", authority)
}
} else {
String::new()
};
let authority = req.authority.unwrap_or_else(String::new);

builder = builder.header(hyper::header::HOST, &authority);

let mut uri = http::Uri::builder()
Expand Down
3 changes: 1 addition & 2 deletions crates/wasi-http/tests/all/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ impl WasiHttpView for Ctx {
) -> HttpResult<HostFutureIncomingResponse> {
if let Some(rejected_authority) = &self.rejected_authority {
let authority = request.uri().authority().map(ToString::to_string).unwrap();
let (auth, _port) = authority.split_once(':').unwrap();
if auth == rejected_authority {
if &authority == rejected_authority {
return Err(ErrorCode::HttpRequestDenied.into());
}
}
Expand Down

0 comments on commit 89af353

Please sign in to comment.