Skip to content

Commit

Permalink
Ensure X-Highway-Version is sent with 403
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Reidel <[email protected]>
  • Loading branch information
Gelbpunkt committed Dec 19, 2023
1 parent 1a44c62 commit 4b37bad
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,25 +808,26 @@ async fn http_handler(
let mut resp = match (req.method(), req.uri().path()) {
(&Method::GET, "/") => websocket_endpoint_handler(addr, req, global_state).await,
(&Method::GET, "/metrics") => {
if let Some(auth_required) = &global_state.config.metrics_token {
if let Some(auth) = req.headers().get(AUTHORIZATION) {
if auth != auth_required {
return Ok(Response::builder()
.status(StatusCode::FORBIDDEN)
.body(Full::default())
.unwrap());
}
} else {
return Ok(Response::builder()
.status(StatusCode::FORBIDDEN)
.body(Full::default())
.unwrap());
}
let authorized =
global_state
.config
.metrics_token
.as_ref()
.map_or(true, |expected_token| {
req.headers().get(AUTHORIZATION).map(|v| v.as_bytes())
== Some(expected_token.as_bytes())
});

if authorized {
Ok(Response::builder()
.body(Full::from(metrics_handle.render()))
.unwrap())
} else {
Ok(Response::builder()
.status(StatusCode::FORBIDDEN)
.body(Full::default())
.unwrap())
}

Ok(Response::builder()
.body(Full::from(metrics_handle.render()))
.unwrap())
}
_ => Ok(Response::builder()
.status(StatusCode::NOT_FOUND)
Expand Down

0 comments on commit 4b37bad

Please sign in to comment.