Skip to content

Commit

Permalink
sites: enable logs
Browse files Browse the repository at this point in the history
  • Loading branch information
picoHz committed Jul 4, 2023
1 parent 2baef5f commit beea8a3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
21 changes: 15 additions & 6 deletions taxy/src/proxy/http/mod.rs
Expand Up @@ -233,8 +233,12 @@ pub async fn start(
let mut hostname = String::new();
let mut host = String::new();

let mut span = Span::current();

let mut client_tls = false;
if let Some((route, res)) = router.get_route(&req) {
if let Some((route, res, resource_id)) = router.get_route(&req) {
span = span!(Level::INFO, "proxy", resource_id);

let mut parts = Parts::default();

parts.path_and_query = if let Some(query) = req.uri().query() {
Expand Down Expand Up @@ -279,6 +283,7 @@ pub async fn start(
header_rewriter.pre_process(req.headers_mut(), remote.ip());
header_rewriter.post_process(req.headers_mut());

let span_cloned = span.clone();
async move {
if hostname.is_empty() || domain_fronting {
let mut res = hyper::Response::new(hyper::Body::empty());
Expand Down Expand Up @@ -314,7 +319,7 @@ pub async fn start(
}

if upgrade {
return upgrade::connect(req, out).await;
return upgrade::connect(req, out).instrument(span).await;
}

let (mut sender, conn) = client::conn::Builder::new()
Expand All @@ -326,11 +331,14 @@ pub async fn start(
err
})?;

tokio::task::spawn(async move {
if let Err(err) = conn.await {
error!("Connection failed: {:?}", err);
tokio::task::spawn(
async move {
if let Err(err) = conn.await {
error!("Connection failed: {:?}", err);
}
}
});
.instrument(span),
);

let accept_brotli = req
.headers()
Expand Down Expand Up @@ -363,6 +371,7 @@ pub async fn start(
Response::from_parts(parts, body)
})
}
.instrument(span_cloned)
});

tokio::task::spawn(async move {
Expand Down
13 changes: 9 additions & 4 deletions taxy/src/proxy/http/route.rs
Expand Up @@ -17,6 +17,7 @@ impl Router {
.routes
.into_iter()
.map(move |route| FilteredRoute {
resource_id: entry.id.clone(),
filter: RequestFilter::new(&entry.site.vhosts, &route),
route,
})
Expand All @@ -25,15 +26,19 @@ impl Router {
Self { routes }
}

pub fn get_route<T>(&self, req: &Request<T>) -> Option<(&Route, FilterResult)> {
self.routes
.iter()
.find_map(|route| route.filter.test(req).map(|res| (&route.route, res)))
pub fn get_route<T>(&self, req: &Request<T>) -> Option<(&Route, FilterResult, &str)> {
self.routes.iter().find_map(|route| {
route
.filter
.test(req)
.map(|res| (&route.route, res, route.resource_id.as_str()))
})
}
}

#[derive(Debug)]
pub struct FilteredRoute {
pub resource_id: String,
pub filter: RequestFilter,
pub route: Route,
}

0 comments on commit beea8a3

Please sign in to comment.