diff --git a/src/server/core.rs b/src/server/core.rs index 9e403af..5dba2a7 100644 --- a/src/server/core.rs +++ b/src/server/core.rs @@ -1,8 +1,9 @@ +use super::compress; +use super::execute; +use super::judge; +use super::jwt; +use super::version; use crate::config::*; -use crate::server::compress; -use crate::server::execute; -use crate::server::judge; -use crate::server::jwt; use rocket::data::ByteUnit; use rocket::serde::{json::Json, Deserialize, Serialize}; use rocket::Build; @@ -51,6 +52,8 @@ pub fn rocket() -> Rocket { routes![index, info, jwt::validate, execute::execute, judge::judge], ); + let server = server.attach(version::fairing()); + if cfg!(debug_assertions) { server } else { diff --git a/src/server/execute.rs b/src/server/execute.rs index 01001c4..97c56f6 100644 --- a/src/server/execute.rs +++ b/src/server/execute.rs @@ -1,6 +1,6 @@ +use super::jwt; use crate::config::*; use crate::run; -use crate::server::jwt; use base64::{engine::general_purpose, Engine as _}; use rocket::serde::{ json::{Error, Json}, diff --git a/src/server/judge.rs b/src/server/judge.rs index 3ee84fa..246bfcf 100644 --- a/src/server/judge.rs +++ b/src/server/judge.rs @@ -1,6 +1,6 @@ +use super::jwt; use crate::judger::{Input, JudgeSpec, Judger, Output}; use crate::run; -use crate::server::jwt; use base64::engine::general_purpose; use base64::Engine; use reqwest::Client; diff --git a/src/server/mod.rs b/src/server/mod.rs index 84d8b1e..3800782 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -3,3 +3,4 @@ pub mod core; mod execute; mod judge; mod jwt; +mod version; diff --git a/src/server/version.rs b/src/server/version.rs new file mode 100644 index 0000000..6d664ed --- /dev/null +++ b/src/server/version.rs @@ -0,0 +1,13 @@ +use rocket::{fairing::AdHoc, http::Header}; + +pub fn fairing() -> AdHoc { + AdHoc::on_response("Version Headers", |_req, res| { + Box::pin(async move { + res.set_header(Header::new( + "X-Powered-By", + "WARK (https://github.com/wasm-oj/wark)", + )); + res.set_header(Header::new("X-Version", env!("VERGEN_GIT_DESCRIBE"))); + }) + }) +}