Skip to content

Commit

Permalink
Fix h2spec http2/6.4/3
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Mar 15, 2024
1 parent 55ead1f commit 78a3e1e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
56 changes: 36 additions & 20 deletions crates/fluke/src/h2/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,30 +665,46 @@ impl<D: ServerDriver + 'static, W: WriteOwned> ServerContext<D, W> {
}
}
// note: this always unconditionally transitions the stream to closed
FrameType::RstStream => match self.state.streams.remove(&frame.stream_id) {
None => {
return Err(H2ConnectionError::RstStreamForUnknownStream {
stream_id: frame.stream_id,
})
}
Some(ss) => {
debug!(
"Closed stream (read RstStream) {}, now have {} streams",
FrameType::RstStream => {
// error code is a 32bit little-endian integer
// a frame size of 4 is expected, if not send a PROTOCOL_ERROR
if frame.len != 4 {
self.rst(
frame.stream_id,
self.state.streams.len()
);
match ss {
StreamState::Open(body_tx) | StreamState::HalfClosedLocal(body_tx) => {
_ = body_tx
.send(Err(H2StreamError::ReceivedRstStream.into()))
.await;
}
StreamState::HalfClosedRemote => {
// good
H2StreamError::InvalidRstStreamFrameSize {
frame_size: frame.len,
},
)
.await?;
return Ok(());
}
// TODO: do something with the error code?

match self.state.streams.remove(&frame.stream_id) {
None => {
return Err(H2ConnectionError::RstStreamForUnknownStream {
stream_id: frame.stream_id,
})
}
Some(ss) => {
debug!(
"Closed stream (read RstStream) {}, now have {} streams",
frame.stream_id,
self.state.streams.len()
);
match ss {
StreamState::Open(body_tx) | StreamState::HalfClosedLocal(body_tx) => {
_ = body_tx
.send(Err(H2StreamError::ReceivedRstStream.into()))
.await;
}
StreamState::HalfClosedRemote => {
// good
}
}
}
}
},
}
FrameType::Settings(s) => {
if frame.stream_id != StreamId::CONNECTION {
return Err(H2ConnectionError::SettingsWithNonZeroStreamId {
Expand Down
4 changes: 4 additions & 0 deletions crates/fluke/src/h2/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ pub(crate) enum H2StreamError {

#[error("stream closed")]
StreamClosed,

#[error("received RST_STREAM frame with invalid size, expected 4 got {frame_size}")]
InvalidRstStreamFrameSize { frame_size: u32 },
}

impl H2StreamError {
Expand All @@ -235,6 +238,7 @@ impl H2StreamError {
StreamClosed => Code::StreamClosed,
RefusedStream => Code::RefusedStream,
InvalidPriorityFrameSize { .. } => Code::FrameSizeError,
InvalidRstStreamFrameSize { .. } => Code::FrameSizeError,
_ => Code::ProtocolError,
}
}
Expand Down

0 comments on commit 78a3e1e

Please sign in to comment.