Skip to content

Commit

Permalink
h3i: add additional helpers for EnrichedHeaders and StatusCode intera…
Browse files Browse the repository at this point in the history
…ctions
  • Loading branch information
evanrittenhouse committed Nov 17, 2024
1 parent 57bdafd commit 08babd4
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion h3i/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,20 @@ impl From<Vec<Header>> for EnrichedHeaders {
}
}

impl PartialEq<StatusCode> for EnrichedHeaders {
fn eq(&self, other: &StatusCode) -> bool {
self.status_code()
.map(|status| status.ok() == Some(*other))
.unwrap_or(false)
}
}

impl From<StatusCode> for EnrichedHeaders {
fn from(value: StatusCode) -> Self {
Self::from(vec![Header::new(b":status", value.as_str().as_bytes())])
}
}

impl TryFrom<QFrame> for EnrichedHeaders {
type Error = BoxError;

Expand Down Expand Up @@ -446,7 +460,16 @@ mod tests {
let enriched = H3iFrame::Headers(header_frame.into())
.to_enriched_headers()
.unwrap();

assert!(enriched.status_code().is_none());
}

#[test]
fn test_status_code_interaction() {
let header_frame = EnrichedHeaders::from(StatusCode::OK);
assert_eq!(header_frame.headers(), vec![Header::new(
b":status", b"200"
)]);

assert_eq!(header_frame, StatusCode::OK);
}
}

0 comments on commit 08babd4

Please sign in to comment.