use Services instead of Server for middleware function state
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
1f88866612
commit
f632b06e6d
2 changed files with 8 additions and 5 deletions
|
@ -48,7 +48,7 @@ pub(crate) fn build(services: &Arc<Services>) -> Result<(Router, Guard)> {
|
|||
|
||||
let layers = layers
|
||||
.sensitive_headers([header::AUTHORIZATION])
|
||||
.layer(axum::middleware::from_fn_with_state(Arc::clone(server), request::spawn))
|
||||
.layer(axum::middleware::from_fn_with_state(Arc::clone(services), request::spawn))
|
||||
.layer(
|
||||
TraceLayer::new_for_http()
|
||||
.make_span_with(tracing_span::<_>)
|
||||
|
@ -56,7 +56,7 @@ pub(crate) fn build(services: &Arc<Services>) -> Result<(Router, Guard)> {
|
|||
.on_request(DefaultOnRequest::new().level(Level::TRACE))
|
||||
.on_response(DefaultOnResponse::new().level(Level::DEBUG)),
|
||||
)
|
||||
.layer(axum::middleware::from_fn_with_state(Arc::clone(server), request::handle))
|
||||
.layer(axum::middleware::from_fn_with_state(Arc::clone(services), request::handle))
|
||||
.layer(SecureClientIpSource::ConnectInfo.into_extension())
|
||||
.layer(SetResponseHeaderLayer::if_not_present(
|
||||
HeaderName::from_static("origin-agent-cluster"), // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin-Agent-Cluster
|
||||
|
|
|
@ -4,13 +4,15 @@ use axum::{
|
|||
extract::State,
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use conduit::{debug, debug_error, debug_warn, defer, err, error, trace, Result, Server};
|
||||
use conduit::{debug, debug_error, debug_warn, defer, err, error, trace, Result};
|
||||
use conduit_service::Services;
|
||||
use http::{Method, StatusCode, Uri};
|
||||
|
||||
#[tracing::instrument(skip_all, level = "debug")]
|
||||
pub(crate) async fn spawn(
|
||||
State(server): State<Arc<Server>>, req: http::Request<axum::body::Body>, next: axum::middleware::Next,
|
||||
State(services): State<Arc<Services>>, req: http::Request<axum::body::Body>, next: axum::middleware::Next,
|
||||
) -> Result<Response, StatusCode> {
|
||||
let server = &services.server;
|
||||
if !server.running() {
|
||||
debug_warn!("unavailable pending shutdown");
|
||||
return Err(StatusCode::SERVICE_UNAVAILABLE);
|
||||
|
@ -34,8 +36,9 @@ pub(crate) async fn spawn(
|
|||
|
||||
#[tracing::instrument(skip_all, name = "handle")]
|
||||
pub(crate) async fn handle(
|
||||
State(server): State<Arc<Server>>, req: http::Request<axum::body::Body>, next: axum::middleware::Next,
|
||||
State(services): State<Arc<Services>>, req: http::Request<axum::body::Body>, next: axum::middleware::Next,
|
||||
) -> Result<Response, StatusCode> {
|
||||
let server = &services.server;
|
||||
if !server.running() {
|
||||
debug_warn!(
|
||||
method = %req.method(),
|
||||
|
|
Loading…
Add table
Reference in a new issue