rename header to meta

This commit is contained in:
yggverse 2025-02-23 10:19:39 +02:00
parent 7c62a393ed
commit 2d096515d4
6 changed files with 38 additions and 38 deletions

View file

@ -1,11 +1,11 @@
pub const CODE: &[u8] = b"20";
pub struct Header {
pub struct Meta {
pub mime: String,
}
impl Header {
/// Build `Self` from UTF-8 header bytes
impl Meta {
/// Build `Self` from UTF-8 meta bytes
/// * expected buffer includes leading status code, message, CRLF
pub fn from_bytes(buffer: &[u8]) -> Result<Self> {
use crate::Header;
@ -46,10 +46,10 @@ impl Header {
#[test]
fn test() {
const BYTES: &[u8] = "20 text/gemini\r\nDATA".as_bytes();
let header = Header::from_bytes(BYTES).unwrap();
let meta = Meta::from_bytes(BYTES).unwrap();
assert_eq!(header.mime, "text/gemini".to_string());
assert_eq!(header.into_bytes(), BYTES[..BYTES.len() - 4]); // skip DATA
assert_eq!(meta.mime, "text/gemini".to_string());
assert_eq!(meta.into_bytes(), BYTES[..BYTES.len() - 4]); // skip DATA
}
use anyhow::{bail, Result};