Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion http/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,6 @@ where
async fn call(&self, res: Result<S, E>) -> Result<Self::Response, Self::Error> {
let service = res.map_err(|e| Box::new(e) as Error)?;
let tls_acceptor = self.tls_factory.call(()).await.map_err(|e| Box::new(e) as Error)?;
Ok(HttpService::new(self.config, service, tls_acceptor))
Ok(HttpService::new(self.config.clone(), service, tls_acceptor))
}
}
2 changes: 1 addition & 1 deletion http/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub const DEFAULT_WRITE_BUF_LIMIT: usize = 8192 + 4096 * 100;
/// 64 chosen for no particular reason.
pub const DEFAULT_HEADER_LIMIT: usize = 64;

#[derive(Copy, Clone)]
#[derive(Clone)]
pub struct HttpServiceConfig<
const HEADER_LIMIT: usize = DEFAULT_HEADER_LIMIT,
const READ_BUF_LIMIT: usize = DEFAULT_READ_BUF_LIMIT,
Expand Down
2 changes: 1 addition & 1 deletion http/src/h1/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ where
async fn call(&self, res: Result<S, E>) -> Result<Self::Response, Self::Error> {
let service = res.map_err(|e| Box::new(e) as Error)?;
let tls_acceptor = self.tls_factory.call(()).await.map_err(|e| Box::new(e) as Error)?;
Ok(H1Service::new(self.config, service, tls_acceptor))
Ok(H1Service::new(self.config.clone(), service, tls_acceptor))
}
}
5 changes: 3 additions & 2 deletions http/src/h1/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
date::DateTime,
h1::error::Error,
http::{StatusCode, response::Response},
util::timer::{KeepAlive, Timeout},
util::timer::{KeepAlive, KeepAliveOutput, Timeout},
};

use super::{
Expand Down Expand Up @@ -98,7 +98,8 @@ where
break Ok(());
}
}
Err(_) => break Err(dispatcher.timer.map_to_err()),
Err(KeepAliveOutput::Cancel) => break Ok(()),
Err(KeepAliveOutput::Expire) => break Err(dispatcher.timer.map_to_err()),
}
};

Expand Down
2 changes: 1 addition & 1 deletion http/src/h1/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where
addr,
crate::bytes::BytesMut::new(),
timer,
self.config,
self.config.clone(),
&self.service,
self.date.get(),
)
Expand Down
2 changes: 1 addition & 1 deletion http/src/h2/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ where
async fn call(&self, res: Result<S, E>) -> Result<Self::Response, Self::Error> {
let service = res.map_err(|e| Box::new(e) as Error)?;
let tls_acceptor = self.tls_factory.call(()).await.map_err(|e| Box::new(e) as Error)?;
Ok(H2Service::new(self.config, service, tls_acceptor))
Ok(H2Service::new(self.config.clone(), service, tls_acceptor))
}
}
2 changes: 1 addition & 1 deletion http/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ where
_addr,
_read_buf,
_timer.as_mut(),
self.config,
self.config.clone(),
&self.service,
self.date.get(),
)
Expand Down
14 changes: 11 additions & 3 deletions http/src/util/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pin_project! {
}

impl<F: Future> Future for TimeoutFuture<'_, F> {
type Output = Result<F::Output, ()>;
type Output = Result<F::Output, KeepAliveOutput>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
Expand Down Expand Up @@ -79,17 +79,25 @@ impl KeepAlive {
}

impl Future for KeepAlive {
type Output = ();
type Output = KeepAliveOutput;

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.as_mut().project();
ready!(this.timer.poll(cx));

if self.is_expired() {
Poll::Ready(())
Poll::Ready(KeepAliveOutput::Expire)
} else {
self.as_mut().reset();
self.poll(cx)
}
}
}

/// return type of timer when it's finished
pub enum KeepAliveOutput {
/// Timer is canceled by foreign input
Cancel,
/// Timer is explired
Expire,
}
12 changes: 6 additions & 6 deletions web/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ where
ResB: Body<Data = Bytes> + 'static,
ResB::Error: fmt::Debug + 'static,
{
let http = HttpServiceBuilder::with_config(self.config);
let http = HttpServiceBuilder::with_config(self.config.clone());
let service = self.service.clone();
let name = "xitca-web";

Expand Down Expand Up @@ -226,7 +226,7 @@ where
ResB::Error: fmt::Debug + 'static,
L: IntoListener + 'static,
{
let http = HttpServiceBuilder::with_config(self.config);
let http = HttpServiceBuilder::with_config(self.config.clone());
let service = self.service.clone();
let name = "xitca-web";

Expand Down Expand Up @@ -259,7 +259,7 @@ where
ResB: Body<Data = Bytes> + 'static,
ResB::Error: fmt::Debug + 'static,
{
let config = self.config;
let config = self.config.clone();

const H11: &[u8] = b"\x08http/1.1";

Expand Down Expand Up @@ -323,7 +323,7 @@ where
ResB: Body<Data = Bytes> + 'static,
ResB::Error: fmt::Debug + 'static,
{
let service_config = self.config;
let service_config = self.config.clone();

#[cfg(feature = "http2")]
config.alpn_protocols.push("h2".into());
Expand Down Expand Up @@ -361,7 +361,7 @@ where
ResB: Body<Data = Bytes> + 'static,
ResB::Error: fmt::Debug + 'static,
{
let http = HttpServiceBuilder::with_config(self.config);
let http = HttpServiceBuilder::with_config(self.config.clone());
let name = "xitca-web";
let service = self.service.clone();
self.builder = if self.enable_io_uring {
Expand Down Expand Up @@ -396,7 +396,7 @@ where
let service = self
.service
.clone()
.enclosed(HttpServiceBuilder::with_config(self.config));
.enclosed(HttpServiceBuilder::with_config(self.config.clone()));

self.builder = self.builder.bind_h3("xitca-web", addr, config, service)?;
Ok(self)
Expand Down
Loading