Merge branch 'feature/cow'

This commit is contained in:
Valentin Brandl 2019-08-07 20:41:23 +02:00
commit 9ae990e9c8
No known key found for this signature in database
GPG Key ID: 30D341DD34118D7D
4 changed files with 15 additions and 11 deletions

View File

@ -15,7 +15,7 @@ lazy_static = "1.3.0"
mime_guess = "1.8.7"
openssl-probe = "0.1.2"
pretty_env_logger = "0.3.0"
serde = "1.0.97"
serde = { version = "1.0.97", features = ["rc"] }
serde_derive = "1.0.97"
serde_json = "1.0.40"
structopt = "0.2.18"

View File

@ -1,6 +1,7 @@
use std::{
collections::HashMap,
hash::Hash,
sync::Arc,
time::{Duration, Instant},
};
@ -67,7 +68,7 @@ impl<T> CacheEntry<T> {
}
#[derive(Eq, PartialEq, Hash, Debug)]
pub(crate) struct Key(Service, String, String, String);
pub(crate) struct Key(Service, Arc<String>, Arc<String>, Arc<String>);
#[derive(Eq, PartialEq, Hash, Debug)]
pub(crate) enum Service {
@ -77,7 +78,12 @@ pub(crate) enum Service {
}
impl Key {
pub(crate) fn new(service: Service, user: String, repo: String, branch: String) -> Self {
pub(crate) fn new(
service: Service,
user: Arc<String>,
repo: Arc<String>,
branch: Arc<String>,
) -> Self {
Key(service, user, repo, branch)
}
}

View File

@ -8,10 +8,10 @@ pub(crate) type State = Arc<RwLock<Cache<Key, String>>>;
#[derive(Deserialize, Debug)]
pub(crate) struct FilePath {
pub(crate) user: String,
pub(crate) repo: String,
pub(crate) commit: String,
pub(crate) file: String,
pub(crate) user: Arc<String>,
pub(crate) repo: Arc<String>,
pub(crate) commit: Arc<String>,
pub(crate) file: Arc<String>,
}
impl FilePath {

View File

@ -7,8 +7,6 @@ extern crate serde_derive;
#[macro_use]
extern crate structopt;
// TODO: cow instead of string
mod cache;
mod cdn;
mod config;
@ -51,7 +49,7 @@ fn proxy_file<T: Service>(
.from_err()
.and_then(move |response| match response.status() {
StatusCode::OK => {
let mime = mime_guess::guess_mime_type(&data.file);
let mime = mime_guess::guess_mime_type(&*data.file);
Ok(HttpResponse::Ok()
.content_type(mime.to_string().as_str())
.set(CacheControl(vec![
@ -134,7 +132,7 @@ fn serve_gist(
.from_err()
.and_then(move |response| match response.status() {
StatusCode::OK => {
let mime = mime_guess::guess_mime_type(&data.file);
let mime = mime_guess::guess_mime_type(&*data.file);
Ok(HttpResponse::Ok()
.content_type(mime.to_string().as_str())
.set(CacheControl(vec![