Skip to content

Commit

Permalink
add API version in HTTP headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ghubertpalo committed Nov 14, 2022
1 parent 9714e2c commit 1f7973f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions mithril-aggregator/src/http_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ mod routes;
mod server;

pub use server::{Server, SERVER_BASE_PATH};

pub const MITHRIL_API_VERSION: &str = "0.1.0";
11 changes: 9 additions & 2 deletions mithril-aggregator/src/http_server/routes/router.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::http_server::routes::{
certificate_routes, epoch_routes, signatures_routes, signer_routes, snapshot_routes,
};
use crate::http_server::SERVER_BASE_PATH;
use crate::http_server::{MITHRIL_API_VERSION, SERVER_BASE_PATH};
use crate::DependencyManager;
use reqwest::header::{HeaderMap, HeaderValue};
use std::sync::Arc;
use warp::http::Method;
use warp::Filter;
Expand All @@ -15,13 +16,19 @@ pub fn routes(
.allow_any_origin()
.allow_headers(vec!["content-type"])
.allow_methods(vec![Method::GET, Method::POST, Method::OPTIONS]);
let mut headers = HeaderMap::new();
headers.insert(
"mithril-api-version",
HeaderValue::from_static(MITHRIL_API_VERSION),
);

warp::any().and(warp::path(SERVER_BASE_PATH)).and(
certificate_routes::routes(dependency_manager.clone())
.or(snapshot_routes::routes(dependency_manager.clone()))
.or(signer_routes::routes(dependency_manager.clone()))
.or(signatures_routes::routes(dependency_manager.clone()))
.or(epoch_routes::routes(dependency_manager))
.with(cors),
.with(cors)
.with(warp::reply::with::headers(headers)),
)
}

0 comments on commit 1f7973f

Please sign in to comment.