diff --git a/src/types/response.rs b/src/types/response.rs index dceec4e..fe8326f 100644 --- a/src/types/response.rs +++ b/src/types/response.rs @@ -20,8 +20,12 @@ impl Response { } } + #[deprecated( + since = "0.4.0", + note = "Deprecated in favor of Response::success_gemini() or Document::into()" + )] pub fn document(document: impl Borrow) -> Self { - Self::success_with_body(&GEMINI_MIME, document) + Self::success_gemini(document) } pub fn input(prompt: impl Cowy) -> Result { @@ -34,27 +38,27 @@ impl Response { Self::new(header) } - pub fn success(mime: &Mime) -> Self { - let header = ResponseHeader::success(mime); - Self::new(header) - } - pub fn redirect_temporary_lossy<'a>(location: impl TryInto>) -> Self { let header = ResponseHeader::redirect_temporary_lossy(location); Self::new(header) } - /// Create a successful response with a preconfigured body - /// - /// This is equivilent to: - /// - /// ```ignore - /// Response::success(mime) - /// .with_body(body) - /// ``` - pub fn success_with_body(mime: &Mime, body: impl Into) -> Self { - Self::success(mime) - .with_body(body) + /// Create a successful response with a given body and MIME + pub fn success(mime: &Mime, body: impl Into) -> Self { + Self { + header: ResponseHeader::success(mime), + body: Some(body.into()), + } + } + + /// Create a successful response with a `text/gemini` MIME + pub fn success_gemini(body: impl Into) -> Self { + Self::success(&GEMINI_MIME, body) + } + + /// Create a successful response with a `text/plain` MIME + pub fn success_plain(body: impl Into) -> Self { + Self::success(&mime::TEXT_PLAIN, body) } pub fn server_error(reason: impl Cowy) -> Result { @@ -98,6 +102,6 @@ impl Response { impl> From for Response { fn from(doc: D) -> Self { - Self::document(doc) + Self::success_gemini(doc) } }