mirror of https://git.sr.ht/~garritfra/taurus
Garrit Franke
4 years ago
2 changed files with 31 additions and 29 deletions
@ -0,0 +1,28 @@
|
||||
use url::Url; |
||||
|
||||
pub struct GeminiRequest { |
||||
path: Url, |
||||
} |
||||
|
||||
impl GeminiRequest { |
||||
pub fn from_string(request: &str) -> Result<Self, String> { |
||||
let gemini_request = GeminiRequest { |
||||
path: Url::parse(&parse_path(request).ok_or("Invalid path")?.to_string()) |
||||
.map_err(|e| e.to_string())?, |
||||
}; |
||||
|
||||
Ok(gemini_request) |
||||
} |
||||
|
||||
pub fn file_path(&self) -> Option<&str> { |
||||
self.path |
||||
.path() |
||||
.chars() |
||||
.next() |
||||
.map(|c| &self.path.path()[c.len_utf8()..]) |
||||
} |
||||
} |
||||
|
||||
fn parse_path(req: &str) -> Option<&str> { |
||||
req.split("\r\n").next() |
||||
} |
Loading…
Reference in new issue