File tree Expand file tree Collapse file tree 3 files changed +13
-9
lines changed Expand file tree Collapse file tree 3 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -9,8 +9,12 @@ use crate::Error;
9
9
pub struct HeaderName ( Cow < ' static , str > ) ;
10
10
11
11
impl HeaderName {
12
- /// Create a new `HeaderName`.
13
- pub fn from_ascii ( mut bytes : Vec < u8 > ) -> Result < Self , Error > {
12
+ /// Create a new `HeaderName` from a Vec of ASCII bytes.
13
+ ///
14
+ /// # Error
15
+ ///
16
+ /// This function will error if the bytes is not valid ASCII.
17
+ pub fn from_bytes ( mut bytes : Vec < u8 > ) -> Result < Self , Error > {
14
18
crate :: ensure!( bytes. is_ascii( ) , "Bytes should be valid ASCII" ) ;
15
19
bytes. make_ascii_lowercase ( ) ;
16
20
@@ -33,7 +37,7 @@ impl HeaderName {
33
37
/// ASCII. If this constraint is violated, it may cause memory
34
38
/// unsafety issues with future users of the HeaderName, as the rest of the library assumes
35
39
/// that Strings are valid ASCII.
36
- pub unsafe fn from_ascii_unchecked ( mut bytes : Vec < u8 > ) -> Self {
40
+ pub unsafe fn from_bytes_unchecked ( mut bytes : Vec < u8 > ) -> Self {
37
41
bytes. make_ascii_lowercase ( ) ;
38
42
let string = String :: from_utf8_unchecked ( bytes) ;
39
43
HeaderName ( Cow :: Owned ( string) )
Original file line number Diff line number Diff line change @@ -13,12 +13,12 @@ pub struct HeaderValue {
13
13
}
14
14
15
15
impl HeaderValue {
16
- /// Create a new `HeaderValue` from ASCII bytes.
16
+ /// Create a new `HeaderValue` from a Vec of ASCII bytes.
17
17
///
18
18
/// # Error
19
19
///
20
- /// This function will error if the string is not a valid ASCII.
21
- pub fn from_ascii ( bytes : & [ u8 ] ) -> Result < Self , Error > {
20
+ /// This function will error if the bytes is not valid ASCII.
21
+ pub fn from_bytes ( bytes : & [ u8 ] ) -> Result < Self , Error > {
22
22
crate :: ensure!( bytes. is_ascii( ) , "Bytes should be valid ASCII" ) ;
23
23
24
24
// This is permitted because ASCII is valid UTF-8, and we just checked that.
@@ -35,7 +35,7 @@ impl HeaderValue {
35
35
/// ASCII. If this constraint is violated, it may cause memory
36
36
/// unsafety issues with future users of the HeaderValue, as the rest of the library assumes
37
37
/// that Strings are valid ASCII.
38
- pub unsafe fn from_ascii_unchecked ( bytes : Vec < u8 > ) -> Self {
38
+ pub unsafe fn from_bytes_unchecked ( bytes : Vec < u8 > ) -> Self {
39
39
let string = String :: from_utf8_unchecked ( bytes) ;
40
40
Self { inner : string }
41
41
}
Original file line number Diff line number Diff line change @@ -57,10 +57,10 @@ impl From<Version> for http::Version {
57
57
fn hyperium_headers_to_headers ( hyperium_headers : http:: HeaderMap , headers : & mut Headers ) {
58
58
for ( name, value) in hyperium_headers {
59
59
let value = value. as_bytes ( ) . to_owned ( ) ;
60
- let value = unsafe { HeaderValue :: from_ascii_unchecked ( value) } ;
60
+ let value = unsafe { HeaderValue :: from_bytes_unchecked ( value) } ;
61
61
if let Some ( name) = name {
62
62
let name = name. as_str ( ) . as_bytes ( ) . to_owned ( ) ;
63
- let name = unsafe { HeaderName :: from_ascii_unchecked ( name) } ;
63
+ let name = unsafe { HeaderName :: from_bytes_unchecked ( name) } ;
64
64
headers. insert ( name, value) . unwrap ( ) ;
65
65
}
66
66
}
You can’t perform that action at this time.
0 commit comments