🏡 index : ~doyle/bin.git

author Jordan Johnson-Doyle <jordan@doyle.la> 2019-02-13 21:52:17.0 +00:00:00
committer Jordan Johnson-Doyle <jordan@doyle.la> 2019-02-13 21:52:17.0 +00:00:00
commit
707b5b16e7dda6161179bcffab4ed1d858b1630f [patch]
tree
e5d63d10bf3ac0eea80bef4f4f5da64132d6a47e
parent
4fde2681173c2f8ba1d255535661f76cd83d7f2c
download
707b5b16e7dda6161179bcffab4ed1d858b1630f.tar.gz

Use dereferencing for request parameters



Diff

 src/main.rs   |  4 ++--
 src/params.rs | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 84361e5..c8e08f0 100644
--- a/src/main.rs
+++ a/src/main.rs
@@ -63,7 +63,7 @@

    let paste = store_paste(data);

    match host.0 {
    match *host {
        Some(host) => Ok(format!("https://{}/{}", host, paste)),
        None => Ok(paste)
    }
@@ -90,7 +90,7 @@
    // again so we can hold this for as long as we want
    let entry = get_paste(key)?;

    if plaintext.0 {
    if *plaintext {
        Some(Content(ContentType::Plain, entry))
    } else {
        Some(Content(ContentType::HTML, Render {
diff --git a/src/params.rs b/src/params.rs
index e8b7930..7e8902a 100644
--- a/src/params.rs
+++ a/src/params.rs
@@ -1,3 +1,5 @@
use std::ops::Deref;

use rocket::Request;
use rocket::request::{FromRequest, Outcome};

@@ -6,6 +8,14 @@
/// We assume anything with the text/plain Accept or Content-Type headers want plaintext,
/// and also anything calling us from the console or that we can't identify.
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 {
    type Error = ();
@@ -29,6 +39,14 @@
/// The inner value of this `HostHeader` will be `None` if there was no Host header
/// on the request.
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> {
    type Error = ();