web_server.rs: Log X-Forwarded-For IP #504
No reviewers
Labels
No Label
AdminAPI
Bug
Check AWS
CI
Correctness
Critical
Documentation
Ideas
Improvement
Low priority
Newcomer
Performance
S3 Compatibility
Testing
Usability
No Milestone
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: Deuxfleurs/garage#504
Loading…
Reference in New Issue
No description provided.
Delete Branch "jpds/garage:web_server-log-x-forwarded-for"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
b8be8b6af4
toe840c9b5b8
Do you confirm this work is the continuation of #500 but for the web endpoint?
@quentin Indeed, it is.
Proposing some changes to make code more consise and better exploit Rust's type system
@ -135,2 +132,2 @@
.to_str()
.unwrap_or_default();
let forwarded_for_ip_addr =
forwarded_headers::handle_forwarded_for_headers(&req.headers());
With
handle_forwarded_for_headers
returning aResult
(see below), lines 130-133 should be rewritten as follows:@ -0,0 +1,42 @@
use http::{HeaderMap, HeaderValue};
pub fn handle_forwarded_for_headers(headers: &HeaderMap<HeaderValue>) -> String {
This function should return a
Result<String, Error>
, which isOk
if the value exists and passes all the checks, andErr
otherwise.@ -108,0 +108,4 @@
let has_forwarded_for_header = req.headers().contains_key("x-forwarded-for");
if has_forwarded_for_header {
let forwarded_for_ip_addr =
forwarded_headers::handle_forwarded_for_headers(&req.headers());
Same as above, lines 108-111 should be rewritten as:
e840c9b5b8
tob65af6df86
b65af6df86
tof65beea554
f65beea554
to401a737acf
401a737acf
to9f026396f6
9f026396f6
to872ffe68bd
@ -128,20 +129,17 @@ impl<A: ApiHandler> ApiServer<A> {
let has_forwarded_for_header = req.headers().contains_key("x-forwarded-for");
if has_forwarded_for_header {
You don't need lines 130-131, just use the second if (the
if let
statement) with the else branch of the first one.@ -106,2 +107,3 @@
) -> Result<Response<Body>, Infallible> {
info!("{} {} {}", addr, req.method(), req.uri());
let has_forwarded_for_header = req.headers().contains_key("x-forwarded-for");
if has_forwarded_for_header {
Same here
872ffe68bd
to4e0fc3d6c9
Thanks!