fix(websocket): retain WsPumps handle on the server path (WS-08)
This commit is contained in:
+14
-2
@@ -25,14 +25,25 @@ pub enum DecoyConfig {
|
||||
|
||||
/// State embedded in the axum `Router`: the registry and identity
|
||||
/// provider every request handler reaches through the router state, plus
|
||||
/// the decoy config for the fallback and the pre-serialized
|
||||
/// `/openapi.json` projection cache (SRV-09).
|
||||
/// the decoy config for the fallback, the pre-serialized
|
||||
/// `/openapi.json` projection cache (SRV-09), and the shared WS session
|
||||
/// registry the WS upgrade retains pump handles in (WS-08).
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct RouterState {
|
||||
pub(crate) registry: Arc<OperationRegistry>,
|
||||
pub(crate) identity_provider: Arc<dyn IdentityProvider>,
|
||||
pub(crate) decoy: DecoyConfig,
|
||||
pub(crate) openapi_doc: crate::server::adapter::CachedOpenAPIDoc,
|
||||
pub(crate) ws_sessions: Arc<crate::websocket::WsSessions>,
|
||||
}
|
||||
|
||||
impl axum::extract::FromRef<RouterState> for crate::websocket::SessionState {
|
||||
fn from_ref(state: &RouterState) -> Self {
|
||||
crate::websocket::SessionState::new(
|
||||
Arc::clone(&state.registry),
|
||||
Arc::clone(&state.ws_sessions),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl axum::extract::FromRef<RouterState> for DecoyConfig {
|
||||
@@ -77,6 +88,7 @@ mod tests {
|
||||
to: "https://example.com".to_string(),
|
||||
},
|
||||
openapi_doc: crate::server::adapter::CachedOpenAPIDoc::new(&OperationRegistry::new()),
|
||||
ws_sessions: Arc::new(crate::websocket::WsSessions::new()),
|
||||
};
|
||||
let extracted: DecoyConfig = axum::extract::FromRef::from_ref(&state);
|
||||
assert!(matches!(extracted, DecoyConfig::Redirect { .. }));
|
||||
|
||||
Reference in New Issue
Block a user