Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature parity with legacy ytproxy #18

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ optimized = ["libwebp-sys?/sse41", "libwebp-sys?/avx2", "libwebp-sys?/neon"]

qhash = ["blake3"]

prefix-path = []

[profile.release]
lto = true
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ fn is_header_allowed(header: &str) -> bool {
!matches!(
header,
"host"
| "authorization"
| "cookie"
| "etag"
| "content-length"
| "set-cookie"
| "alt-svc"
Expand Down
33 changes: 30 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ use qstring::QString;
use reqwest::Url;
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::env;

#[cfg(feature = "prefix-path")]
{
use once_cell::sync::Lazy;
static PREFIX_PATH: Lazy<Option<String>> = Lazy::new(|| match env::var("PREFIX_PATH") {
Ok(v) => Some(String::from(v)),
Err(e) => panic!("$PREFIX_PATH is not set ({})", e)
});
}

pub fn read_buf(buf: &[u8], pos: &mut usize) -> u8 {
let byte = buf[*pos];
Expand All @@ -13,7 +23,6 @@ fn finalize_url(path: &str, query: BTreeMap<String, String>) -> String {
#[cfg(feature = "qhash")]
{
use std::collections::BTreeSet;
use std::env;

let qhash = {
let secret = env::var("HASH_SECRET");
Expand Down Expand Up @@ -46,12 +55,30 @@ fn finalize_url(path: &str, query: BTreeMap<String, String>) -> String {
if qhash.is_some() {
let mut query = QString::new(query.into_iter().collect::<Vec<_>>());
query.add_pair(("qhash", qhash.unwrap()));
return format!("{}?{}", path, query);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need feature specific code for when prefix-path enabled and not.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @FireMasterK , please let me know if my solution is what you meant. thanks

#[cfg(not(feature = "prefix-path"))]
{
return format!("{}?{}", path, query);
}


#[cfg(feature = "prefix-path")]
{
return format!("{}{}?{}", PREFIX_PATH.as_ref().unwrap().to_string(), path, query);
}
}
}

let query = QString::new(query.into_iter().collect::<Vec<_>>());
format!("{}?{}", path, query)
#[cfg(not(feature = "prefix-path"))]
{
format!("{}?{}", path, query)
}


#[cfg(feature = "prefix-path")]
{
format!("{}{}?{}", PREFIX_PATH.as_ref().unwrap().to_string(), path, query)
}
}

pub fn localize_url(url: &str, host: &str) -> String {
Expand Down
Loading