Skip to content
Open
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
11 changes: 11 additions & 0 deletions pingora-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions pingora-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,10 @@ where
self.inner.logging(&mut session, None, &mut ctx).await;
self.cleanup_sub_req(&mut session);
let persistent_settings = HttpPersistentSettings::for_session(&session);
return session
.downstream_session
.finish()
return self
.inner
.finish_downstream_session(session.downstream_session, &mut ctx)
.await
.ok()
.flatten()
.map(|s| ReusedHttpStream::new(s, Some(persistent_settings)));
}
/* else continue */
Expand Down
11 changes: 11 additions & 0 deletions pingora-proxy/src/proxy_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,17 @@ pub trait ProxyHttp {
) -> Result<()> {
Ok(())
}

/// Called when response_sent is true from request_filter, allowing custom handling of the downstream session.
///
/// Returns an optional Stream if the connection can be reused.
async fn finish_downstream_session(
&self,
downstream_session: Box<HttpSession>,
_ctx: &mut Self::CTX,
) -> Option<Stream> {
downstream_session.finish().await.ok().flatten()
}
}

/// Context struct returned by `fail_to_proxy`.
Expand Down