diff --git a/viz-core/src/middleware.rs b/viz-core/src/middleware.rs index a9205180..577c2170 100644 --- a/viz-core/src/middleware.rs +++ b/viz-core/src/middleware.rs @@ -11,7 +11,7 @@ pub mod limits; #[cfg(feature = "session")] pub mod session; -#[cfg(feature = "otel")] +#[cfg(all(feature = "params", feature = "otel"))] pub mod otel; #[cfg(feature = "cookie")] diff --git a/viz-core/src/middleware/helper.rs b/viz-core/src/middleware/helper.rs index 351729aa..2733bfb8 100644 --- a/viz-core/src/middleware/helper.rs +++ b/viz-core/src/middleware/helper.rs @@ -131,7 +131,7 @@ pub trait Cookieable { /// Gets a cookie from the cookies. fn get_cookie<'a>(&'a self, cookies: &'a Cookies) -> Option> { - cookies.get(self.options().name); + cookies.get(self.options().name) } /// Deletes a cookie from the cookies. diff --git a/viz-core/src/request.rs b/viz-core/src/request.rs index 19d795cf..44d1fd87 100644 --- a/viz-core/src/request.rs +++ b/viz-core/src/request.rs @@ -1,13 +1,16 @@ -use std::{mem::replace, sync::Arc}; +use std::mem::replace; use crate::{ async_trait, header, - types::{PayloadError, RealIp, RouteInfo}, + types::{PayloadError, RealIp}, Bytes, FromRequest, Incoming, IncomingBody, Request, Result, }; use headers::HeaderMapExt; use http_body_util::{BodyExt, Collected}; +#[cfg(any(feature = "params", feature = "multipart"))] +use std::sync::Arc; + #[cfg(feature = "limits")] use crate::types::Limits; #[cfg(feature = "limits")] @@ -32,7 +35,7 @@ use crate::types::{Cookie, Cookies, CookiesError}; use crate::types::Session; #[cfg(feature = "params")] -use crate::types::{ParamsError, PathDeserializer}; +use crate::types::{ParamsError, PathDeserializer, RouteInfo}; /// The [Request] Extension. #[async_trait] @@ -185,6 +188,7 @@ pub trait RequestExt: Sized { T::Err: std::fmt::Display; /// Get current route. + #[cfg(feature = "params")] fn route_info(&self) -> &Arc; /// Get remote addr. @@ -435,6 +439,7 @@ impl RequestExt for Request { self.extensions().get() } + #[cfg(feature = "params")] fn route_info(&self) -> &Arc { self.extensions().get().expect("should get current route") } diff --git a/viz-core/src/types.rs b/viz-core/src/types.rs index f00d9130..06c438d2 100644 --- a/viz-core/src/types.rs +++ b/viz-core/src/types.rs @@ -59,12 +59,15 @@ mod websocket; #[cfg(feature = "websocket")] pub use websocket::{Message, WebSocket, WebSocketConfig, WebSocketError, WebSocketStream}; +#[cfg(feature = "params")] +mod route_info; +#[cfg(feature = "params")] +pub use route_info::RouteInfo; + mod header; mod payload; mod realip; -mod route_info; pub use header::{Header, HeaderError}; pub use payload::{Payload, PayloadError}; pub use realip::RealIp; -pub use route_info::RouteInfo; diff --git a/viz-test/src/lib.rs b/viz-test/src/lib.rs index d4440d0d..169d06f8 100644 --- a/viz-test/src/lib.rs +++ b/viz-test/src/lib.rs @@ -1,7 +1,7 @@ use reqwest::Client; use std::{net::SocketAddr, sync::Arc}; use tokio::net::TcpListener; -use viz::{server::conn::http1, Error, Io, Responder, Result, Router, Tree}; +use viz::{serve, Error, Result, Router, Tree}; pub use nano_id; pub use sessions; @@ -63,13 +63,6 @@ async fn run(listener: TcpListener, tree: Arc) -> Result<()> { loop { let (stream, addr) = listener.accept().await?; let tree = tree.clone(); - tokio::task::spawn(async move { - if let Err(err) = http1::Builder::new() - .serve_connection(Io::new(stream), Responder::new(tree, Some(addr))) - .await - { - eprintln!("Error while serving HTTP connection: {err}"); - } - }); + tokio::task::spawn(serve(stream, tree, Some(addr))); } } diff --git a/viz/src/lib.rs b/viz/src/lib.rs index d30d7956..2e7d912d 100644 --- a/viz/src/lib.rs +++ b/viz/src/lib.rs @@ -535,7 +535,9 @@ mod responder; #[cfg(any(feature = "http1", feature = "http2"))] pub use responder::Responder; +#[cfg(any(feature = "http1", feature = "http2"))] mod serve; +#[cfg(any(feature = "http1", feature = "http2"))] pub use serve::serve; /// TLS