I dunno
This commit is contained in:
parent
943ff8eb45
commit
e209abe7a0
2 changed files with 36 additions and 2 deletions
|
|
@ -21,7 +21,7 @@ pub enum RequestHeader {
|
|||
Host(String),
|
||||
UserAgent(String),
|
||||
ContentType(ContentType),
|
||||
Accept((String, String)),
|
||||
Accept(ContentType),
|
||||
Other(String, String),
|
||||
}
|
||||
|
||||
|
|
@ -29,7 +29,25 @@ impl FromStr for RequestHeader {
|
|||
type Err = io::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let
|
||||
let header_split: Vec<&str> = s.split(": ").collect();
|
||||
|
||||
match header_split.as_slice() {
|
||||
[header_type, value] => match *header_type {
|
||||
"Host" => Ok(RequestHeader::Host(value.to_string())),
|
||||
"UserAgent" => Ok(RequestHeader::UserAgent(value.to_string())),
|
||||
"ContentType" => Ok(RequestHeader::ContentType(ContentType::from_str(value)?)),
|
||||
"Accept" => Ok(RequestHeader::Accept(ContentType::from_str(value)?)),
|
||||
|
||||
_ => Ok(RequestHeader::Other(
|
||||
header_type.to_string(),
|
||||
value.to_string(),
|
||||
)),
|
||||
},
|
||||
_ => Err(io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
"Invalid header-type",
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,30 @@
|
|||
use std::{io, str::FromStr};
|
||||
|
||||
pub enum ContentType {
|
||||
Text(TextType),
|
||||
Aplication(ApplicationType),
|
||||
Any,
|
||||
}
|
||||
|
||||
impl FromStr for ContentType {
|
||||
type Err = io::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
"Invalid content-type",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub enum TextType {
|
||||
Html,
|
||||
Css,
|
||||
Javascript,
|
||||
Any,
|
||||
}
|
||||
|
||||
pub enum ApplicationType {
|
||||
Json,
|
||||
Any,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue