From cb9214f713cf04e5c5a60e0723ab64845a2d42f0 Mon Sep 17 00:00:00 2001 From: Nicholas Barbier Date: Mon, 17 Nov 2025 08:53:30 -0500 Subject: [PATCH] Add host() method to RequestHeader --- pingora-http/src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pingora-http/src/lib.rs b/pingora-http/src/lib.rs index ce081027..18809dff 100644 --- a/pingora-http/src/lib.rs +++ b/pingora-http/src/lib.rs @@ -323,6 +323,17 @@ impl RequestHeader { self.base.version = version; } + /// Return the host from the request. + /// + /// Checks (in order): `:authority` pseudo-header (HTTP/2), `Host` header (HTTP/1), URI host. + pub fn host(&self) -> Option<&str> { + self.headers + .get(":authority") + .or_else(|| self.headers.get(http::header::HOST)) + .and_then(|v| v.to_str().ok()) + .or_else(|| self.uri.host()) + } + /// Clone `self` into [http::request::Parts]. pub fn as_owned_parts(&self) -> ReqParts { clone_req_parts(&self.base)