mirror of
https://github.com/YGGverse/titanite.git
synced 2026-03-31 09:05:31 +00:00
validate scheme
This commit is contained in:
parent
f90c012543
commit
b8ce8774a3
2 changed files with 9 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use anyhow::Result;
|
||||
use anyhow::{bail, Result};
|
||||
use url::Url;
|
||||
|
||||
/// [Gemini](https://geminiprotocol.net/docs/protocol-specification.gmi) request
|
||||
|
|
@ -9,8 +9,12 @@ pub struct Gemini {
|
|||
impl Gemini {
|
||||
pub fn from_bytes(buffer: &[u8]) -> Result<Self> {
|
||||
use crate::tool::Header;
|
||||
let header = buffer.header_bytes()?;
|
||||
if !header.starts_with(b"gemini://") {
|
||||
bail!("Invalid scheme")
|
||||
}
|
||||
Ok(Self {
|
||||
url: Url::parse(std::str::from_utf8(buffer.header_bytes()?)?)?,
|
||||
url: Url::parse(std::str::from_utf8(header)?)?,
|
||||
})
|
||||
}
|
||||
pub fn into_bytes(self) -> Vec<u8> {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@ impl Meta {
|
|||
use crate::tool::Header;
|
||||
use regex::Regex;
|
||||
let header = from_utf8(buffer.header_bytes()?)?;
|
||||
if !header.starts_with("titan://") {
|
||||
bail!("Invalid scheme")
|
||||
}
|
||||
Ok(Self {
|
||||
size: match Regex::new(r"size=(\d+)")?.captures(header) {
|
||||
Some(c) => match c.get(1) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue