Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@ use axum::extract::rejection::PathRejection;
use axum::extract::{FromRequestParts, Path};
use axum::http::request::Parts;
use axum::response::{IntoResponse, Response};
use serde::Deserialize;

use crate::http::axum_implementation::handlers::auth::{self, KeyParam};
use crate::http::axum_implementation::handlers::common::auth;
use crate::http::axum_implementation::responses;
use crate::tracker::auth::Key;

pub struct Extract(pub Key);

#[derive(Deserialize)]
pub struct KeyParam(String);

impl KeyParam {
#[must_use]
pub fn value(&self) -> String {
self.0.clone()
}
}

#[async_trait]
impl<S> FromRequestParts<S> for Extract
where
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
//! Wrapper for two Axum extractors to get the relevant information
//! to resolve the remote client IP.
use std::net::{IpAddr, SocketAddr};
use std::net::SocketAddr;

use axum::async_trait;
use axum::extract::{ConnectInfo, FromRequestParts};
use axum::http::request::Parts;
use axum::response::Response;
use axum_client_ip::RightmostXForwardedFor;
use serde::{Deserialize, Serialize};

/// Given this request chain:
///
/// client <-> http proxy 1 <-> http proxy 2 <-> server
/// ip: 126.0.0.1 ip: 126.0.0.2 ip: 126.0.0.3 ip: 126.0.0.4
/// X-Forwarded-For: 126.0.0.1 X-Forwarded-For: 126.0.0.1,126.0.0.2
///
/// This extractor extracts these values from the HTTP headers and connection info.
///
/// `right_most_x_forwarded_for` = 126.0.0.2
/// `connection_info_ip` = 126.0.0.3
///
/// More info about inner extractors: <https://github.com/imbolc/axum-client-ip>
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct RemoteClientIp {
pub right_most_x_forwarded_for: Option<IpAddr>,
pub connection_info_ip: Option<IpAddr>,
}
use crate::http::axum_implementation::services::peer_ip_resolver::ClientIpSources;

pub struct Extract(pub ClientIpSources);

#[async_trait]
impl<S> FromRequestParts<S> for RemoteClientIp
impl<S> FromRequestParts<S> for Extract
where
S: Send + Sync,
{
Expand All @@ -45,9 +30,9 @@ where
Err(_) => None,
};

Ok(RemoteClientIp {
Ok(Extract(ClientIpSources {
right_most_x_forwarded_for,
connection_info_ip,
})
}))
}
}
4 changes: 2 additions & 2 deletions src/http/axum_implementation/extractors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod announce_request;
pub mod key;
pub mod remote_client_ip;
pub mod authentication_key;
pub mod client_ip_sources;
pub mod scrape_request;
Loading