🚧 it works!
parent
c663d126aa
commit
08009de043
|
@ -79,4 +79,7 @@ pub enum ServerError {
|
||||||
|
|
||||||
#[error ("Step 3 relay response (non-200 OK) was not valid UTF-8")]
|
#[error ("Step 3 relay response (non-200 OK) was not valid UTF-8")]
|
||||||
Step3ErrorResponseNotUtf8 (std::string::FromUtf8Error),
|
Step3ErrorResponseNotUtf8 (std::string::FromUtf8Error),
|
||||||
|
|
||||||
|
#[error (transparent)]
|
||||||
|
Other (#[from] anyhow::Error),
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#![allow (clippy::mut_mut)]
|
#![allow (clippy::mut_mut)]
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
future::Future,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
|
@ -144,10 +145,15 @@ async fn handle_one_req (
|
||||||
Ok::<(), ServerError> (())
|
Ok::<(), ServerError> (())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_requests (
|
async fn handle_requests <F, F2, H> (
|
||||||
state: &Arc <State>,
|
state: &Arc <State>,
|
||||||
req_resp: reqwest::Response
|
req_resp: reqwest::Response,
|
||||||
|
mut spawn_handler: H,
|
||||||
) -> Result <(), ServerError>
|
) -> Result <(), ServerError>
|
||||||
|
where
|
||||||
|
F: Send + Future <Output = anyhow::Result <http_serde::Response>>,
|
||||||
|
F2: Send + 'static + FnOnce (http_serde::RequestParts) -> F,
|
||||||
|
H: Send + FnMut () -> F2
|
||||||
{
|
{
|
||||||
//println! ("Step 1");
|
//println! ("Step 1");
|
||||||
|
|
||||||
|
@ -165,6 +171,7 @@ async fn handle_requests (
|
||||||
|
|
||||||
for wrapped_req in wrapped_reqs {
|
for wrapped_req in wrapped_reqs {
|
||||||
let state = Arc::clone (&state);
|
let state = Arc::clone (&state);
|
||||||
|
let handler = spawn_handler ();
|
||||||
|
|
||||||
// These have to detach, so we won't be able to catch the join errors.
|
// These have to detach, so we won't be able to catch the join errors.
|
||||||
|
|
||||||
|
@ -172,12 +179,16 @@ async fn handle_requests (
|
||||||
let (req_id, parts) = (wrapped_req.id, wrapped_req.req);
|
let (req_id, parts) = (wrapped_req.id, wrapped_req.req);
|
||||||
|
|
||||||
debug! ("Handling request {}", req_id);
|
debug! ("Handling request {}", req_id);
|
||||||
|
/*
|
||||||
let response = state.file_server.serve_all (
|
let response = state.file_server.serve_all (
|
||||||
parts.method,
|
parts.method,
|
||||||
&parts.uri,
|
&parts.uri,
|
||||||
&parts.headers,
|
&parts.headers,
|
||||||
).await?;
|
).await?;
|
||||||
|
*/
|
||||||
|
|
||||||
|
let f = handler (parts);
|
||||||
|
let response = f.await?;
|
||||||
|
|
||||||
handle_one_req (&state, req_id, response).await
|
handle_one_req (&state, req_id, response).await
|
||||||
});
|
});
|
||||||
|
@ -373,7 +384,19 @@ async fn run_server_loop (
|
||||||
// Unpack the requests, spawn them into new tasks, then loop back
|
// Unpack the requests, spawn them into new tasks, then loop back
|
||||||
// around.
|
// around.
|
||||||
|
|
||||||
if handle_requests (&state, req_resp).await.is_err () {
|
let spawn_handler = || {
|
||||||
|
let state = Arc::clone (&state);
|
||||||
|
|
||||||
|
|req: http_serde::RequestParts| async move {
|
||||||
|
Ok (state.file_server.serve_all (req.method, &req.uri, &req.headers).await?)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if handle_requests (
|
||||||
|
&state,
|
||||||
|
req_resp,
|
||||||
|
spawn_handler,
|
||||||
|
).await.is_err () {
|
||||||
backoff_delay = err_backoff_delay;
|
backoff_delay = err_backoff_delay;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue