mirror of
https://codeberg.org/slatian/service.echoip-slatecave.git
synced 2025-07-16 22:13:30 +02:00
Update to axum 0.7
This commit is contained in:
17
src/main.rs
17
src/main.rs
@ -1,20 +1,21 @@
|
||||
use axum::{
|
||||
body::Body,
|
||||
extract::{
|
||||
self,
|
||||
Query,
|
||||
State,
|
||||
Extension,
|
||||
},
|
||||
headers,
|
||||
http::Request,
|
||||
handler::Handler,
|
||||
http::Request,
|
||||
middleware::{self, Next},
|
||||
response::Response,
|
||||
Router,
|
||||
routing::get,
|
||||
TypedHeader,
|
||||
};
|
||||
use axum_client_ip::SecureClientIp;
|
||||
use axum_extra::headers;
|
||||
use axum_extra::TypedHeader;
|
||||
use clap::Parser;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
@ -311,21 +312,21 @@ async fn main() {
|
||||
|
||||
println!("Starting Server on {} ...",listen_on);
|
||||
|
||||
axum::Server::bind(&listen_on)
|
||||
.serve(app.into_make_service_with_connect_info::<std::net::SocketAddr>())
|
||||
let listener = tokio::net::TcpListener::bind(&listen_on).await.unwrap();
|
||||
axum::serve(listener, app.into_make_service_with_connect_info::<std::net::SocketAddr>())
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
|
||||
async fn settings_query_middleware<B>(
|
||||
async fn settings_query_middleware(
|
||||
Query(query): Query<SettingsQuery>,
|
||||
Extension(config): Extension<config::EchoIpServiceConfig>,
|
||||
Extension(derived_config): Extension<DerivedConfiguration>,
|
||||
cookie_header: Option<TypedHeader<headers::Cookie>>,
|
||||
user_agent_header: Option<TypedHeader<headers::UserAgent>>,
|
||||
mut req: Request<B>,
|
||||
next: Next<B>
|
||||
mut req: Request<Body>,
|
||||
next: Next
|
||||
) -> Response {
|
||||
let mut format = query.format;
|
||||
let mut dns_resolver_id = derived_config.default_resolver;
|
||||
|
@ -1,5 +1,6 @@
|
||||
use axum_client_ip::SecureClientIp;
|
||||
use axum::{
|
||||
body::Body,
|
||||
extract::Extension,
|
||||
http::{
|
||||
Request,
|
||||
@ -40,11 +41,11 @@ pub fn build_rate_limiting_state(
|
||||
Extension(arc_limiter)
|
||||
}
|
||||
|
||||
pub async fn rate_limit_middleware<B>(
|
||||
pub async fn rate_limit_middleware(
|
||||
SecureClientIp(address): SecureClientIp,
|
||||
Extension(arc_limiter): Extension<Arc<SimpleRateLimiter<IpAddr>>>,
|
||||
req: Request<B>,
|
||||
next: Next<B>
|
||||
req: Request<Body>,
|
||||
next: Next
|
||||
) -> Response {
|
||||
let limiter = Arc::clone(&arc_limiter);
|
||||
|
||||
|
@ -51,10 +51,10 @@ impl HumusView<QuerySettings, ResponseFormat> for View {
|
||||
|
||||
fn get_cookie_header(&self, settings: &QuerySettings) -> Option<String> {
|
||||
Some(
|
||||
Cookie::build("dns_resolver",settings.dns_resolver_id.to_string())
|
||||
Cookie::build(Cookie::new("dns_resolver",settings.dns_resolver_id.to_string()))
|
||||
.path("/")
|
||||
.same_site(cookie::SameSite::Strict)
|
||||
.finish()
|
||||
.build()
|
||||
.to_string()
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user