Why and when does trillium serialize calls? #196
-
Hello. use std::time::Duration;
use log::LevelFilter;
use simple_logger::SimpleLogger;
use trillium::{Conn, Status};
use trillium_async_std::Stopper;
use trillium_logger::Logger;
use trillium_router::Router;
fn main() {
SimpleLogger::new()
.with_level(LevelFilter::Debug)
.init()
.expect("The logger should be able to be initialized without an issue.");
let stopper = Stopper::new();
set_stopper_to_handle_ctrlc(stopper.clone());
trillium_async_std::config()
.with_host("127.0.0.1")
.with_port(7878)
.with_stopper(stopper)
.run((
Logger::new(),
Router::new()
.get("/", serve_default)
.get("/sleep", serve_sleep),
))
}
async fn serve_default(connection_state: Conn) -> Conn {
log::debug!("Serving the default page");
connection_state
.with_body("Default page")
.with_status(Status::Ok)
}
async fn serve_sleep(connection_state: Conn) -> Conn {
log::debug!("Serving the sleep page");
trillium_async_std::async_std::task::sleep(Duration::from_secs(10)).await;
connection_state
.with_body("It was a great nap")
.with_status(Status::Ok)
}
fn set_stopper_to_handle_ctrlc(stopper: Stopper) {
ctrlc::set_handler(move || {
log::debug!("Initiating the stopping procedures");
stopper.stop()
})
.expect("The handler should just work.")
} When I'm accessing |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
If your handcrafted http server does not support http/1.1 keepalive, that would explain the difference. Your browser is reusing the same tcp connection. How are you making the request in the browser? Try it with curl in the terminal to see that two separate requests on different tcp connections do not block each other |
Beta Was this translation helpful? Give feedback.
If your handcrafted http server does not support http/1.1 keepalive, that would explain the difference. Your browser is reusing the same tcp connection. How are you making the request in the browser? Try it with curl in the terminal to see that two separate requests on different tcp connections do not block each other