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 5 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ regex = "1.10.3"
blake3 = { version = "1.5.0", optional = true }
bytes = "1.5.0"
futures-util = "0.3.30"
lazy_static = "1.4.0"

[features]
default = ["webp", "mimalloc", "reqwest-rustls", "qhash"]
Expand All @@ -42,5 +43,7 @@ optimized = ["libwebp-sys?/sse41", "libwebp-sys?/avx2", "libwebp-sys?/neon"]

qhash = ["blake3"]

prefix-path = []

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

#[cfg(not(feature = "prefix-path"))]
lazy_static! {
static ref PREFIX_PATH: Option<String> = Some(String::from(""));
}
aspacca marked this conversation as resolved.
Show resolved Hide resolved

#[cfg(feature = "prefix-path")]
lazy_static! {
static ref PREFIX_PATH: Option<String> = match env::var("PREFIX_PATH") {
Ok(v) => Some(String::from(v)),
Err(e) => panic!("$PREFIX_PATH is not set ({})", e)
};
}
aspacca marked this conversation as resolved.
Show resolved Hide resolved

pub fn read_buf(buf: &[u8], pos: &mut usize) -> u8 {
let byte = buf[*pos];
Expand All @@ -13,7 +28,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 +60,12 @@ 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

return format!("{}{}?{}", PREFIX_PATH.as_ref().unwrap().to_string(), path, query);
}
}

let query = QString::new(query.into_iter().collect::<Vec<_>>());
format!("{}?{}", path, query)
format!("{}{}?{}", PREFIX_PATH.as_ref().unwrap().to_string(), path, query)
}

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