use std::time::{Duration, Instant};
use crate::engine::RefusalKind;
use crate::envelope::Envelope;
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum BodyPolicy {
Buffer {
max: u64,
},
Discard {
max: u64,
},
Stream,
}
#[non_exhaustive]
#[derive(Debug, Clone)]
pub enum HeadAction {
Proceed,
ProceedWith(BodyPolicy),
Refuse {
status: u16,
retry_after: Option<Duration>,
},
Upgrade(UpgradeTarget),
}
impl HeadAction {
#[must_use]
pub const fn refuse(status: u16) -> Self {
HeadAction::Refuse {
status,
retry_after: None,
}
}
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub enum UpgradeTarget {
#[cfg(feature = "ws")]
WebSocket(crate::ws::WebSocketTarget),
}
#[cfg(feature = "ws")]
impl From<crate::ws::WebSocketTarget> for UpgradeTarget {
fn from(target: crate::ws::WebSocketTarget) -> Self {
UpgradeTarget::WebSocket(target)
}
}
#[derive(Debug)]
pub struct UpgradedConn {
pub(crate) env: Envelope,
pub(crate) protocol: &'static str,
pub(crate) subprotocol: Option<&'static str>,
}
impl UpgradedConn {
#[must_use]
pub fn envelope(&self) -> &Envelope {
&self.env
}
#[must_use]
pub fn protocol(&self) -> &'static str {
self.protocol
}
#[must_use]
pub fn subprotocol(&self) -> Option<&'static str> {
self.subprotocol
}
}
#[non_exhaustive]
#[must_use]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Outcome {
Done,
Deferred,
Close,
More,
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum WorkClass {
#[default]
Quick,
Io,
Cpu,
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RequestEnd {
Replied,
Refused(RefusalKind),
Shed,
Denied,
TimedOut,
PeerGone,
Drained,
Killed,
ServicePanic,
Dropped,
Upgraded,
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug)]
pub struct Finished {
pub head_reads: u16,
pub status: Option<u16>,
pub end: RequestEnd,
pub bytes_in: u64,
pub bytes_out: u64,
pub head_at: Instant,
pub admitted_at: Option<Instant>,
pub replied_at: Option<Instant>,
}