Move the far_expires impl to RenderRucte.
This commit is contained in:
parent
cd0911c3e5
commit
001cdc8e80
@ -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,
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user