Extract into const
This commit is contained in:
parent
8e237ea234
commit
c7dfac83d6
3 changed files with 18 additions and 12 deletions
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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()))?,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue