Move the far_expires impl to RenderRucte.

This commit is contained in:
Rasmus Kaj 2019-04-25 21:43:02 +02:00
parent cd0911c3e5
commit 001cdc8e80
2 changed files with 9 additions and 13 deletions

View File

@ -15,7 +15,7 @@ use crate::env::{dburl, env_or, jwt_key};
use crate::models::{Person, Photo, Place, Tag};
use crate::pidfiles::handle_pid_file;
use crate::templates::{self, Html};
use chrono::{Datelike, Duration, Utc};
use chrono::Datelike;
use clap::ArgMatches;
use diesel::prelude::*;
use djangohashers;
@ -28,18 +28,6 @@ use warp::filters::path::Tail;
use warp::http::{header, Response, StatusCode};
use warp::{self, reply, Filter, Rejection, Reply};
/// Trait to easily add a far expires header to a response builder.
trait FarExpires {
fn far_expires(&mut self) -> &mut Self;
}
impl FarExpires for warp::http::response::Builder {
fn far_expires(&mut self) -> &mut Self {
let far_expires = Utc::now() + Duration::days(180);
self.header(header::EXPIRES, far_expires.to_rfc2822())
}
}
pub struct PhotoLink {
pub title: Option<String>,
pub href: String,

View File

@ -1,6 +1,7 @@
/// This module defines the `RenderRucte` trait for a response builer.
///
/// If ructe gets a warp feature, this is probably it.
use chrono::{Duration, Utc};
use mime::TEXT_HTML_UTF_8;
use std::io::{self, Write};
use warp::http::response::Builder;
@ -12,6 +13,8 @@ pub trait RenderRucte {
F: FnOnce(&mut Write) -> io::Result<()>;
fn redirect(&mut self, url: &str) -> Response<Vec<u8>>;
fn far_expires(&mut self) -> &mut Self;
}
impl RenderRucte for Builder {
@ -31,4 +34,9 @@ impl RenderRucte for Builder {
.body(format!("Please refer to {}", url).into_bytes())
.unwrap()
}
fn far_expires(&mut self) -> &mut Self {
let far_expires = Utc::now() + Duration::days(180);
self.header(header::EXPIRES, far_expires.to_rfc2822())
}
}