Merge branch 'rework-success' into user-management
This commit is contained in:
commit
a9b347a8c9
|
@ -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<Document>) -> Self {
|
pub fn document(document: impl Borrow<Document>) -> Self {
|
||||||
Self::success_with_body(&GEMINI_MIME, document)
|
Self::success_gemini(document)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn input(prompt: impl Cowy<str>) -> Result<Self> {
|
pub fn input(prompt: impl Cowy<str>) -> Result<Self> {
|
||||||
|
@ -34,27 +38,27 @@ impl Response {
|
||||||
Self::new(header)
|
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<URIReference<'a>>) -> Self {
|
pub fn redirect_temporary_lossy<'a>(location: impl TryInto<URIReference<'a>>) -> Self {
|
||||||
let header = ResponseHeader::redirect_temporary_lossy(location);
|
let header = ResponseHeader::redirect_temporary_lossy(location);
|
||||||
Self::new(header)
|
Self::new(header)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a successful response with a preconfigured body
|
/// Create a successful response with a given body and MIME
|
||||||
///
|
pub fn success(mime: &Mime, body: impl Into<Body>) -> Self {
|
||||||
/// This is equivilent to:
|
Self {
|
||||||
///
|
header: ResponseHeader::success(mime),
|
||||||
/// ```ignore
|
body: Some(body.into()),
|
||||||
/// Response::success(mime)
|
}
|
||||||
/// .with_body(body)
|
}
|
||||||
/// ```
|
|
||||||
pub fn success_with_body(mime: &Mime, body: impl Into<Body>) -> Self {
|
/// Create a successful response with a `text/gemini` MIME
|
||||||
Self::success(mime)
|
pub fn success_gemini(body: impl Into<Body>) -> Self {
|
||||||
.with_body(body)
|
Self::success(&GEMINI_MIME, body)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a successful response with a `text/plain` MIME
|
||||||
|
pub fn success_plain(body: impl Into<Body>) -> Self {
|
||||||
|
Self::success(&mime::TEXT_PLAIN, body)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn server_error(reason: impl Cowy<str>) -> Result<Self> {
|
pub fn server_error(reason: impl Cowy<str>) -> Result<Self> {
|
||||||
|
@ -98,6 +102,6 @@ impl Response {
|
||||||
|
|
||||||
impl<D: Borrow<Document>> From<D> for Response {
|
impl<D: Borrow<Document>> From<D> for Response {
|
||||||
fn from(doc: D) -> Self {
|
fn from(doc: D) -> Self {
|
||||||
Self::document(doc)
|
Self::success_gemini(doc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue