Merge branch 'feature/cow'
This commit is contained in:
commit
9ae990e9c8
@ -15,7 +15,7 @@ lazy_static = "1.3.0"
|
|||||||
mime_guess = "1.8.7"
|
mime_guess = "1.8.7"
|
||||||
openssl-probe = "0.1.2"
|
openssl-probe = "0.1.2"
|
||||||
pretty_env_logger = "0.3.0"
|
pretty_env_logger = "0.3.0"
|
||||||
serde = "1.0.97"
|
serde = { version = "1.0.97", features = ["rc"] }
|
||||||
serde_derive = "1.0.97"
|
serde_derive = "1.0.97"
|
||||||
serde_json = "1.0.40"
|
serde_json = "1.0.40"
|
||||||
structopt = "0.2.18"
|
structopt = "0.2.18"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
|
sync::Arc,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -67,7 +68,7 @@ impl<T> CacheEntry<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Hash, Debug)]
|
#[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)]
|
#[derive(Eq, PartialEq, Hash, Debug)]
|
||||||
pub(crate) enum Service {
|
pub(crate) enum Service {
|
||||||
@ -77,7 +78,12 @@ pub(crate) enum Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Key {
|
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)
|
Key(service, user, repo, branch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,10 @@ pub(crate) type State = Arc<RwLock<Cache<Key, String>>>;
|
|||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub(crate) struct FilePath {
|
pub(crate) struct FilePath {
|
||||||
pub(crate) user: String,
|
pub(crate) user: Arc<String>,
|
||||||
pub(crate) repo: String,
|
pub(crate) repo: Arc<String>,
|
||||||
pub(crate) commit: String,
|
pub(crate) commit: Arc<String>,
|
||||||
pub(crate) file: String,
|
pub(crate) file: Arc<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FilePath {
|
impl FilePath {
|
||||||
|
@ -7,8 +7,6 @@ extern crate serde_derive;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate structopt;
|
extern crate structopt;
|
||||||
|
|
||||||
// TODO: cow instead of string
|
|
||||||
|
|
||||||
mod cache;
|
mod cache;
|
||||||
mod cdn;
|
mod cdn;
|
||||||
mod config;
|
mod config;
|
||||||
@ -51,7 +49,7 @@ fn proxy_file<T: Service>(
|
|||||||
.from_err()
|
.from_err()
|
||||||
.and_then(move |response| match response.status() {
|
.and_then(move |response| match response.status() {
|
||||||
StatusCode::OK => {
|
StatusCode::OK => {
|
||||||
let mime = mime_guess::guess_mime_type(&data.file);
|
let mime = mime_guess::guess_mime_type(&*data.file);
|
||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_type(mime.to_string().as_str())
|
.content_type(mime.to_string().as_str())
|
||||||
.set(CacheControl(vec![
|
.set(CacheControl(vec![
|
||||||
@ -134,7 +132,7 @@ fn serve_gist(
|
|||||||
.from_err()
|
.from_err()
|
||||||
.and_then(move |response| match response.status() {
|
.and_then(move |response| match response.status() {
|
||||||
StatusCode::OK => {
|
StatusCode::OK => {
|
||||||
let mime = mime_guess::guess_mime_type(&data.file);
|
let mime = mime_guess::guess_mime_type(&*data.file);
|
||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_type(mime.to_string().as_str())
|
.content_type(mime.to_string().as_str())
|
||||||
.set(CacheControl(vec![
|
.set(CacheControl(vec![
|
||||||
|
Loading…
Reference in New Issue
Block a user