Skip to content

Commit b044239

Browse files
steebchenclaude
andcommitted
refactor: always return X-Torii-Host header without flag
Hostname is resolved once at startup and added to every response. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3b6cd97 commit b044239

3 files changed

Lines changed: 8 additions & 23 deletions

File tree

crates/cli/src/options.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,6 @@ pub struct ServerOptions {
361361
help = "Use mkcert to automatically generate and install local development certificates for HTTPS. This will create certificates for localhost and 127.0.0.1."
362362
)]
363363
pub mkcert: bool,
364-
365-
/// Add X-Torii-Host response header with hostname
366-
#[arg(
367-
long = "http.hostname_header",
368-
help = "When set, adds X-Torii-Host response header with the system hostname to every response."
369-
)]
370-
pub hostname_header: bool,
371364
}
372365

373366
impl Default for ServerOptions {
@@ -380,7 +373,6 @@ impl Default for ServerOptions {
380373
tls_cert_path: None,
381374
tls_key_path: None,
382375
mkcert: false,
383-
hostname_header: false,
384376
}
385377
}
386378
}

crates/runner/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,6 @@ impl Runner {
767767
http2_keepalive_interval: self.args.grpc.http2_keepalive_interval,
768768
http2_keepalive_timeout: self.args.grpc.http2_keepalive_timeout,
769769
},
770-
self.args.server.hostname_header,
771770
);
772771

773772
// Handle mkcert certificate generation

crates/server/src/proxy.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ impl<P: Provider + Sync + Send + Debug + 'static> Proxy<P> {
173173
provider: P,
174174
version_spec: String,
175175
proxy_settings: ProxySettings,
176-
hostname_header_enabled: bool,
177176
) -> Self {
178177
// Create proxy clients with configured settings
179178
let grpc_proxy_client = Arc::new(create_grpc_proxy_client(&proxy_settings));
@@ -194,12 +193,8 @@ impl<P: Provider + Sync + Send + Debug + 'static> Proxy<P> {
194193

195194
let handlers: Arc<RwLock<Vec<Box<dyn Handler>>>> = Arc::new(RwLock::new(handlers));
196195

197-
// Get hostname if the flag is enabled
198-
let hostname = if hostname_header_enabled {
199-
hostname::get().ok().and_then(|h| h.into_string().ok())
200-
} else {
201-
None
202-
};
196+
// Get hostname once at startup
197+
let hostname = hostname::get().ok().and_then(|h| h.into_string().ok());
203198

204199
Self {
205200
addr,
@@ -450,14 +445,13 @@ async fn handle(
450445
.unwrap()
451446
});
452447

453-
// Add hostname header if configured
448+
// Add hostname header
454449
if let Some(hostname_value) = hostname {
455-
response.headers_mut().insert(
456-
HeaderName::from_static("x-torii-host"),
457-
hostname_value
458-
.parse()
459-
.unwrap_or_else(|_| http::HeaderValue::from_static("unknown")),
460-
);
450+
if let Ok(header_value) = hostname_value.parse() {
451+
response
452+
.headers_mut()
453+
.insert(HeaderName::from_static("x-torii-host"), header_value);
454+
}
461455
}
462456

463457
Ok(response)

0 commit comments

Comments
 (0)