From c7dfac83d6306b006a2bbb73974d5debbdb04676 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 27 Sep 2026 21:36:38 +0100 Subject: [PATCH] Extract into const --- sync-server/src/consts.rs | 5 +++++ sync-server/src/server.rs | 13 +++++++------ sync-server/src/server/history.rs | 12 ++++++------ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/sync-server/src/consts.rs b/sync-server/src/consts.rs index 341fd9eb..a797309c 100644 --- a/sync-server/src/consts.rs +++ b/sync-server/src/consts.rs @@ -27,3 +27,8 @@ pub const DEFAULT_EVENTS_PAGE_SIZE: usize = 64; pub const MAX_EVENTS_PAGE_BYTES: usize = 1024 * 1024; pub const SUPPORTED_API_VERSION: u32 = 4; + +pub const HISTORY_HEADER: axum::http::HeaderName = + axum::http::HeaderName::from_static("x-vault-link-history"); +pub const HISTORY_MISMATCH_HEADER: axum::http::HeaderName = + axum::http::HeaderName::from_static("x-vault-link-history-mismatch"); diff --git a/sync-server/src/server.rs b/sync-server/src/server.rs index 0cfa87ef..ce41fffb 100644 --- a/sync-server/src/server.rs +++ b/sync-server/src/server.rs @@ -1,3 +1,4 @@ +use crate::consts::{HISTORY_HEADER, HISTORY_MISMATCH_HEADER}; pub mod auth; mod device_id_header; mod endpoints; @@ -48,7 +49,10 @@ pub async fn create_server(config: Config) -> Result<()> { let app = Router::new() .nest("/", create_authenticated_routes(app_state.clone())) .route("/", get(endpoints::index::index)) - .route("/vaults/:vault_id/ping", get(endpoints::ping::ping)) + .route( + "/vaults/:vault_id/config", + get(endpoints::get_server_config::get_server_config), + ) .route( "/vaults/:vault_id/ws", get(endpoints::websocket::websocket_handler), @@ -65,12 +69,9 @@ pub async fn create_server(config: Config) -> Result<()> { http::header::CONTENT_TYPE, http::header::AUTHORIZATION, DEVICE_ID_HEADER_NAME.clone(), - http::header::HeaderName::from_static("x-vault-link-history"), - ]) - .expose_headers([ - http::header::HeaderName::from_static("x-vault-link-history"), - http::header::HeaderName::from_static("x-vault-link-history-mismatch"), + HISTORY_HEADER, ]) + .expose_headers([HISTORY_HEADER, HISTORY_MISMATCH_HEADER]) .allow_methods([Method::GET, Method::PUT]), ) .layer( diff --git a/sync-server/src/server/history.rs b/sync-server/src/server/history.rs index 2f851c8f..2a14aaca 100644 --- a/sync-server/src/server/history.rs +++ b/sync-server/src/server/history.rs @@ -1,3 +1,4 @@ +use crate::consts::{HISTORY_HEADER, HISTORY_MISMATCH_HEADER}; use std::collections::HashMap; use axum::{ @@ -27,7 +28,7 @@ pub async fn history_middleware( // A restore happens while the server is stopped. Validate before executing // any old request, including retries whose numeric parent IDs were reused. - if let Some(checkpoint) = req.headers().get("x-vault-link-history") { + if let Some(checkpoint) = req.headers().get(HISTORY_HEADER) { let checkpoint = checkpoint .to_str() .map_err(|error| client_error(error.into()))?; @@ -38,10 +39,9 @@ pub async fn history_middleware( .map_err(server_error)? { let mut response = (StatusCode::CONFLICT, "Server history changed").into_response(); - response.headers_mut().insert( - "x-vault-link-history-mismatch", - HeaderValue::from_static("1"), - ); + response + .headers_mut() + .insert(HISTORY_MISMATCH_HEADER, HeaderValue::from_static("1")); return Ok(response); } } @@ -54,7 +54,7 @@ pub async fn history_middleware( .await .map_err(server_error)?; response.headers_mut().insert( - "x-vault-link-history", + HISTORY_HEADER, HeaderValue::from_str(&checkpoint).map_err(|error| server_error(error.into()))?, ); }