Redirect on invalid UTF-8 in /p/
Previously, uploading a paste with invalid UTF-8 and then viewing it with the pretty URL would cause a panic. With this change, it simply redirects to the raw URL.
This commit is contained in:
parent
ea144a1024
commit
5aafe2500a
5 changed files with 63 additions and 9 deletions
31
src/models/maybe_redirect.rs
Normal file
31
src/models/maybe_redirect.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use rocket::{
|
||||
request::Request,
|
||||
response::{Redirect, Responder, Result},
|
||||
};
|
||||
use rocket_dyn_templates::Template;
|
||||
|
||||
pub enum MaybeRedirect {
|
||||
Redirect(Box<Redirect>),
|
||||
Template(Box<Template>),
|
||||
}
|
||||
|
||||
impl From<Redirect> for MaybeRedirect {
|
||||
fn from(other: Redirect) -> Self {
|
||||
Self::Redirect(Box::new(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Template> for MaybeRedirect {
|
||||
fn from(other: Template) -> Self {
|
||||
Self::Template(Box::new(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r, 'o: 'r> Responder<'r, 'o> for MaybeRedirect {
|
||||
fn respond_to(self, req: &'r Request<'_>) -> Result<'o> {
|
||||
match self {
|
||||
Self::Template(t) => t.respond_to(req),
|
||||
Self::Redirect(r) => r.respond_to(req),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue