From 4de2f901a549f051c1a03b83fc114d38638dcbfb Mon Sep 17 00:00:00 2001 From: Vika Date: Wed, 2 Mar 2022 23:41:58 +0300 Subject: frontend: convert to warp Warp is using hyperium/http instead of http-types, so I replaced all of the http-types usage (mostly status codes) by Warp's http::StatusCode. Additionally some of the struct fields were made public to allow initialization from public code. --- src/frontend/templates/mod.rs | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'src/frontend/templates') diff --git a/src/frontend/templates/mod.rs b/src/frontend/templates/mod.rs index c21d30b..364a716 100644 --- a/src/frontend/templates/mod.rs +++ b/src/frontend/templates/mod.rs @@ -1,7 +1,7 @@ use crate::database::MicropubChannel; use crate::frontend::IndiewebEndpoints; use ellipse::Ellipse; -use http_types::StatusCode; +use warp::http::StatusCode; use log::error; /// Return a pretty location specifier from a geo: URI. @@ -397,12 +397,12 @@ markup::define! { @Feed { feed } } ErrorPage(code: StatusCode, msg: Option) { - h1 { @format!("HTTP {} {}", code, code.canonical_reason()) } - @match code { - StatusCode::Unauthorized => { + h1 { @format!("HTTP {}", code) } + @match *code { + StatusCode::UNAUTHORIZED => { p { "Looks like you need to authenticate yourself before seeing this page. Try logging in with IndieAuth using the Login button above!" } } - StatusCode::Forbidden => { + StatusCode::FORBIDDEN => { p { "Looks like you're forbidden from viewing this page." } p { "This might've been caused by being banned from viewing my website" @@ -410,16 +410,16 @@ markup::define! { "like a private post that's not intended for you. It's ok, it happens." } } - StatusCode::Gone => { + StatusCode::GONE => { p { "Looks like the page you're trying to find is gone and is never coming back." } } - StatusCode::UnavailableForLegalReasons => { + StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS => { p { "The page is there, but I can't legally provide it to you because the censorship said so." } } - StatusCode::NotFound => { + StatusCode::NOT_FOUND => { p { "Looks like there's no such page. Maybe you or someone else mistyped a URL or my database experienced data loss." } } - StatusCode::ImATeapot => { + StatusCode::IM_A_TEAPOT => { p { "Wait, do you seriously expect my website to brew you coffee? It's not a coffee machine!" } p { @@ -433,16 +433,18 @@ markup::define! { } } } - StatusCode::BadRequest => { - @if msg.is_none() { - p { - "There was an undescribed error in your request. " - "Please try again later or with a different request." + StatusCode::BAD_REQUEST => { + @match msg { + None => { + p { + "There was an undescribed error in your request. " + "Please try again later or with a different request." + } } - } else { - p { - "There was a following error in your request: " - @msg.as_ref().unwrap() + Some(msg) => { + p { + "There was a following error in your request: " @msg + } } } } -- cgit 1.4.1