Skip to content

Commit

Permalink
fix(router): ensure route-time locks
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuwn committed Jul 17, 2024
1 parent 701cffd commit 4c5dd01
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ members = ["rossweisse"]

[package]
name = "windmark"
version = "0.3.10"
version = "0.3.11"
authors = ["Fuwn <contact@fuwn.me>"]
edition = "2021"
description = "An elegant and highly performant async Gemini server framework"
Expand Down
38 changes: 21 additions & 17 deletions src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,15 @@ impl Router {
module.on_pre_route(hook_context.clone()).await;
}

for module in &mut *self.modules.lock().unwrap() {
module.on_pre_route(hook_context.clone());
if let Ok(mut modules) = self.modules.lock() {
for module in &mut *modules {
module.on_pre_route(hook_context.clone());
}
}

(*self.pre_route_callback)
.lock()
.unwrap()
.call(hook_context.clone());
if let Ok(mut callback) = self.pre_route_callback.lock() {
callback.call(hook_context.clone());
}

let mut content = if let Ok(ref route) = route {
let footers_length = (*self.footers.lock().unwrap()).len();
Expand All @@ -451,11 +452,13 @@ impl Router {
peer_certificate,
);

for partial_header in &mut *self.headers.lock().unwrap() {
header.push_str(&format!(
"{}\n",
partial_header.call(route_context.clone()),
));
if let Ok(mut headers) = self.headers.lock() {
for partial_header in &mut *headers {
header.push_str(&format!(
"{}\n",
partial_header.call(route_context.clone()),
));
}
}

for (i, partial_footer) in {
Expand Down Expand Up @@ -493,14 +496,15 @@ impl Router {
module.on_post_route(hook_context.clone()).await;
}

for module in &mut *self.modules.lock().unwrap() {
module.on_post_route(hook_context.clone());
if let Ok(mut modules) = self.modules.lock() {
for module in &mut *modules {
module.on_post_route(hook_context.clone());
}
}

(*self.post_route_callback)
.lock()
.unwrap()
.call(hook_context.clone(), &mut content);
if let Ok(mut callback) = self.post_route_callback.lock() {
callback.call(hook_context.clone(), &mut content);
}

stream
.write_all(
Expand Down

0 comments on commit 4c5dd01

Please sign in to comment.