web_server.rs: Log X-Forwarded-For IP #504
No reviewers
Labels
No labels
action
check-aws
action
discussion-needed
action
for-external-contributors
action
for-newcomers
action
more-info-needed
action
need-funding
action
triage-required
kind
correctness
kind
ideas
kind
improvement
kind
performance
kind
testing
kind
usability
kind
wrong-behavior
prio
critical
prio
low
scope
admin-api
scope
background-healing
scope
build
scope
documentation
scope
k8s
scope
layout
scope
metadata
scope
ops
scope
rpc
scope
s3-api
scope
security
scope
telemetry
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: Deuxfleurs/garage#504
Loading…
Reference in a 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!