47 lines
1.1 KiB
Rust
47 lines
1.1 KiB
Rust
use std::str::FromStr;
|
|||
|
|
|
||
|
|
#[derive(Debug)]
|
||
|
|
pub(crate) struct ReqLine {
|
||
|
|
pub(crate) method: String,
|
||
|
|
pub(crate) route: String,
|
||
|
|
pub(crate) version: String,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl FromStr for ReqLine {
|
||
|
|
type Err = std::io::Error;
|
||
|
|
|
||
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||
|
|
let (method, rest) = s
|
||
|
|
.split_once(" ")
|
||
|
|
.ok_or(std::io::Error::other("Missing route"))?;
|
||
|
|
let (route, version) = rest
|
||
|
|
.split_once(" ")
|
||
|
|
.ok_or(std::io::Error::other("Missing version"))?;
|
||
|
|
Ok(Self {
|
||
|
|
method: method.trim().to_string(),
|
||
|
|
route: route.trim().to_string(),
|
||
|
|
version: version.trim().to_string(),
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug)]
|
||
|
|
pub(crate) struct Header {
|
||
|
|
pub(crate) key: String,
|
||
|
|
pub(crate) value: String,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl FromStr for Header {
|
||
|
|
type Err = std::io::Error;
|
||
|
|
|
||
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||
|
|
let (key, value) = s
|
||
|
|
.split_once(":")
|
||
|
|
.ok_or(std::io::Error::other("Missing value"))?;
|
||
|
|
Ok(Self {
|
||
|
|
key: key.trim().to_string(),
|
||
|
|
value: value.trim().to_string(),
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|