diff --git a/src/globals.rs b/src/globals.rs index def9f68..658aca2 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -1,12 +1,13 @@ use crate::config::Config; use crate::ip::HashedIp; use dashmap::DashMap; +use hyper::server::conn::http1; use lazy_static::lazy_static; use parking_lot::RwLock; use pocket_db::Store; use std::sync::atomic::{AtomicU64, AtomicUsize}; use std::sync::OnceLock; -use std::time::Instant; +use std::time::{Duration, Instant}; use tokio::sync::broadcast::Sender as BroadcastSender; use tokio::sync::watch::Sender as WatchSender; @@ -16,6 +17,7 @@ pub struct Globals { pub bytes_outbound: AtomicU64, pub config: RwLock, pub store: OnceLock, + pub http1builder: http1::Builder, pub rid: OnceLock, /// This is a broadcast channel where new incoming events are advertised by their offset. @@ -34,12 +36,18 @@ lazy_static! { let (new_events, _) = tokio::sync::broadcast::channel(512); let (shutting_down, _) = tokio::sync::watch::channel(false); + let mut http1builder = http1::Builder::new(); + http1builder.half_close(true); + http1builder.keep_alive(true); + http1builder.header_read_timeout(Duration::from_secs(5)); + Globals { start_time: Instant::now(), bytes_inbound: AtomicU64::new(0), bytes_outbound: AtomicU64::new(0), config: RwLock::new(Default::default()), store: OnceLock::new(), + http1builder, rid: OnceLock::new(), new_events, num_connections: AtomicUsize::new(0), diff --git a/src/lib.rs b/src/lib.rs index e5c214f..17f9c9c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,6 @@ use crate::reply::NostrReply; use futures::{sink::SinkExt, stream::StreamExt}; use http_body_util::Full; use hyper::body::{Bytes, Incoming}; -use hyper::server::conn::http1; use hyper::service::Service; use hyper::upgrade::Upgraded; use hyper::StatusCode; @@ -57,10 +56,7 @@ pub async fn serve(stream: Box, peer: HashedPeer) { let io = hyper_util::rt::TokioIo::new(stream); - let mut http1builder = http1::Builder::new(); - http1builder.half_close(true); - http1builder.keep_alive(true); - http1builder.header_read_timeout(Duration::from_secs(5)); + let http1builder = GLOBALS.http1builder.clone(); let connection = http1builder.serve_connection(io, service).with_upgrades(); // If our service exits with an error, log the error