mirror of
https://git.asonix.dog/asonix/relay.git
synced 2024-11-22 09:31:07 +00:00
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::Arbiter;
|
||||||
use actix_web::{middleware::Logger, web, App, HttpServer};
|
use actix_web::{
|
||||||
|
middleware::{Compress, Logger},
|
||||||
|
web, App, HttpServer,
|
||||||
|
};
|
||||||
|
|
||||||
mod apub;
|
mod apub;
|
||||||
mod args;
|
mod args;
|
||||||
|
@ -112,6 +115,7 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
|
|
||||||
App::new()
|
App::new()
|
||||||
.wrap(Logger::default())
|
.wrap(Logger::default())
|
||||||
|
.wrap(Compress::default())
|
||||||
.data(db.clone())
|
.data(db.clone())
|
||||||
.data(state.clone())
|
.data(state.clone())
|
||||||
.data(state.requests())
|
.data(state.requests())
|
||||||
|
|
|
@ -3,7 +3,7 @@ use activitystreams::primitives::XsdAnyUri;
|
||||||
use actix_web::client::Client;
|
use actix_web::client::Client;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use http_signature_normalization_actix::prelude::*;
|
use http_signature_normalization_actix::prelude::*;
|
||||||
use log::error;
|
use log::{error, info};
|
||||||
use rsa::{hash::Hashes, padding::PaddingScheme, RSAPrivateKey};
|
use rsa::{hash::Hashes, padding::PaddingScheme, RSAPrivateKey};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ impl Requests {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_bytes(&self, url: &str) -> Result<(String, Bytes), MyError> {
|
pub async fn fetch_bytes(&self, url: &str) -> Result<(String, Bytes), MyError> {
|
||||||
|
info!("Fetching bytes for {}", url);
|
||||||
let mut res = self
|
let mut res = self
|
||||||
.client
|
.client
|
||||||
.get(url)
|
.get(url)
|
||||||
|
|
|
@ -20,7 +20,10 @@ pub async fn route(
|
||||||
.store_bytes(uuid, content_type.clone(), bytes.clone())
|
.store_bytes(uuid, content_type.clone(), bytes.clone())
|
||||||
.await;
|
.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())
|
Ok(HttpResponse::NotFound().finish())
|
||||||
|
|
Loading…
Reference in a new issue