mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 10:10:30 +08:00
httpd: Update axum and hyper dependency
This commit is contained in:
committed by
cloudhead
parent
66369f98d9
commit
4c16c2724f
@@ -13,10 +13,11 @@ use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::Context as _;
|
||||
use axum::body::{Body, BoxBody, HttpBody};
|
||||
use axum::body::{Body, HttpBody};
|
||||
use axum::http::{Request, Response};
|
||||
use axum::middleware;
|
||||
use axum::Router;
|
||||
use tokio::net::TcpListener;
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tracing::Span;
|
||||
|
||||
@@ -54,9 +55,9 @@ pub async fn run(options: Options) -> anyhow::Result<()> {
|
||||
|
||||
tracing::info!("{}", str::from_utf8(&git_version)?.trim());
|
||||
|
||||
let listen = options.listen;
|
||||
let listener = TcpListener::bind(options.listen).await?;
|
||||
|
||||
tracing::info!("listening on http://{}", listen);
|
||||
tracing::info!("listening on http://{}", options.listen);
|
||||
|
||||
let profile = Profile::load()?;
|
||||
let request_id = RequestId::new();
|
||||
@@ -72,7 +73,7 @@ pub async fn run(options: Options) -> anyhow::Result<()> {
|
||||
tracing::info_span!("request", id = %request_id.clone().next())
|
||||
})
|
||||
.on_response(
|
||||
|response: &Response<BoxBody>, latency: Duration, _span: &Span| {
|
||||
|response: &Response<Body>, latency: Duration, _span: &Span| {
|
||||
if let Some(info) = response.extensions().get::<TracingInfo>() {
|
||||
tracing::info!(
|
||||
"{} \"{} {} {:?}\" {} {:?} {}",
|
||||
@@ -100,8 +101,7 @@ pub async fn run(options: Options) -> anyhow::Result<()> {
|
||||
)
|
||||
.into_make_service_with_connect_info::<SocketAddr>();
|
||||
|
||||
axum::Server::bind(&listen)
|
||||
.serve(app)
|
||||
axum::serve(listener, app)
|
||||
.await
|
||||
.map_err(anyhow::Error::from)
|
||||
}
|
||||
|
||||
@@ -381,6 +381,8 @@ impl Response {
|
||||
}
|
||||
|
||||
pub async fn body(self) -> Bytes {
|
||||
hyper::body::to_bytes(self.0.into_body()).await.unwrap()
|
||||
axum::body::to_bytes(self.0.into_body(), usize::MAX)
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ use std::net::SocketAddr;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::body::Body;
|
||||
use axum::extract::ConnectInfo;
|
||||
use axum::http::Request;
|
||||
use axum::middleware::Next;
|
||||
@@ -25,6 +26,7 @@ impl RequestId {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TracingInfo {
|
||||
pub connect_info: ConnectInfo<SocketAddr>,
|
||||
pub method: Method,
|
||||
@@ -45,7 +47,7 @@ impl fmt::Display for ColoredStatus {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn tracing_middleware<B>(request: Request<B>, next: Next<B>) -> impl IntoResponse {
|
||||
pub async fn tracing_middleware(request: Request<Body>, next: Next) -> impl IntoResponse {
|
||||
let connect_info = *request
|
||||
.extensions()
|
||||
.get::<ConnectInfo<std::net::SocketAddr>>()
|
||||
|
||||
Reference in New Issue
Block a user