Skip to content

Commit

Permalink
fix(Stream): fn streaming_url proxy header double-
Browse files Browse the repository at this point in the history
encoding

Signed-off-by: Lachezar Lechev <[email protected]>
  • Loading branch information
elpiel committed May 10, 2024
1 parent 02c1cfd commit ffbfedb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
15 changes: 8 additions & 7 deletions src/types/resource/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,13 @@ impl Stream {
.iter()
.map(|header| ("r", format!("{}:{}", header.0, header.1))),
);
streaming_url
.path_segments_mut()
.ok()?
.push("proxy")
.push(proxy_query.finish().as_str())
.push(&url.path()[1..]);

streaming_url.set_path(&format!(
"proxy/{query}/{url_path}",
query = proxy_query.finish().as_str(),
url_path = url.path().strip_prefix('/').unwrap_or(url.path()),
));

streaming_url.set_query(url.query());
Some(streaming_url)
}
Expand Down Expand Up @@ -576,7 +577,7 @@ mod tests {

let stream = serde_json::from_value::<Stream>(stream_json)
.expect("Should be able to deserialize valid Stream");
let expected = "http://127.0.0.1:3000/proxy/d=https%253A%252F%252Fwebdav.premiumize.me&h=Authorization%253ABasic+%2527XXXXXXXXXXXXXXXXXXXXXXX%253D%2527/%255B%2520Torrent911.vc%2520%255D%2520The.Beekeeper.2024.FRENCH.1080p.WEBRip.x264-RZP.mkv".parse::<Url>().expect("Valid url");
let expected = "http://127.0.0.1:3000/proxy/d=https%3A%2F%2Fwebdav.premiumize.me&h=Authorization%3ABasic+%27XXXXXXXXXXXXXXXXXXXXXXX%3D%27/%5B%20Torrent911.vc%20%5D%20The.Beekeeper.2024.FRENCH.1080p.WEBRip.x264-RZP.mkv".parse::<Url>().expect("Valid url");
assert_eq!(
expected,
stream
Expand Down
23 changes: 11 additions & 12 deletions src/unit_tests/deep_links/stream_deep_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use std::str::FromStr;
use url::Url;

const MAGNET_STR_URL: &str = "magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c";
const HTTP_STR_URL: &str = "http://domain.root/path";
const HTTP_WITH_QUERY_STR_URL: &str = "http://domain.root/path?param=some&foo=bar";
const BASE64_HTTP_URL: &str = "data:application/octet-stream;charset=utf-8;base64,I0VYVE0zVQojRVhUSU5GOjAKaHR0cDovL2RvbWFpbi5yb290L3BhdGg=";
const HTTP_STR_URL: &str = "http://domain.root/some/path";
const HTTP_WITH_QUERY_STR_URL: &str = "http://domain.root/some/path?param=some&foo=bar";
const BASE64_HTTP_URL: &str = "data:application/octet-stream;charset=utf-8;base64,I0VYVE0zVQojRVhUSU5GOjAKaHR0cDovL2RvbWFpbi5yb290L3NvbWUvcGF0aA==";
const STREAMING_SERVER_URL: &str = "http://127.0.0.1:11470";
const YT_ID: &str = "aqz-KE-bpKQ";

Expand Down Expand Up @@ -56,9 +56,8 @@ fn stream_deep_links_http() {
let settings = Settings::default();
let sdl = StreamDeepLinks::try_from((&stream, &streaming_server_url, &settings)).unwrap();
assert_eq!(
sdl.player,
"stremio:///player/eAEBIQDe%2F3sidXJsIjoiaHR0cDovL2RvbWFpbi5yb290L3BhdGgifcEEC6w%3D"
.to_string()
&sdl.player,
"stremio:///player/eAEBJgDZ%2F3sidXJsIjoiaHR0cDovL2RvbWFpbi5yb290L3NvbWUvcGF0aCJ9AYANjw%3D%3D",
);
assert_eq!(
sdl.external_player.playlist,
Expand Down Expand Up @@ -98,13 +97,13 @@ fn stream_deep_links_http_with_request_headers() {
let streaming_server_url = Some(Url::parse(STREAMING_SERVER_URL).unwrap());
let settings = Settings::default();
let sdl = StreamDeepLinks::try_from((&stream, &streaming_server_url, &settings)).unwrap();
assert_eq!(sdl.player, "stremio:///player/eAEBawCU%2F3sidXJsIjoiaHR0cDovL2RvbWFpbi5yb290L3BhdGgiLCJiZWhhdmlvckhpbnRzIjp7InByb3h5SGVhZGVycyI6eyJyZXF1ZXN0Ijp7IkF1dGhvcml6YXRpb24iOiJteSt0b2tlbiJ9fX19DNkm%2FA%3D%3D".to_string());
assert_eq!(sdl.player, "stremio:///player/eAEBcACP%2F3sidXJsIjoiaHR0cDovL2RvbWFpbi5yb290L3NvbWUvcGF0aCIsImJlaGF2aW9ySGludHMiOnsicHJveHlIZWFkZXJzIjp7InJlcXVlc3QiOnsiQXV0aG9yaXphdGlvbiI6Im15K3Rva2VuIn19fX3Y5Cjf".to_string());
assert_eq!(
sdl.external_player.streaming,
Some(format!(
"{}/proxy/{}",
STREAMING_SERVER_URL,
"d=http%253A%252F%252Fdomain.root&h=Authorization%253Amy%252Btoken/path"
"d=http%3A%2F%2Fdomain.root&h=Authorization%3Amy%2Btoken/some/path",
))
);
}
Expand Down Expand Up @@ -139,13 +138,13 @@ fn stream_deep_links_http_with_request_response_headers_and_query_params() {
let streaming_server_url = Some(Url::parse(STREAMING_SERVER_URL).unwrap());
let settings = Settings::default();
let sdl = StreamDeepLinks::try_from((&stream, &streaming_server_url, &settings)).unwrap();
assert_eq!(sdl.player, "stremio:///player/eAEBrABT%2F3sidXJsIjoiaHR0cDovL2RvbWFpbi5yb290L3BhdGg%2FcGFyYW09c29tZSZmb289YmFyIiwiYmVoYXZpb3JIaW50cyI6eyJwcm94eUhlYWRlcnMiOnsicmVxdWVzdCI6eyJBdXRob3JpemF0aW9uIjoibXkrdG9rZW4ifSwicmVzcG9uc2UiOnsiQ29udGVudC1UeXBlIjoiYXBwbGljYXRpb24veG1sIn19fX322z6q".to_string());
assert_eq!(sdl.player, "stremio:///player/eAEBsQBO%2F3sidXJsIjoiaHR0cDovL2RvbWFpbi5yb290L3NvbWUvcGF0aD9wYXJhbT1zb21lJmZvbz1iYXIiLCJiZWhhdmlvckhpbnRzIjp7InByb3h5SGVhZGVycyI6eyJyZXF1ZXN0Ijp7IkF1dGhvcml6YXRpb24iOiJteSt0b2tlbiJ9LCJyZXNwb25zZSI6eyJDb250ZW50LVR5cGUiOiJhcHBsaWNhdGlvbi94bWwifX19fT2nQI0%3D".to_string());
assert_eq!(
sdl.external_player.streaming,
Some(format!(
"{}/proxy/{}",
STREAMING_SERVER_URL,
"d=http%253A%252F%252Fdomain.root&h=Authorization%253Amy%252Btoken&r=Content-Type%253Aapplication%252Fxml/path?param=some&foo=bar"
"d=http%3A%2F%2Fdomain.root&h=Authorization%3Amy%2Btoken&r=Content-Type%3Aapplication%2Fxml/some/path?param=some&foo=bar",
))
);
}
Expand Down Expand Up @@ -293,7 +292,7 @@ fn stream_deep_links_external() {
let streaming_server_url = Some(Url::parse(STREAMING_SERVER_URL).unwrap());
let settings = Settings::default();
let sdl = StreamDeepLinks::try_from((&stream, &streaming_server_url, &settings)).unwrap();
assert_eq!(sdl.player, "stremio:///player/eAEBKQDW%2F3siZXh0ZXJuYWxVcmwiOiJodHRwOi8vZG9tYWluLnJvb3QvcGF0aCJ9OoEO7w%3D%3D".to_string());
assert_eq!(sdl.player, "stremio:///player/eAEBLgDR%2F3siZXh0ZXJuYWxVcmwiOiJodHRwOi8vZG9tYWluLnJvb3Qvc29tZS9wYXRoIn2LPRDS".to_string());
assert_eq!(
sdl.external_player.web,
Some(Url::from_str(HTTP_STR_URL).unwrap()),
Expand Down Expand Up @@ -351,7 +350,7 @@ fn stream_deep_links_player_frame() {
let streaming_server_url = Some(Url::parse(STREAMING_SERVER_URL).unwrap());
let settings = Settings::default();
let sdl = StreamDeepLinks::try_from((&stream, &streaming_server_url, &settings)).unwrap();
assert_eq!(sdl.player, "stremio:///player/eAEBLADT%2F3sicGxheWVyRnJhbWVVcmwiOiJodHRwOi8vZG9tYWluLnJvb3QvcGF0aCJ9abUQBA%3D%3D".to_string());
assert_eq!(sdl.player, "stremio:///player/eAEBMQDO%2F3sicGxheWVyRnJhbWVVcmwiOiJodHRwOi8vZG9tYWluLnJvb3Qvc29tZS9wYXRoIn2%2F2hHn".to_string());
assert_eq!(sdl.external_player.playlist, None);
assert_eq!(sdl.external_player.file_name, None);
}
Expand Down

0 comments on commit ffbfedb

Please sign in to comment.