pub struct Header {
pub name: HeaderType,
pub value: String,
}Expand description
Http header. Has a name and a value.
Fields§
§name: HeaderTypeName of the Header
value: StringValue of the Header
Implementations§
source§impl Header
impl Header
sourcepub fn new(name: impl Into<HeaderType>, value: impl AsRef<str>) -> Header
pub fn new(name: impl Into<HeaderType>, value: impl AsRef<str>) -> Header
Make a new header from a name and a value.
The name must implement IntoHeaderType.
The value can be anything that implements AsRef
Example
let header1 = Header::new("Content-Type", "text/html");
let header2 = Header::new("Access-Control-Allow-Origin", "*");sourcepub fn from_string(header: impl AsRef<str>) -> Result<Header>
pub fn from_string(header: impl AsRef<str>) -> Result<Header>
Convert a string to a header.
String must be in the format name: value, or an error will be returned.
Example
let header1 = Header::new(HeaderType::ContentType, "text/html");
let header2 = Header::from_string("Content-Type: text/html").unwrap();
assert_eq!(header1, header2);