Skip to content

Commit

Permalink
Remove Control::Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Feb 7, 2024
1 parent a8447b1 commit 68e158d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 52 deletions.
40 changes: 1 addition & 39 deletions ntex/src/http/h1/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ use std::{future::Future, io};

use crate::http::message::CurrentIo;
use crate::http::{body::Body, h1::Codec, Request, Response, ResponseError};
use crate::io::{Filter, Io, IoBoxed, IoRef};
use crate::io::{Filter, Io, IoBoxed};

pub enum Control<F, Err> {
/// New connection
NewConnection(Connection),
/// New request is loaded
NewRequest(NewRequest),
/// Handle `Connection: UPGRADE`
Expand Down Expand Up @@ -74,10 +72,6 @@ impl<F, Err> Control<F, Err> {
Control::NewRequest(NewRequest(req))
}

pub(super) fn con(io: IoRef) -> Self {
Control::NewConnection(Connection { io })
}

pub(super) fn upgrade(req: Request, io: Io<F>, codec: Codec) -> Self {
Control::Upgrade(Upgrade { req, io, codec })
}
Expand All @@ -102,7 +96,6 @@ impl<F, Err> Control<F, Err> {
Err: ResponseError,
{
match self {
Control::NewConnection(msg) => msg.ack(),
Control::NewRequest(msg) => msg.ack(),
Control::Upgrade(msg) => msg.ack(),
Control::Expect(msg) => msg.ack(),
Expand All @@ -114,37 +107,6 @@ impl<F, Err> Control<F, Err> {
}
}

#[derive(Debug)]
pub struct Connection {
io: IoRef,
}

impl Connection {
#[inline]
/// Returns reference to Io
pub fn io(&self) -> &IoRef {
&self.io
}

#[inline]
/// Ack and continue handling process
pub fn ack(self) -> ControlAck {
ControlAck {
result: ControlResult::Stop,
flags: ControlFlags::empty(),
}
}

#[inline]
/// Drop connection
pub fn disconnect(self) -> ControlAck {
ControlAck {
result: ControlResult::Stop,
flags: ControlFlags::DISCONNECT,
}
}
}

#[derive(Debug)]
pub struct NewRequest(Request);

Expand Down
15 changes: 2 additions & 13 deletions ntex/src/http/h1/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,8 @@ where
io.query::<types::PeerAddr>().get()
);

let ack = self
.config
.control
.call_nowait(Control::con(io.get_ref()))
Dispatcher::new(io, self.config.clone())
.await
.map_err(|e| DispatchError::Control(e.into()))?;

if ack.flags.contains(super::control::ControlFlags::DISCONNECT) {
Ok(())
} else {
Dispatcher::new(io, self.config.clone())
.await
.map_err(DispatchError::Control)
}
.map_err(DispatchError::Control)
}
}

0 comments on commit 68e158d

Please sign in to comment.