From 007ab9efbfd273bdd74109bfe14e2be11b3e08b0 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 9 Feb 2022 13:55:21 +0000 Subject: [PATCH] Improve web header performance --- src/cnf/mod.rs | 12 ++++++++++-- src/web/head.rs | 23 +++++++++++++++-------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/cnf/mod.rs b/src/cnf/mod.rs index fd149fac..8ee000ac 100644 --- a/src/cnf/mod.rs +++ b/src/cnf/mod.rs @@ -1,4 +1,12 @@ +// The name and version of this build +pub const PKG_NAME: &'static str = env!("CARGO_PKG_NAME"); +pub const PKG_VERS: &'static str = env!("CARGO_PKG_VERSION"); + +// The publicly visible name of the server +pub const SERVER_NAME: &'static str = "SurrealDB"; + +// The public endpoint for the database administration interface +pub const APP_ENDPOINT: &'static str = "https://app.surrealdb.com"; + // Specifies how many subqueries will be processed recursively before the query fails. pub const MAX_RECURSIVE_QUERIES: usize = 16; - -pub const APP_ENDPOINT: &'static str = "https://app.surrealdb.com"; diff --git a/src/web/head.rs b/src/web/head.rs index 076bfa3f..f57d51f8 100644 --- a/src/web/head.rs +++ b/src/web/head.rs @@ -1,13 +1,20 @@ -const NAME: &'static str = env!("CARGO_PKG_NAME"); -const VERS: &'static str = env!("CARGO_PKG_VERSION"); +use crate::cnf::PKG_NAME; +use crate::cnf::PKG_VERS; +use crate::cnf::SERVER_NAME; + +const ID: &'static str = "ID"; +const NS: &'static str = "NS"; +const DB: &'static str = "DB"; +const SERVER: &'static str = "Server"; +const VERSION: &'static str = "Version"; pub fn version() -> warp::filters::reply::WithHeader { - let val = format!("{}-{}", NAME, VERS); - warp::reply::with::header("Version", val) + let val = format!("{}-{}", PKG_NAME, PKG_VERS); + warp::reply::with::header(VERSION, val) } pub fn server() -> warp::filters::reply::WithHeader { - warp::reply::with::header("Server", "SurrealDB") + warp::reply::with::header(SERVER, SERVER_NAME) } pub fn cors() -> warp::filters::cors::Builder { @@ -27,8 +34,8 @@ pub fn cors() -> warp::filters::cors::Builder { http::header::AUTHORIZATION, http::header::CONTENT_TYPE, http::header::ORIGIN, - "NS".parse().unwrap(), - "DB".parse().unwrap(), - "ID".parse().unwrap(), + NS.parse().unwrap(), + DB.parse().unwrap(), + ID.parse().unwrap(), ]) }