mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
fix undefined mime type detection
This commit is contained in:
parent
7215258a71
commit
c1c06667c9
1 changed files with 14 additions and 11 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
//! MIME type parser for different data types:
|
//! MIME type parser for different data types:
|
||||||
//!
|
//!
|
||||||
//! * UTF-8 buffer with entire response or just with meta slice (that include **header**)
|
//! * UTF-8 buffer with entire response or just with meta slice (that include entire **header**)
|
||||||
//! * String (that include **header**)
|
//! * String (that include **header**)
|
||||||
//! * [Uri](https://docs.gtk.org/glib/struct.Uri.html) (that include **extension**)
|
//! * [Uri](https://docs.gtk.org/glib/struct.Uri.html) (that include **extension**)
|
||||||
//! * `std::Path` (that include **extension**)
|
//! * `std::Path` (that include **extension**)
|
||||||
|
|
@ -30,10 +30,12 @@ pub enum Mime {
|
||||||
} // @TODO
|
} // @TODO
|
||||||
|
|
||||||
impl Mime {
|
impl Mime {
|
||||||
/// Create new `Self` from UTF-8 buffer
|
/// Create new `Self` from UTF-8 buffer (that includes **header**)
|
||||||
///
|
///
|
||||||
/// * result could be `None` for some [status codes](https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes) that does not expect MIME type in header
|
/// * result could be `None` for some [status codes](https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes)
|
||||||
/// * includes `Self::from_string` parser, it means that given buffer should contain some **header** (not filepath or any other type of strings)
|
/// that does not expect MIME type in header
|
||||||
|
/// * includes `Self::from_string` parser,
|
||||||
|
/// it means that given buffer should contain some **header** (not filepath or any other type of strings)
|
||||||
pub fn from_utf8(buffer: &[u8]) -> Result<Option<Self>, Error> {
|
pub fn from_utf8(buffer: &[u8]) -> Result<Option<Self>, Error> {
|
||||||
// Define max buffer length for this method
|
// Define max buffer length for this method
|
||||||
const MAX_LEN: usize = 0x400; // 1024
|
const MAX_LEN: usize = 0x400; // 1024
|
||||||
|
|
@ -75,8 +77,10 @@ impl Mime {
|
||||||
|
|
||||||
/// Create new `Self` from string that includes **header**
|
/// Create new `Self` from string that includes **header**
|
||||||
///
|
///
|
||||||
/// * result could be `None` for some [status codes](https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes)
|
/// **Return**
|
||||||
/// that does not expect MIME type
|
///
|
||||||
|
/// * `None` if MIME type not found
|
||||||
|
/// * `Error::Undefined` if status code 2* and type not found in `Mime` enum
|
||||||
pub fn from_string(value: &str) -> Result<Option<Self>, Error> {
|
pub fn from_string(value: &str) -> Result<Option<Self>, Error> {
|
||||||
// Text
|
// Text
|
||||||
if value.contains("text/gemini") {
|
if value.contains("text/gemini") {
|
||||||
|
|
@ -121,14 +125,13 @@ impl Mime {
|
||||||
return Ok(Some(Self::AudioOgg));
|
return Ok(Some(Self::AudioOgg));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some type exist, but not defined yet
|
// Some type exist, but not defined yet (on status code is 2*)
|
||||||
/* @TODO unstable
|
if value.starts_with("2") && value.contains("/") {
|
||||||
if value.contains("/") {
|
|
||||||
return Err(Error::Undefined);
|
return Err(Error::Undefined);
|
||||||
} */
|
}
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
Ok(None) // may be empty (for some status codes)
|
Ok(None) // may be empty (status code ^2*)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create new `Self` from [Uri](https://docs.gtk.org/glib/struct.Uri.html)
|
/// Create new `Self` from [Uri](https://docs.gtk.org/glib/struct.Uri.html)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue