forked from mirrors/relay
Compress responses, cache images, log requests
This commit is contained in:
parent
9ada30626b
commit
7e9779aa4a
3 changed files with 11 additions and 3 deletions
|
@ -1,5 +1,8 @@
|
|||
use actix::Arbiter;
|
||||
use actix_web::{middleware::Logger, web, App, HttpServer};
|
||||
use actix_web::{
|
||||
middleware::{Compress, Logger},
|
||||
web, App, HttpServer,
|
||||
};
|
||||
|
||||
mod apub;
|
||||
mod args;
|
||||
|
@ -112,6 +115,7 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
|
||||
App::new()
|
||||
.wrap(Logger::default())
|
||||
.wrap(Compress::default())
|
||||
.data(db.clone())
|
||||
.data(state.clone())
|
||||
.data(state.requests())
|
||||
|
|
|
@ -3,7 +3,7 @@ use activitystreams::primitives::XsdAnyUri;
|
|||
use actix_web::client::Client;
|
||||
use bytes::Bytes;
|
||||
use http_signature_normalization_actix::prelude::*;
|
||||
use log::error;
|
||||
use log::{error, info};
|
||||
use rsa::{hash::Hashes, padding::PaddingScheme, RSAPrivateKey};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
|
@ -65,6 +65,7 @@ impl Requests {
|
|||
}
|
||||
|
||||
pub async fn fetch_bytes(&self, url: &str) -> Result<(String, Bytes), MyError> {
|
||||
info!("Fetching bytes for {}", url);
|
||||
let mut res = self
|
||||
.client
|
||||
.get(url)
|
||||
|
|
|
@ -20,7 +20,10 @@ pub async fn route(
|
|||
.store_bytes(uuid, content_type.clone(), bytes.clone())
|
||||
.await;
|
||||
|
||||
return Ok(HttpResponse::Ok().content_type(content_type).body(bytes));
|
||||
return Ok(HttpResponse::Ok()
|
||||
.content_type(content_type)
|
||||
.header("Cache-Control", "public, max-age=1200, immutable")
|
||||
.body(bytes));
|
||||
}
|
||||
|
||||
Ok(HttpResponse::NotFound().finish())
|
||||
|
|
Loading…
Reference in a new issue