mirror of
https://github.com/TeamPiped/piped-proxy.git
synced 2024-08-14 23:50:45 +00:00
feature parity with legacy ytproxy
This commit is contained in:
parent
8bbda01e9c
commit
b1658c94af
1 changed files with 13 additions and 1 deletions
14
src/main.rs
14
src/main.rs
|
@ -1,7 +1,9 @@
|
|||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::string::ToString;
|
||||
|
||||
use actix_web::{App, HttpRequest, HttpResponse, HttpResponseBuilder, HttpServer, web};
|
||||
use actix_web::dev::ResourcePath;
|
||||
use actix_web::http::Method;
|
||||
use image::EncodableLayout;
|
||||
use lazy_static::lazy_static;
|
||||
|
@ -49,6 +51,10 @@ lazy_static!(
|
|||
};
|
||||
);
|
||||
|
||||
lazy_static!(
|
||||
static ref PREFIX_PATH: String = env::var("PREFIX_PATH").unwrap_or_else(|_| "".to_string());
|
||||
);
|
||||
|
||||
const ALLOWED_DOMAINS: [&str; 7] = [
|
||||
"youtube.com",
|
||||
"googlevideo.com",
|
||||
|
@ -59,6 +65,7 @@ const ALLOWED_DOMAINS: [&str; 7] = [
|
|||
"odycdn.com",
|
||||
];
|
||||
|
||||
|
||||
fn add_headers(response: &mut HttpResponseBuilder) {
|
||||
response
|
||||
.append_header(("Access-Control-Allow-Origin", "*"))
|
||||
|
@ -73,6 +80,11 @@ fn is_header_allowed(header: &str) -> bool {
|
|||
}
|
||||
|
||||
!matches!(header, "host" |
|
||||
"authorization" |
|
||||
"origin" |
|
||||
"referer" |
|
||||
"cookie" |
|
||||
"etag" |
|
||||
"content-length" |
|
||||
"set-cookie" |
|
||||
"alt-svc" |
|
||||
|
@ -242,7 +254,7 @@ fn localize_url(url: &str, host: &str) -> String {
|
|||
url.query_pairs_mut()
|
||||
.append_pair("host", &host);
|
||||
|
||||
return format!("{}?{}", url.path(), url.query().unwrap());
|
||||
return format!("{}{}?{}", PREFIX_PATH.as_str(), url.path(), url.query().unwrap());
|
||||
} else if url.ends_with(".m3u8") || url.ends_with(".ts") {
|
||||
return if url.contains('?') {
|
||||
format!("{}&host={}", url, host)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue