Skip to content

Commit

Permalink
feat(ext): remove ReasonPhrase::from_bytes_unchecked() method
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The `ReasonPhrase::from_bytes_unchecked()` method is
  gone. Use `from_static()` or `TryFrom` to construct one.
  • Loading branch information
seanmonstar committed Aug 24, 2023
1 parent 43d2f5c commit 4021c57
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/ext/h1_reason_phrase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ impl ReasonPhrase {
Self(Bytes::from_static(reason))
}

// Not public on purpose.
/// Converts a `Bytes` directly into a `ReasonPhrase` without validating.
///
/// Use with care; invalid bytes in a reason phrase can cause serious security problems if
/// emitted in a response.
pub unsafe fn from_bytes_unchecked(reason: Bytes) -> Self {
pub(crate) fn from_bytes_unchecked(reason: Bytes) -> Self {
Self(reason)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/proto/h1/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ impl Http1Transaction for Client {
if let Some(reason) = reason {
// Safety: httparse ensures that only valid reason phrase bytes are present in this
// field.
let reason = unsafe { crate::ext::ReasonPhrase::from_bytes_unchecked(reason) };
let reason = crate::ext::ReasonPhrase::from_bytes_unchecked(reason);
extensions.insert(reason);
}

Expand Down

0 comments on commit 4021c57

Please sign in to comment.