From 1f010074fa51adfbf0bc219467491015cbec859a Mon Sep 17 00:00:00 2001 From: Valentin Brandl Date: Thu, 18 Apr 2019 14:45:57 +0200 Subject: [PATCH] Set expiry header to 60 seconds Closes #9 --- src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index aee5dcd..618c878 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,11 @@ #[macro_use] extern crate actix_web; -use actix_web::{error, http, middleware, web, App, HttpResponse, HttpServer, ResponseError}; +use actix_web::{ + error, + http::{self, header::Expires}, + middleware, web, App, HttpResponse, HttpServer, ResponseError, +}; use badge::{Badge, BadgeOptions}; use bytes::Bytes; use futures::{unsync::mpsc, Stream}; @@ -10,6 +14,7 @@ use std::{ path::{Path, PathBuf}, process::Command, sync::Arc, + time::{Duration, SystemTime}, }; use structopt::StructOpt; @@ -146,8 +151,10 @@ fn calculate_hoc( let (tx, rx_body) = mpsc::unbounded(); let _ = tx.unbounded_send(Bytes::from(badge.to_svg().as_bytes())); + let expiration = SystemTime::now() + Duration::from_secs(60); Ok(HttpResponse::Ok() .content_type("image/svg+xml") + .set(Expires(expiration.into())) .streaming(rx_body.map_err(|_| error::ErrorBadRequest("bad request")))) }