Skip to content

Commit

Permalink
fix: use local addr for cache refresh'
Browse files Browse the repository at this point in the history
  • Loading branch information
lostb1t committed Aug 14, 2023
1 parent 476184c commit ebd9c0e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ docker-run:


run:
REPLEX_PORT=80 REPLEX_INCLUDE_WATCHED=0 REPLEX_REDIRECT_STREAMS=0 REPLEX_DISABLE_RELATED=1 REPLEX_DISABLE_LEAF_COUNT=0 REPLEX_DISABLE_USER_STATE=1 REPLEX_ENABLE_CONSOLE=0 REPLEX_CACHE_TTL=25 REPLEX_HOST=https://46-4-30-217.01b0839de64b49138531cab1bf32f7c2.plex.direct:42405 RUST_LOG="info,replex=debug" cargo watch -x run
REPLEX_PORT=80 REPLEX_INCLUDE_WATCHED=0 REPLEX_REDIRECT_STREAMS=0 REPLEX_DISABLE_RELATED=1 REPLEX_DISABLE_LEAF_COUNT=0 REPLEX_DISABLE_USER_STATE=1 REPLEX_ENABLE_CONSOLE=0 REPLEX_CACHE_TTL=5 REPLEX_HOST=https://46-4-30-217.01b0839de64b49138531cab1bf32f7c2.plex.direct:42405 RUST_LOG="info,replex=debug" cargo watch -x run

# run:
# REPLEX_ENABLE_CONSOLE=0 REPLEX_CACHE_TTL=0 REPLEX_HOST=https://46-4-30-217.01b0839de64b49138531cab1bf32f7c2.plex.direct:42405 RUST_LOG="info" cargo run
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ Settings are set via [environment variables](https://kinsta.com/knowledgebase/wh
| REPLEX_REDIRECT_STREAMS | false | Redirect streams to another endpoint. |
| REPLEX_REDIRECT_STREAMS_URL | REPLEX_HOST | Alternative streams endpoint |
| REPLEX_DISABLE_RELATED | false | See: https://github.com/sarendsen/replex/issues/26. |
| REPLEX_SSL_ENABLE | false | Enable automatic SSL generation. http will be disabled |
| | | (stored in /data/acme/letsencrypt so make sure to mount a volume) |
| REPLEX_SSL_DOMAIN | | Domain to request SSL certificate for when REPLEX_SSL_ENABLE is enabled |
Note: Automatic SSl is untested
## Mixed rows
Expand Down
40 changes: 26 additions & 14 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ impl CacheManager {
}

pub struct RequestIssuer {
use_scheme: bool,
// use_scheme: bool,
use_authority: bool,
use_local_addr: bool,
use_path: bool,
use_query: bool,
use_method: bool,
Expand All @@ -161,8 +162,9 @@ impl RequestIssuer {
/// Create a new `RequestIssuer`.
pub fn new() -> Self {
Self {
use_scheme: true,
use_authority: true,
// use_scheme: true,
use_authority: false,
use_local_addr: true,
use_path: true,
use_query: true,
use_method: true,
Expand All @@ -172,15 +174,19 @@ impl RequestIssuer {
}
}
/// Whether to use request's uri scheme when generate the key.
pub fn use_scheme(mut self, value: bool) -> Self {
self.use_scheme = value;
self
}
// pub fn use_scheme(mut self, value: bool) -> Self {
// self.use_scheme = value;
// self
// }
/// Whether to use request's uri authority when generate the key.
pub fn use_authority(mut self, value: bool) -> Self {
self.use_authority = value;
self
}
pub fn use_local_addr(mut self, value: bool) -> Self {
self.use_local_addr = value;
self
}
/// Whether to use request's uri path when generate the key.
pub fn use_path(mut self, value: bool) -> Self {
self.use_path = value;
Expand Down Expand Up @@ -215,18 +221,23 @@ impl CacheIssuer for RequestIssuer {
_depot: &Depot,
) -> Option<Self::Key> {
let mut key = String::new();
key.push_str("uri::");
if self.use_scheme {
if let Some(scheme) = req.uri().scheme_str() {
key.push_str(scheme);
key.push_str("://");
}
}
key.push_str("uri::http://"); // always http as we use local addr
// if self.use_scheme {
// if let Some(scheme) = req.uri().scheme_str() {
// key.push_str(scheme);
// key.push_str("://");
// }
// }
if self.use_authority {
if let Some(authority) = req.uri().authority() {
key.push_str(authority.as_str());
}
}
if self.use_local_addr {
// key.push_str(format!("{}", req.local_addr().into()));
// dbg!(format!("{}", req.local_addr()));
key.push_str(req.local_addr().to_string().replace("socket://", "").as_str());
}
if self.use_path {
key.push_str(req.uri().path());
}
Expand Down Expand Up @@ -255,6 +266,7 @@ impl CacheIssuer for RequestIssuer {
key.push_str("|X-Plex-Language::");
key.push_str(req.header("X-Plex-Language").unwrap());
}
dbg!(&key);
Some(key)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub struct Config {
}

fn default_cache_ttl() -> u64 {
5 * 60
15 * 60 // 15 minutes
}

// fn default_port() -> u64 {
Expand Down

0 comments on commit ebd9c0e

Please sign in to comment.