mirror of
https://github.com/TeamPiped/piped-proxy.git
synced 2024-08-14 23:50:45 +00:00
Add parameter to disable rewriting.
This commit is contained in:
parent
82d5b16d85
commit
71cb04d028
1 changed files with 58 additions and 39 deletions
21
src/main.rs
21
src/main.rs
|
@ -98,6 +98,14 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
|
|||
|
||||
let res = query.get("host");
|
||||
|
||||
let rewrite = {
|
||||
if let Some(rewrite) = query.get("rewrite") {
|
||||
rewrite == "true"
|
||||
} else {
|
||||
true
|
||||
}
|
||||
};
|
||||
|
||||
if res.is_none() {
|
||||
return Err("No host provided".into());
|
||||
}
|
||||
|
@ -123,8 +131,17 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
|
|||
return Err("Domain not allowed".into());
|
||||
}
|
||||
|
||||
let qs = {
|
||||
let qs = query.clone();
|
||||
let collected = qs.into_pairs()
|
||||
.into_iter()
|
||||
.filter(|(key, _)| key != "host" && key != "rewrite")
|
||||
.collect::<Vec<_>>();
|
||||
QString::new(collected)
|
||||
};
|
||||
|
||||
let mut url = Url::parse(&format!("https://{}{}", host, req.path()))?;
|
||||
url.set_query(Some(req.query_string()));
|
||||
url.set_query(Some(qs.to_string().as_str()));
|
||||
|
||||
let mut request = Request::new(
|
||||
req.method().clone(),
|
||||
|
@ -157,6 +174,7 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
|
|||
}
|
||||
}
|
||||
|
||||
if rewrite {
|
||||
if let Some(content_type) = resp.headers().get("content-type") {
|
||||
if content_type == "image/jpeg" {
|
||||
let resp_bytes = resp.bytes().await.unwrap();
|
||||
|
@ -204,6 +222,7 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
|
|||
return Ok(response.body(resp_str));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Stream response
|
||||
Ok(response.streaming(resp.bytes_stream()))
|
||||
|
|
Loading…
Reference in a new issue