Skip to content

Commit

Permalink
Fixups and tidying
Browse files Browse the repository at this point in the history
Signed-off-by: itowlson <[email protected]>
  • Loading branch information
itowlson committed Mar 18, 2024
1 parent 2f239de commit b2a6b4d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
8 changes: 6 additions & 2 deletions crates/loader/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use tokio::sync::Semaphore;

use crate::{cache::Cache, FilesMountStrategy};

const SERVICE_CHAINING_DOMAIN_SUFFIX: &str = ".spin.internal";

#[derive(Debug)]
pub struct LocalLoader {
app_root: PathBuf,
Expand Down Expand Up @@ -559,8 +561,10 @@ fn is_chaining_host(pattern: &str) -> bool {
};

match allowed.host() {
HostConfig::List(hosts) => hosts.iter().any(|h| h.ends_with(".spin.internal")),
HostConfig::AnySubdomain(domain) => domain == ".spin.internal",
HostConfig::List(hosts) => hosts
.iter()
.any(|h| h.ends_with(SERVICE_CHAINING_DOMAIN_SUFFIX)),
HostConfig::AnySubdomain(domain) => domain == SERVICE_CHAINING_DOMAIN_SUFFIX,
_ => false,
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/locked-app/src/locked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ pub struct LockedApp {
#[serde(
default,
skip_serializing_if = "ValuesMap::is_empty",
deserialize_with = "i_cant_even"
deserialize_with = "deserialize_host_requirements"
)]
pub host_requirements: ValuesMap,
/// Custom config variables
#[serde(default, skip_serializing_if = "Vec::is_empty")]
#[serde(default, skip_serializing_if = "LockedMap::is_empty")]
pub variables: LockedMap<Variable>,
/// Application triggers
pub triggers: Vec<LockedTrigger>,
/// Application components
pub components: Vec<LockedComponent>,
}

fn i_cant_even<'de, D>(deserializer: D) -> Result<ValuesMap, D::Error>
fn deserialize_host_requirements<'de, D>(deserializer: D) -> Result<ValuesMap, D::Error>
where
D: serde::Deserializer<'de>,
{
Expand Down
9 changes: 6 additions & 3 deletions crates/trigger-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub use tls::TlsConfig;
pub(crate) type RuntimeData = HttpRuntimeData;
pub(crate) type Store = spin_core::Store<RuntimeData>;

const SERVICE_CHAINING_DOMAIN: &str = "spin.internal";
const SERVICE_CHAINING_DOMAIN_SUFFIX: &str = ".spin.internal";

/// The Spin HTTP trigger.
pub struct HttpTrigger {
engine: Arc<TriggerAppEngine<Self>>,
Expand Down Expand Up @@ -392,7 +395,7 @@ fn strip_forbidden_headers(req: &mut Request<Body>) {
if let Some(host_header) = headers.get("Host") {
if let Ok(host) = host_header.to_str() {
let (host, _) = host.rsplit_once(':').unwrap_or((host, ""));
if host.ends_with(".spin.internal") {
if host.ends_with(SERVICE_CHAINING_DOMAIN_SUFFIX) {
headers.remove("Host");
}
}
Expand Down Expand Up @@ -488,7 +491,7 @@ impl HttpRuntimeData {
use wasmtime_wasi_http::types::HostFutureIncomingResponse;
use wasmtime_wasi_http::types::IncomingResponseInternal;

let this = data.as_mut();
let this = data.as_ref();

let engine = this.engine.clone().ok_or(wasmtime::Error::msg(
"Internal error: internal request chaining not prepared (engine not assigned)",
Expand Down Expand Up @@ -531,7 +534,7 @@ fn parse_chaining_target(request: &wasmtime_wasi_http::types::OutgoingRequest) -

let (first, rest) = host.split_once('.')?;

if rest == "spin.internal" {
if rest == SERVICE_CHAINING_DOMAIN {
Some(first.to_owned())
} else {
None
Expand Down

0 comments on commit b2a6b4d

Please sign in to comment.