Added Percent Encoding Support

This commit is contained in:
spikecodes 2020-11-29 18:50:29 -08:00
parent 8f157c0b40
commit 9a6430656d
11 changed files with 63 additions and 16570 deletions

View file

@ -1,18 +1,27 @@
use actix_web::{get, web, HttpResponse, Result, client::Client, Error};
use actix_web::{client::Client, get, web, Error, HttpResponse, Result};
#[cfg(feature = "proxy")]
use percent_encoding::percent_decode_str;
#[get("/imageproxy/{url:.*}")]
async fn handler(web::Path(url): web::Path<String>) -> Result<HttpResponse> {
if cfg!(feature = "proxy") {
dbg!(&url);
#[cfg(feature = "proxy")]
let media: String = percent_decode_str(url.as_str()).decode_utf8()?.to_string();
#[cfg(not(feature = "proxy"))]
let media: String = url;
dbg!(&media);
let client = Client::default();
client.get(url)
client
.get(media)
.send()
.await
.map_err(Error::from)
.and_then(|res| {
Ok(HttpResponse::build(res.status()).streaming(res))
})
.and_then(|res| Ok(HttpResponse::build(res.status()).streaming(res)))
} else {
Ok(HttpResponse::Ok().body(""))
}
}
}