Skip to content

Commit ca76613

Browse files
committed
docs: Correct comments in HeaderValue::from_maybe_shared_unchecked.
Signed-off-by: Piotr Sikora <code@piotrsikora.dev>
1 parent d59d939 commit ca76613

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/header/value.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,23 @@ impl HeaderValue {
172172
/// This function does NOT validate that illegal bytes are not contained
173173
/// within the buffer.
174174
///
175-
/// ## Panics
176-
/// In a debug build this will panic if `src` is not valid UTF-8.
175+
/// # Panics
176+
///
177+
/// In a debug build this will panic if `src` contains bytes that are not
178+
/// allowed in HTTP field values.
179+
///
180+
/// # Safety
181+
///
182+
/// This function is not unsafe in Rust terms (meaning memory unsafety),
183+
/// and the value is only converted to &str in the `to_str()` function
184+
/// after verifying that all bytes are in a visible subset of US-ASCII
185+
/// (which is also valid UTF-8).
177186
///
178-
/// ## Safety
179-
/// `src` must contain valid UTF-8. In a release build it is undefined
180-
/// behaviour to call this with `src` that is not valid UTF-8.
187+
/// However, a care must be taken to ensure that `src` contains only bytes
188+
/// allowed in HTTP field values (e.g. by using this function with a value
189+
/// that was already processed by a validating HTTP parser), since invalid
190+
/// bytes might result in a header being ignored, or even the whole request
191+
/// containing it being rejected, by an HTTP peer.
181192
pub unsafe fn from_maybe_shared_unchecked<T>(src: T) -> HeaderValue
182193
where
183194
T: AsRef<[u8]> + 'static,

0 commit comments

Comments
 (0)