use super::H2ErrorCode;
use crate::{Body, Headers, headers::hpack::PseudoHeaders};
#[derive(Debug)]
pub(super) enum StreamLifecycle {
Idle { recv_eof: bool },
Submitted {
submission: Box<Submission>,
recv_eof: bool,
},
Sending { recv_eof: bool },
UpgradeOpen { recv_eof: bool },
UpgradeClosing {
recv_eof: bool,
pending_trailers: Option<Headers>,
},
ResetRequested(H2ErrorCode),
Reset(#[allow(dead_code)] H2ErrorCode),
AwaitingRelease,
}
impl Default for StreamLifecycle {
fn default() -> Self {
Self::Idle { recv_eof: false }
}
}
impl StreamLifecycle {
#[allow(
dead_code,
reason = "kept as a documenting predicate; specific call sites currently use \
`has_active_send` + `has_pending_recv` directly"
)]
pub(super) fn is_in_flight(&self) -> bool {
!matches!(self, Self::Reset(_) | Self::AwaitingRelease)
}
pub(super) fn has_pending_recv(&self) -> bool {
matches!(
self,
Self::Idle { recv_eof: false }
| Self::Submitted {
recv_eof: false,
..
}
| Self::Sending { recv_eof: false }
| Self::UpgradeOpen { recv_eof: false }
| Self::UpgradeClosing {
recv_eof: false,
..
}
)
}
pub(super) fn recv_eof(&self) -> bool {
match self {
Self::Idle { recv_eof }
| Self::Submitted { recv_eof, .. }
| Self::Sending { recv_eof }
| Self::UpgradeOpen { recv_eof }
| Self::UpgradeClosing { recv_eof, .. } => *recv_eof,
Self::ResetRequested(_) | Self::Reset(_) | Self::AwaitingRelease => true,
}
}
pub(super) fn has_active_send(&self) -> bool {
matches!(
self,
Self::Submitted { .. }
| Self::Sending { .. }
| Self::UpgradeOpen { .. }
| Self::UpgradeClosing { .. }
)
}
pub(super) fn mark_recv_eof(&mut self) {
match self {
Self::Idle { recv_eof }
| Self::Submitted { recv_eof, .. }
| Self::Sending { recv_eof }
| Self::UpgradeOpen { recv_eof }
| Self::UpgradeClosing { recv_eof, .. } => *recv_eof = true,
Self::ResetRequested(_) | Self::Reset(_) | Self::AwaitingRelease => {}
}
}
}
#[derive(Debug)]
pub(super) struct Submission {
pub(super) pseudos: PseudoHeaders<'static>,
pub(super) headers: Headers,
pub(super) body: Option<Body>,
pub(super) is_upgrade: bool,
}
impl Submission {
pub(super) fn field_section(&self) -> crate::headers::hpack::FieldSection<'_> {
crate::headers::hpack::FieldSection::new(self.pseudos.clone(), &self.headers)
}
}