From 1f497c682df9f4716f52282167f2087cbbee9c03 Mon Sep 17 00:00:00 2001 From: itowlson Date: Wed, 1 Nov 2023 13:26:38 +1300 Subject: [PATCH] Fix misleading guidance on disallowed host Signed-off-by: itowlson --- crates/trigger-http/src/lib.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/trigger-http/src/lib.rs b/crates/trigger-http/src/lib.rs index dc2322c96..37d53b667 100644 --- a/crates/trigger-http/src/lib.rs +++ b/crates/trigger-http/src/lib.rs @@ -507,14 +507,20 @@ impl OutboundWasiHttpHandler for HttpRuntimeData { let host = if unallowed_absolute { // Safe to unwrap because absolute urls have a host by definition. let host = uri.authority().map(|a| a.host()).unwrap(); - let port = uri - .scheme() - .and_then(|s| (s == &Scheme::HTTP).then_some(80)) - .unwrap_or(443); + let port = uri.authority().map(|a| a.port()).unwrap(); + let port = match port { + Some(port_str) => port_str.to_string(), + None => uri + .scheme() + .and_then(|s| (s == &Scheme::HTTP).then_some(80)) + .unwrap_or(443) + .to_string(), + }; terminal::warn!( "A component tried to make a HTTP request to non-allowed host '{host}'." ); - format!("https://{host}:{port}") + let scheme = uri.scheme().unwrap_or(&Scheme::HTTPS); + format!("{scheme}://{host}:{port}") } else { terminal::warn!("A component tried to make a HTTP request to the same component but it does not have permission."); "self".into()