C: C3 x-slinuxm-peer response header on every proxied outcome
This commit is contained in:
1 parent
bab6959a94
commit
58012018d9
4 files changed
+34
-8
No files matched your search
+20
-5
@@ -8,7 +8,7 @@ use std::time::Duration;
|
||||
|
||||
use axum::body::Body;
|
||||
use axum::extract::{Path, Request, State};
|
||||
use axum::http::{header, HeaderValue, StatusCode};
|
||||
use axum::http::{header, HeaderName, HeaderValue, StatusCode};
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum::routing::get;
|
||||
use axum::{Json, Router};
|
||||
@@ -57,16 +57,31 @@ async fn pass(
|
||||
Path((peer, _path)): Path<(String, String)>,
|
||||
request: Request,
|
||||
) -> Response {
|
||||
with_peer_header(&peer, pass_through(&st, &peer, request).await)
|
||||
}
|
||||
|
||||
/// Every outcome for a proxy call names the peer, including consolidator-side
|
||||
/// errors (bad path, dead peer), so a client can tell which peer failed.
|
||||
fn with_peer_header(peer: &str, mut response: Response) -> Response {
|
||||
if let Ok(value) = HeaderValue::from_str(peer) {
|
||||
response
|
||||
.headers_mut()
|
||||
.insert(HeaderName::from_static(proxy::PEER_HEADER), value);
|
||||
}
|
||||
response
|
||||
}
|
||||
|
||||
async fn pass_through(st: &AppState, peer: &str, request: Request) -> Response {
|
||||
let Some(reg) = st.peers.clone() else {
|
||||
return AppError::NotFound("no such route".into()).into_response();
|
||||
};
|
||||
if let Err(err) = proxy::reject_inbound_hop(&peer, request.headers()) {
|
||||
if let Err(err) = proxy::reject_inbound_hop(peer, request.headers()) {
|
||||
return err.into_response();
|
||||
}
|
||||
let Some(raw_path) = raw_peer_path(request.uri().path()) else {
|
||||
return AppError::BadRequest(format!("peer {peer}: path not allowed")).into_response();
|
||||
};
|
||||
let query = match proxy::query_from_raw(&peer, request.uri().query()) {
|
||||
let query = match proxy::query_from_raw(peer, request.uri().query()) {
|
||||
Ok(query) => query,
|
||||
Err(err) => return err.into_response(),
|
||||
};
|
||||
@@ -74,8 +89,8 @@ async fn pass(
|
||||
traceparent: inbound_traceparent(request.headers()),
|
||||
accept_sse: accepts_event_stream(request.headers()),
|
||||
};
|
||||
match reg.get(&peer, raw_path, &query, opts).await {
|
||||
Ok(resp) => proxy_response(&st, &peer, resp),
|
||||
match reg.get(peer, raw_path, &query, opts).await {
|
||||
Ok(resp) => proxy_response(st, peer, resp),
|
||||
Err(err) => err.into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user