Skip to content

Commit

Permalink
refactor(router): Extract logic for computing restricted headers
Browse files Browse the repository at this point in the history
  • Loading branch information
V-Wong committed Jan 4, 2025
1 parent f684201 commit bc0132f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,22 @@ impl Router {

self.thread_pool.exec(move || {
let mut response = handler(&request);
response.headers.add(
"Content-Length",
&response
.body
.as_ref()
.map(|body| body.len())
.unwrap_or(0)
.to_string(),
);
compute_restricted_headers(&mut response);
stream.write_all(String::from(response).as_bytes()).unwrap();
});
}
}
}

fn compute_restricted_headers(response: &mut response::Response) -> &response::Response {
response.headers.add(
"Content-Length",
&response
.body
.as_ref()
.map(|body| body.len())
.unwrap_or(0)
.to_string(),
);
response
}

0 comments on commit bc0132f

Please sign in to comment.