feat(homeserver): add Server header with version number

This commit is contained in:
nazeh
2025-02-13 18:54:48 +03:00
parent 91d834f9d8
commit 6b92c39af0
2 changed files with 21 additions and 3 deletions

View File

@@ -1,9 +1,15 @@
//! The controller part of the [crate::HomeserverCore]
use axum::{
body::Body,
extract::Request,
http::{header, HeaderValue},
middleware::{self, Next},
response::Response,
routing::{get, post},
Router,
};
use tower::ServiceBuilder;
use tower_cookies::CookieManagerLayer;
use tower_http::cors::CorsLayer;
@@ -16,6 +22,7 @@ mod feed;
mod root;
mod tenants;
static HOMESERVER_VERSION: &str = concat!("pubky.org", "@", env!("CARGO_PKG_VERSION"),);
const TRACING_EXCLUDED_PATHS: [&str; 1] = ["/events/"];
fn base() -> Router<AppState> {
@@ -35,7 +42,20 @@ pub fn create_app(state: AppState) -> Router {
.merge(tenants::router(state.clone()))
.layer(CookieManagerLayer::new())
.layer(CorsLayer::very_permissive())
.layer(ServiceBuilder::new().layer(middleware::from_fn(add_server_header)))
.with_state(state);
with_trace_layer(app, &TRACING_EXCLUDED_PATHS).layer(PubkyHostLayer)
}
// Middleware to add a `Server` header to all responses
async fn add_server_header(request: Request<Body>, next: Next) -> Response {
let mut response = next.run(request).await;
// Add a custom header to the response
response
.headers_mut()
.insert(header::SERVER, HeaderValue::from_static(HOMESERVER_VERSION));
response
}

View File

@@ -45,9 +45,7 @@ impl ClientBuilder {
self.pkarr
.bootstrap(&[format!(
"localhost:{}",
// TODO: update constants
// pubky_common::constants::testnet_ports::BOOTSTRAP
6881
pubky_common::constants::testnet_ports::BOOTSTRAP
)])
.relays(&[format!(
"http://localhost:{}",