Skip to content

Commit

Permalink
fix(core): RouteInfo needs params feature
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Oct 18, 2023
1 parent a697a43 commit 9280436
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion viz-core/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion viz-core/src/middleware/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub trait Cookieable {

/// Gets a cookie from the cookies.
fn get_cookie<'a>(&'a self, cookies: &'a Cookies) -> Option<Cookie<'a>> {
cookies.get(self.options().name);
cookies.get(self.options().name)
}

/// Deletes a cookie from the cookies.
Expand Down
11 changes: 8 additions & 3 deletions viz-core/src/request.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand All @@ -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]
Expand Down Expand Up @@ -185,6 +188,7 @@ pub trait RequestExt: Sized {
T::Err: std::fmt::Display;

/// Get current route.
#[cfg(feature = "params")]
fn route_info(&self) -> &Arc<RouteInfo>;

/// Get remote addr.
Expand Down Expand Up @@ -435,6 +439,7 @@ impl RequestExt for Request {
self.extensions().get()
}

#[cfg(feature = "params")]
fn route_info(&self) -> &Arc<RouteInfo> {
self.extensions().get().expect("should get current route")
}
Expand Down
7 changes: 5 additions & 2 deletions viz-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
11 changes: 2 additions & 9 deletions viz-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -63,13 +63,6 @@ async fn run(listener: TcpListener, tree: Arc<Tree>) -> 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)));
}
}
2 changes: 2 additions & 0 deletions viz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9280436

Please sign in to comment.