refactoring
This commit is contained in:
parent
692d287ee4
commit
fed9dd66b6
28
src/lib.rs
28
src/lib.rs
@ -67,19 +67,27 @@ fn create_proxied_request<B>(client_ip: IpAddr, forward_url: &str, mut request:
|
|||||||
*request.headers_mut() = remove_hop_headers(request.headers());
|
*request.headers_mut() = remove_hop_headers(request.headers());
|
||||||
*request.uri_mut() = forward_uri(forward_url, &request);
|
*request.uri_mut() = forward_uri(forward_url, &request);
|
||||||
|
|
||||||
|
let x_forwarded_for_header_name = "x-forwarded-for";
|
||||||
|
|
||||||
// Add forwarding information in the headers
|
// Add forwarding information in the headers
|
||||||
match request.headers_mut().entry("x-forwarded-for") {
|
match request.headers_mut().entry(x_forwarded_for_header_name) {
|
||||||
Ok(hyper::header::Entry::Vacant(entry)) => {
|
|
||||||
let addr = format!("{}", client_ip);
|
|
||||||
entry.insert(addr.parse().unwrap());
|
|
||||||
},
|
|
||||||
|
|
||||||
Ok(hyper::header::Entry::Occupied(mut entry)) => {
|
Ok(header_entry) => {
|
||||||
let addr = format!("{}, {}", entry.get().to_str().unwrap(), client_ip);
|
match header_entry {
|
||||||
entry.insert(addr.parse().unwrap());
|
hyper::header::Entry::Vacant(entry) => {
|
||||||
},
|
let addr = format!("{}", client_ip);
|
||||||
|
entry.insert(addr.parse().unwrap());
|
||||||
|
},
|
||||||
|
|
||||||
_ => (), // silently fails to add x-forwarded-for header
|
hyper::header::Entry::Occupied(mut entry) => {
|
||||||
|
let addr = format!("{}, {}", entry.get().to_str().unwrap(), client_ip);
|
||||||
|
entry.insert(addr.parse().unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// shouldn't happen...
|
||||||
|
Err(_) => panic!("Invalid header name: {}", x_forwarded_for_header_name),
|
||||||
}
|
}
|
||||||
|
|
||||||
request
|
request
|
||||||
|
Loading…
Reference in New Issue
Block a user