Skip to content

Commit

Permalink
Fixed remote addr (on Caddy reverse proxy) problem
Browse files Browse the repository at this point in the history
  • Loading branch information
jonirrings committed Dec 29, 2024
1 parent 87a43ff commit b720f8c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
18 changes: 17 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ log = "0.4.22"
indicatif = "0.17.9"
#assets
include_dir = "0.7.4"
case_insensitive_hashmap = "1.0.1"

[package.metadata.deb]
maintainer-scripts = "setup/debian/scripts/"
Expand Down
11 changes: 6 additions & 5 deletions src/http/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::future::Future;
use std::pin::Pin;
use log::trace;
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, BufWriter};
use case_insensitive_hashmap::CaseInsensitiveHashMap as CIHashMap;
use crate::config::GARBAGE_DATA;
use crate::http::{Method, MethodStr};
use crate::http::response::Response;
Expand All @@ -13,7 +14,7 @@ pub struct Request {
pub method: Method,
pub remote_addr : String,
pub query_params: HashMap<String, String>,
pub headers: HashMap<String, String>,
pub headers: CIHashMap<String>,
pub form_data : HashMap<String, String>
}

Expand Down Expand Up @@ -189,11 +190,11 @@ fn hex_string_to_int(hex_string: &str) -> Option<u64> {
}
}

pub async fn header_parser<R>(buf_reader: &mut BufReader<R>) -> HashMap<String,String>
pub async fn header_parser<R>(buf_reader: &mut BufReader<R>) -> CIHashMap<String>
where
R: AsyncReadExt + Unpin
{
let mut headers_out = HashMap::new();
let mut headers_out = CIHashMap::new();
'header_loop:loop {
if let Ok(Some(header_line)) = buf_reader.lines().next_line().await {
if header_line.is_empty() {
Expand All @@ -211,7 +212,7 @@ where
headers_out
}

fn check_has_body(headers : &HashMap<String,String>) -> (Option<BodyType>,Option<u64>) {
fn check_has_body(headers : &CIHashMap<String>) -> (Option<BodyType>,Option<u64>) {
let content_type_form = if let Some(content_type) = headers.get("Content-Type") {
if content_type.starts_with("multipart/form-data;") {
Some(BodyType::Form)
Expand Down Expand Up @@ -279,7 +280,7 @@ fn clear_path_end_slash(input: &str) -> &str {
}
}

fn trust_addr_proxy(headers : &HashMap<String,String>,remote_addr : &str) -> String {
fn trust_addr_proxy(headers : &CIHashMap<String>,remote_addr : &str) -> String {
if let Some(remote_ip) = headers.get("X-Real-IP") {
remote_ip.to_string()
} else {
Expand Down

0 comments on commit b720f8c

Please sign in to comment.