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;
|
use url::Url;
|
||||||
|
|
||||||
/// [Gemini](https://geminiprotocol.net/docs/protocol-specification.gmi) request
|
/// [Gemini](https://geminiprotocol.net/docs/protocol-specification.gmi) request
|
||||||
|
|
@ -9,8 +9,12 @@ pub struct Gemini {
|
||||||
impl Gemini {
|
impl Gemini {
|
||||||
pub fn from_bytes(buffer: &[u8]) -> Result<Self> {
|
pub fn from_bytes(buffer: &[u8]) -> Result<Self> {
|
||||||
use crate::tool::Header;
|
use crate::tool::Header;
|
||||||
|
let header = buffer.header_bytes()?;
|
||||||
|
if !header.starts_with(b"gemini://") {
|
||||||
|
bail!("Invalid scheme")
|
||||||
|
}
|
||||||
Ok(Self {
|
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> {
|
pub fn into_bytes(self) -> Vec<u8> {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,9 @@ impl Meta {
|
||||||
use crate::tool::Header;
|
use crate::tool::Header;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
let header = from_utf8(buffer.header_bytes()?)?;
|
let header = from_utf8(buffer.header_bytes()?)?;
|
||||||
|
if !header.starts_with("titan://") {
|
||||||
|
bail!("Invalid scheme")
|
||||||
|
}
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
size: match Regex::new(r"size=(\d+)")?.captures(header) {
|
size: match Regex::new(r"size=(\d+)")?.captures(header) {
|
||||||
Some(c) => match c.get(1) {
|
Some(c) => match c.get(1) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue