Skip to content

Commit

Permalink
feat: Create PushId type (#2286)
Browse files Browse the repository at this point in the history
Fixes #785
  • Loading branch information
larseggert authored Dec 18, 2024
1 parent ab56672 commit bb45c74
Show file tree
Hide file tree
Showing 10 changed files with 438 additions and 227 deletions.
22 changes: 11 additions & 11 deletions neqo-http3/src/client_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
connection::Http3State,
features::extended_connect::{ExtendedConnectEvents, ExtendedConnectType, SessionCloseReason},
settings::HSettingType,
CloseType, Http3StreamInfo, HttpRecvStreamEvents, RecvStreamEvents, SendStreamEvents,
CloseType, Http3StreamInfo, HttpRecvStreamEvents, PushId, RecvStreamEvents, SendStreamEvents,
};

#[derive(Debug, PartialEq, Eq, Clone)]
Expand Down Expand Up @@ -68,24 +68,24 @@ pub enum Http3ClientEvent {
},
/// A new push promise.
PushPromise {
push_id: u64,
push_id: PushId,
request_stream_id: StreamId,
headers: Vec<Header>,
},
/// A push response headers are ready.
PushHeaderReady {
push_id: u64,
push_id: PushId,
headers: Vec<Header>,
interim: bool,
fin: bool,
},
/// New bytes are available on a push stream for reading.
PushDataReadable { push_id: u64 },
PushDataReadable { push_id: PushId },
/// A push has been canceled.
PushCanceled { push_id: u64 },
PushCanceled { push_id: PushId },
/// A push stream was been reset due to a `HttpGeneralProtocol` error.
/// Most common case are malformed response headers.
PushReset { push_id: u64, error: AppError },
PushReset { push_id: PushId, error: AppError },
/// New stream can be created
RequestsCreatable,
/// Cert authentication needed
Expand Down Expand Up @@ -240,20 +240,20 @@ impl ExtendedConnectEvents for Http3ClientEvents {
}

impl Http3ClientEvents {
pub fn push_promise(&self, push_id: u64, request_stream_id: StreamId, headers: Vec<Header>) {
pub fn push_promise(&self, push_id: PushId, request_stream_id: StreamId, headers: Vec<Header>) {
self.insert(Http3ClientEvent::PushPromise {
push_id,
request_stream_id,
headers,
});
}

pub fn push_canceled(&self, push_id: u64) {
pub fn push_canceled(&self, push_id: PushId) {
self.remove_events_for_push_id(push_id);
self.insert(Http3ClientEvent::PushCanceled { push_id });
}

pub fn push_reset(&self, push_id: u64, error: AppError) {
pub fn push_reset(&self, push_id: PushId, error: AppError) {
self.remove_events_for_push_id(push_id);
self.insert(Http3ClientEvent::PushReset { push_id, error });
}
Expand Down Expand Up @@ -336,7 +336,7 @@ impl Http3ClientEvents {
});
}

pub fn has_push(&self, push_id: u64) -> bool {
pub fn has_push(&self, push_id: PushId) -> bool {
for iter in &*self.events.borrow() {
if matches!(iter, Http3ClientEvent::PushPromise{push_id:x, ..} if *x == push_id) {
return true;
Expand All @@ -345,7 +345,7 @@ impl Http3ClientEvents {
false
}

pub fn remove_events_for_push_id(&self, push_id: u64) {
pub fn remove_events_for_push_id(&self, push_id: PushId) {
self.remove(|evt| {
matches!(evt,
Http3ClientEvent::PushPromise{ push_id: x, .. }
Expand Down
Loading

0 comments on commit bb45c74

Please sign in to comment.