Add gemtext helpers for headers and responses

[?]
Jan 8, 2021, 9:09 AM
7DH43OFGO4RVLW3LL23FZDMXRHQLAEMK7VD62T7FZBRHZOF3RRDAC

Dependencies

  • [2] BOFUYB6I Add documentation and implement some feedback from Discord (https://discord.com/channels/273534239310479360/354038657075904544/796256815024701480)
  • [3] 5II6T7YE Add gemini library

Change contents

  • edit in gemini/src/response.rs at line 9
    [2.10851]
    [2.10851]
    gemtext::Builder,
  • edit in gemini/src/response.rs at line 43
    [3.5971]
    [3.5971]
    // TODO: add some built-in mime-types for more infallible constructors?
  • replacement in gemini/src/response.rs at line 47
    [2.11542][2.11542:11650]()
    pub fn with_body(header: Header, body: Vec<u8>) -> Option<Self> {
    Self::new(header, Some(body))
    [2.11542]
    [3.6070]
    pub fn with_body(mime_type: String, body: Vec<u8>) -> Option<Self> {
    let header = Header::new(Status::SUCCESS, mime_type)?;
    let body = Some(body);
    Some(Response { header, body })
    }
    /// Construct a new response with a gemtext body.
    pub fn with_gemtext(builder: Builder) -> Self {
    let header = Header::gemtext();
    let body = Some(builder.build().bytes().collect());
    Self::new_unchecked(header, body)
  • replacement in gemini/src/header.rs at line 78
    [3.9229][3.9229:9482]()
    MetaKind::MimeType => Some({
    let meta = self.meta();
    if meta.trim().is_empty() {
    Self::DEFAULT_MIME_TYPE
    } else {
    meta
    }
    }),
    [3.9229]
    [3.9482]
    MetaKind::MimeType => Some(self.meta()),
  • edit in gemini/src/header.rs at line 89
    [3.9630]
    [3.9630]
    let meta = match status {
    Status::SUCCESS if meta.trim().is_empty() => Self::DEFAULT_MIME_TYPE.to_string(),
    _ => meta,
    };
  • edit in gemini/src/header.rs at line 98
    [3.9722]
    [3.9722]
    /// Construct a `Status::SUCCESS` header with the given mime-type.
    pub fn success(mime_type: String) -> Option<Self> {
    Self::new(Status::SUCCESS, mime_type)
    }
    /// Construct a `Status::SUCCESS` header with the text/gemini mime-type.
    pub fn gemtext() -> Self {
    let status = Status::SUCCESS;
    let meta = Self::DEFAULT_MIME_TYPE.to_string();
    Header { status, meta }
    }