Skip to content

Commit

Permalink
Section 5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Jun 1, 2024
1 parent 425a058 commit 21aa817
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
21 changes: 21 additions & 0 deletions crates/httpwg-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,27 @@ macro_rules! tests {
$body
}
}

/// Section 5.3: Stream Dependencies
mod _5_3_1_stream_dependencies {
use super::__suite::_5_3_1_stream_dependencies as __group;

/// A stream cannot depend on itself. An endpoint MUST treat this
/// as a stream error (Section 5.4.2) of type PROTOCOL_ERROR.
#[test]
fn headers_frame_depends_on_itself() {
use __group::headers_frame_depends_on_itself as test;
$body
}

/// A stream cannot depend on itself. An endpoint MUST treat this
/// as a stream error (Section 5.4.2) of type PROTOCOL_ERROR.
#[test]
fn priority_frame_depends_on_itself() {
use __group::priority_frame_depends_on_itself as test;
$body
}
}
}
};
}
27 changes: 27 additions & 0 deletions crates/httpwg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,33 @@ impl<IO: IntoHalves> Conn<IO> {
Ok(())
}

pub async fn write_headers_with_priority(
&mut self,
stream_id: StreamId,
flags: impl Into<BitFlags<HeadersFlags>>,
priority_spec: PrioritySpec,
block_fragment: Piece,
) -> eyre::Result<()> {
let flags = flags.into() | HeadersFlags::Priority;
let frame = Frame::new(FrameType::Headers(flags), stream_id);

let payload = block_fragment.into_piece(&mut self.scratch)?;
let frame = frame.with_len(payload.len().try_into().unwrap());

let priority_spec_piece = priority_spec.into_piece(&mut self.scratch)?;

let header = frame.into_piece(&mut self.scratch)?;
self.w
.writev_all_owned(
PieceList::single(header)
.followed_by(priority_spec_piece)
.followed_by(payload),
)
.await?;

Ok(())
}

pub async fn write_continuation(
&mut self,
stream_id: StreamId,
Expand Down
59 changes: 59 additions & 0 deletions crates/httpwg/src/rfc9113/_5_3_1_stream_dependencies.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//! Section 5.3: Stream Dependencies
use fluke_buffet::IntoHalves;
use fluke_h2_parse::{HeadersFlags, PrioritySpec, StreamId};

use crate::{Conn, ErrorC};

/// A stream cannot depend on itself. An endpoint MUST treat this
/// as a stream error (Section 5.4.2) of type PROTOCOL_ERROR.
pub async fn headers_frame_depends_on_itself<IO: IntoHalves + 'static>(
mut conn: Conn<IO>,
) -> eyre::Result<()> {
let stream_id = StreamId(1);

conn.handshake().await?;

let headers = conn.common_headers();
let block_fragment = conn.encode_headers(&headers)?;

conn.write_headers_with_priority(
stream_id,
HeadersFlags::EndHeaders | HeadersFlags::EndStream,
PrioritySpec {
stream_dependency: stream_id,
exclusive: false,
weight: 255,
},
block_fragment,
)
.await?;

conn.verify_stream_error(ErrorC::ProtocolError).await?;

Ok(())
}

/// A stream cannot depend on itself. An endpoint MUST treat this
/// as a stream error (Section 5.4.2) of type PROTOCOL_ERROR.
pub async fn priority_frame_depends_on_itself<IO: IntoHalves + 'static>(
mut conn: Conn<IO>,
) -> eyre::Result<()> {
let stream_id = StreamId(1);

conn.handshake().await?;

conn.write_priority(
stream_id,
PrioritySpec {
stream_dependency: stream_id,
exclusive: false,
weight: 255,
},
)
.await?;

conn.verify_stream_error(ErrorC::ProtocolError).await?;

Ok(())
}
2 changes: 2 additions & 0 deletions crates/httpwg/src/rfc9113/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ pub mod _4_3_header_compression_and_decompression;
pub mod _5_1_1_stream_identifiers;
pub mod _5_1_2_stream_concurrency;
pub mod _5_1_stream_states;

pub mod _5_3_1_stream_dependencies;

0 comments on commit 21aa817

Please sign in to comment.