Skip to content

Commit df62215

Browse files
authored
Merge pull request #16 from jonirrings/patch-1
Fixed remote addr (on Caddy reverse proxy) problem
2 parents 87a43ff + b720f8c commit df62215

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

Cargo.lock

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ log = "0.4.22"
3939
indicatif = "0.17.9"
4040
#assets
4141
include_dir = "0.7.4"
42+
case_insensitive_hashmap = "1.0.1"
4243

4344
[package.metadata.deb]
4445
maintainer-scripts = "setup/debian/scripts/"

src/http/request.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::future::Future;
33
use std::pin::Pin;
44
use log::trace;
55
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, BufWriter};
6+
use case_insensitive_hashmap::CaseInsensitiveHashMap as CIHashMap;
67
use crate::config::GARBAGE_DATA;
78
use crate::http::{Method, MethodStr};
89
use crate::http::response::Response;
@@ -13,7 +14,7 @@ pub struct Request {
1314
pub method: Method,
1415
pub remote_addr : String,
1516
pub query_params: HashMap<String, String>,
16-
pub headers: HashMap<String, String>,
17+
pub headers: CIHashMap<String>,
1718
pub form_data : HashMap<String, String>
1819
}
1920

@@ -189,11 +190,11 @@ fn hex_string_to_int(hex_string: &str) -> Option<u64> {
189190
}
190191
}
191192

192-
pub async fn header_parser<R>(buf_reader: &mut BufReader<R>) -> HashMap<String,String>
193+
pub async fn header_parser<R>(buf_reader: &mut BufReader<R>) -> CIHashMap<String>
193194
where
194195
R: AsyncReadExt + Unpin
195196
{
196-
let mut headers_out = HashMap::new();
197+
let mut headers_out = CIHashMap::new();
197198
'header_loop:loop {
198199
if let Ok(Some(header_line)) = buf_reader.lines().next_line().await {
199200
if header_line.is_empty() {
@@ -211,7 +212,7 @@ where
211212
headers_out
212213
}
213214

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

282-
fn trust_addr_proxy(headers : &HashMap<String,String>,remote_addr : &str) -> String {
283+
fn trust_addr_proxy(headers : &CIHashMap<String>,remote_addr : &str) -> String {
283284
if let Some(remote_ip) = headers.get("X-Real-IP") {
284285
remote_ip.to_string()
285286
} else {

0 commit comments

Comments
 (0)