Use dereferencing for request parameters
This commit is contained in:
parent
4fde268117
commit
707b5b16e7
2 changed files with 20 additions and 2 deletions
|
@ -63,7 +63,7 @@ fn submit_raw(input: Data, host: HostHeader) -> std::io::Result<String> {
|
||||||
|
|
||||||
let paste = store_paste(data);
|
let paste = store_paste(data);
|
||||||
|
|
||||||
match host.0 {
|
match *host {
|
||||||
Some(host) => Ok(format!("https://{}/{}", host, paste)),
|
Some(host) => Ok(format!("https://{}/{}", host, paste)),
|
||||||
None => Ok(paste)
|
None => Ok(paste)
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ fn render(key: String, plaintext: IsPlaintextRequest) -> Option<Content<String>>
|
||||||
// again so we can hold this for as long as we want
|
// again so we can hold this for as long as we want
|
||||||
let entry = get_paste(key)?;
|
let entry = get_paste(key)?;
|
||||||
|
|
||||||
if plaintext.0 {
|
if *plaintext {
|
||||||
Some(Content(ContentType::Plain, entry))
|
Some(Content(ContentType::Plain, entry))
|
||||||
} else {
|
} else {
|
||||||
Some(Content(ContentType::HTML, Render {
|
Some(Content(ContentType::HTML, Render {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
use rocket::Request;
|
use rocket::Request;
|
||||||
use rocket::request::{FromRequest, Outcome};
|
use rocket::request::{FromRequest, Outcome};
|
||||||
|
|
||||||
|
@ -7,6 +9,14 @@ use rocket::request::{FromRequest, Outcome};
|
||||||
/// and also anything calling us from the console or that we can't identify.
|
/// and also anything calling us from the console or that we can't identify.
|
||||||
pub struct IsPlaintextRequest(pub bool);
|
pub struct IsPlaintextRequest(pub bool);
|
||||||
|
|
||||||
|
impl Deref for IsPlaintextRequest {
|
||||||
|
type Target = bool;
|
||||||
|
|
||||||
|
fn deref(&self) -> &bool {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for IsPlaintextRequest {
|
impl<'a, 'r> FromRequest<'a, 'r> for IsPlaintextRequest {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
|
@ -30,6 +40,14 @@ impl<'a, 'r> FromRequest<'a, 'r> for IsPlaintextRequest {
|
||||||
/// on the request.
|
/// on the request.
|
||||||
pub struct HostHeader<'a>(pub Option<&'a str>);
|
pub struct HostHeader<'a>(pub Option<&'a str>);
|
||||||
|
|
||||||
|
impl<'a> Deref for HostHeader<'a> {
|
||||||
|
type Target = Option<&'a str>;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Option<&'a str> {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for HostHeader<'a> {
|
impl<'a, 'r> FromRequest<'a, 'r> for HostHeader<'a> {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue