Skip to content
Merged
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
28 changes: 14 additions & 14 deletions crates/http-service/src/executor/wasi_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,27 @@ where
let (sender, receiver) = tokio::sync::oneshot::channel();
let (mut parts, body) = req.into_parts();

const LOCALHOST: SmolStr = SmolStr::new_inline("localhost");

let backend_hostname = self
.backend
.hostname()
.context("backend hostname must be set")?;
let backend_host_header = backend_hostname.parse().context("invalid hostname")?;
Comment thread
ruslanti marked this conversation as resolved.
// Resolve backend hostname using the following precedence:
// 1. `server_name` request header (if set and valid UTF-8)
// 2. backend's configured hostname
// 3. fallback to "localhost"
let backend_hostname: SmolStr = parts
let hostname: SmolStr = parts
.headers
.get(SERVER_NAME_HEADER)
.and_then(|v| v.to_str().ok())
.map(SmolStr::from)
.or_else(|| self.backend.hostname())
.unwrap_or(LOCALHOST);

let hostname = match backend_hostname.find('.') {
None => backend_hostname.as_str(),
Some(i) => {
let (_, domain) = backend_hostname.split_at(i + 1);
domain
}
};
.unwrap_or_else(|| match backend_hostname.find('.') {
None => backend_hostname,
Some(i) => {
let (_, domain) = backend_hostname.split_at(i + 1);
SmolStr::from(domain)
}
});

// fix relative uri to absolute
if parts.uri.scheme().is_none() {
Expand Down Expand Up @@ -108,7 +108,7 @@ where
})
.collect();

propagate_headers.insert(header::HOST, backend_hostname.parse()?);
propagate_headers.insert(header::HOST, backend_host_header);
Comment thread
ruslanti marked this conversation as resolved.

let backend_uri = http_backend.uri();
let state = HttpState {
Expand Down
4 changes: 1 addition & 3 deletions crates/http-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ pub use crate::executor::ExecutorFactory;
use crate::executor::HttpExecutor;
use anyhow::{Context, Error, Result, bail};
use bytes::Bytes;
use http::{
HeaderMap, HeaderName, HeaderValue, StatusCode,
};
use http::{HeaderMap, HeaderName, HeaderValue, StatusCode};
use http_backend::SERVER_NAME_HEADER;
use http_body_util::{BodyExt, Empty, Full};
use hyper::{body::Body, server::conn::http1, service::service_fn};
Expand Down
Loading