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;
99pub struct HeaderName ( Cow < ' static , str > ) ;
1010
1111impl 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 > {
1418 crate :: ensure!( bytes. is_ascii( ) , "Bytes should be valid ASCII" ) ;
1519 bytes. make_ascii_lowercase ( ) ;
1620
@@ -33,7 +37,7 @@ impl HeaderName {
3337 /// ASCII. If this constraint is violated, it may cause memory
3438 /// unsafety issues with future users of the HeaderName, as the rest of the library assumes
3539 /// 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 {
3741 bytes. make_ascii_lowercase ( ) ;
3842 let string = String :: from_utf8_unchecked ( bytes) ;
3943 HeaderName ( Cow :: Owned ( string) )
Original file line number Diff line number Diff line change @@ -13,12 +13,12 @@ pub struct HeaderValue {
1313}
1414
1515impl HeaderValue {
16- /// Create a new `HeaderValue` from ASCII bytes.
16+ /// Create a new `HeaderValue` from a Vec of ASCII bytes.
1717 ///
1818 /// # Error
1919 ///
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 > {
2222 crate :: ensure!( bytes. is_ascii( ) , "Bytes should be valid ASCII" ) ;
2323
2424 // This is permitted because ASCII is valid UTF-8, and we just checked that.
@@ -35,7 +35,7 @@ impl HeaderValue {
3535 /// ASCII. If this constraint is violated, it may cause memory
3636 /// unsafety issues with future users of the HeaderValue, as the rest of the library assumes
3737 /// 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 {
3939 let string = String :: from_utf8_unchecked ( bytes) ;
4040 Self { inner : string }
4141 }
Original file line number Diff line number Diff line change @@ -57,10 +57,10 @@ impl From<Version> for http::Version {
5757fn hyperium_headers_to_headers ( hyperium_headers : http:: HeaderMap , headers : & mut Headers ) {
5858 for ( name, value) in hyperium_headers {
5959 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) } ;
6161 if let Some ( name) = name {
6262 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) } ;
6464 headers. insert ( name, value) . unwrap ( ) ;
6565 }
6666 }
You can’t perform that action at this time.
0 commit comments