mirror of
https://github.com/spikecodes/libreddit.git
synced 2026-01-26 06:24:07 +01:00
Added Percent Encoding Support
This commit is contained in:
23
src/proxy.rs
23
src/proxy.rs
@@ -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(""))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user