File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed
Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments