Skip to content

Commit

Permalink
use consts for headers
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgb committed Sep 24, 2024
1 parent 7acd030 commit d0cf860
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions dynamic-proxy/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ use std::{
use tokio::{net::TcpListener, select, task::JoinSet};
use tokio_rustls::TlsAcceptor;

/// Header which passes the client's IP address to the backend.
const X_FORWARDED_FOR: &str = "x-forwarded-for";

/// Header which passes the client's protocol (http or https) to the backend.
const X_FORWARDED_PROTO: &str = "x-forwarded-proto";

/// A simple server that wraps a hyper service and handles requests.
/// The server can be configured to listen for either HTTP and HTTPS,
/// and supports graceful shutdown and x-forwarded-* headers.
Expand Down Expand Up @@ -330,12 +336,12 @@ where
fn call(&self, request: Request<ReqBody>) -> Self::Future {
let mut request = request;
request.headers_mut().insert(
"X-Forwarded-For",
X_FORWARDED_FOR,
HeaderValue::from_str(&format!("{}", self.forwarded_for))
.expect("X-Forwarded-For is always valid"),
);
request.headers_mut().insert(
"X-Forwarded-Proto",
X_FORWARDED_PROTO,
HeaderValue::from_str(self.forwarded_proto).expect("X-Forwarded-Proto is always valid"),
);
self.inner.call(request)
Expand Down

0 comments on commit d0cf860

Please sign in to comment.