Compare commits

..

1 commit

Author SHA1 Message Date
renovate[bot]
0c0e1e4004
fix(deps): update rust crate reqwest to 0.12.0 2024-10-22 14:38:27 +00:00
3 changed files with 232 additions and 579 deletions

762
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -9,7 +9,7 @@ version = "0.1.0"
# Web Requests & Async Runtime
tokio = { version = "1.37.0", features = ["full"] }
actix-web = "4.5.1"
reqwest = { version = "0.12.9", features = ["stream", "brotli", "gzip", "socks"], default-features = false }
reqwest = { version = "0.12.0", features = ["stream", "brotli", "gzip", "socks"], default-features = false }
qstring = "0.7.2"
# Alternate Allocator
@ -17,17 +17,16 @@ mimalloc = { version = "0.1.41", optional = true }
# Transcoding Images to WebP/AVIF to save bandwidth
image = { version = "0.25.1", features = ["jpeg", "webp", "rayon"], default-features = false, optional = true }
libwebp-sys = { version = "0.12.0", optional = true }
libwebp-sys = { version = "0.10.0", optional = true }
ravif = { version = "0.11.5", optional = true }
rgb = { version = "0.8.37", optional = true }
once_cell = "1.19.0"
regex = "1.10.4"
blake3 = { version = "1.5.5", optional = true }
bytes = "1.9.0"
blake3 = { version = "1.5.1", optional = true }
bytes = "1.6.0"
futures-util = "0.3.30"
listenfd = "1.0.1"
http = "1.2.0"
[features]
default = ["webp", "mimalloc", "reqwest-rustls", "qhash"]

View file

@ -1,7 +1,7 @@
mod ump_stream;
mod utils;
use actix_web::http::StatusCode;
use actix_web::http::{Method, StatusCode};
use actix_web::{web, App, HttpRequest, HttpResponse, HttpResponseBuilder, HttpServer};
use listenfd::ListenFd;
use once_cell::sync::Lazy;
@ -12,16 +12,12 @@ use std::error::Error;
use std::io::ErrorKind;
use std::net::TcpListener;
use std::os::unix::net::UnixListener;
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
use std::{env, io};
#[cfg(not(any(feature = "reqwest-native-tls", feature = "reqwest-rustls")))]
compile_error!("feature \"reqwest-native-tls\" or \"reqwest-rustls\" must be set for proxy to have TLS support");
use futures_util::TryStreamExt;
use http::{HeaderName, Method};
use reqwest::header::HeaderValue;
#[cfg(any(feature = "webp", feature = "avif", feature = "qhash"))]
use tokio::task::spawn_blocking;
use ump_stream::UmpTransformStream;
@ -177,13 +173,11 @@ fn is_header_allowed(header: &str) -> bool {
}
async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
if req.method() == actix_web::http::Method::OPTIONS {
if req.method() == Method::OPTIONS {
let mut response = HttpResponse::Ok();
add_headers(&mut response);
return Ok(response.finish());
} else if req.method() != actix_web::http::Method::GET
&& req.method() != actix_web::http::Method::HEAD
{
} else if req.method() != Method::GET && req.method() != Method::HEAD {
let mut response = HttpResponse::MethodNotAllowed();
add_headers(&mut response);
return Ok(response.finish());
@ -282,20 +276,6 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
}
let video_playback = req.path().eq("/videoplayback");
if video_playback {
if let Some(expiry) = query.get("expire") {
let expiry = expiry.parse::<i64>()?;
let now = SystemTime::now();
let now = now.duration_since(UNIX_EPOCH)
.expect("Time went backwards")
.as_secs() as i64;
if now > expiry {
return Err("Expire time in past".into());
}
}
}
let is_android = video_playback && query.get("c").unwrap_or("").eq("ANDROID");
let is_web = video_playback && query.get("c").unwrap_or("").eq("WEB");
@ -351,7 +331,7 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
if is_web && video_playback {
Method::POST
} else {
Method::from_str(req.method().as_str())?
req.method().clone()
}
};
@ -364,22 +344,18 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
let request_headers = request.headers_mut();
for (key, value) in req.headers() {
let key = key.as_str();
if is_header_allowed(key) {
request_headers.insert(
HeaderName::from_str(key)?,
HeaderValue::from_bytes(value.as_bytes())?,
);
if is_header_allowed(key.as_str()) {
request_headers.insert(key, value.clone());
}
}
if is_android {
request_headers.insert("User-Agent", ANDROID_USER_AGENT.parse()?);
request_headers.insert("User-Agent", ANDROID_USER_AGENT.parse().unwrap());
}
let resp = CLIENT.execute(request).await?;
let mut response = HttpResponse::build(StatusCode::from_u16(resp.status().as_u16())?);
let mut response = HttpResponse::build(resp.status());
add_headers(&mut response);