Skip to content

Commit

Permalink
Merge pull request fermyon#2006 from itowlson/fix-disallowed-host-error
Browse files Browse the repository at this point in the history
Fix misleading guidance on disallowed host
  • Loading branch information
itowlson authored Nov 1, 2023
2 parents 7a9c384 + 1f497c6 commit ee5b781
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions crates/trigger-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ee5b781

Please sign in to comment.