Skip to content

Commit

Permalink
Cache proxied media
Browse files Browse the repository at this point in the history
  • Loading branch information
spikecodes committed Jan 6, 2021
1 parent c9cd825 commit 0f506fc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,20 @@ pub async fn handler(web::Path(b64): web::Path<String>) -> Result<HttpResponse>
.send()
.await
.map_err(Error::from)
.map(|res| HttpResponse::build(res.status()).streaming(res))
.map(|res|
HttpResponse::build(res.status())
.header("Cache-Control", "public, max-age=1209600, s-maxage=86400, must-revalidate")
.header("Content-Length", res.headers().get("Content-Length").unwrap().to_owned())
.header("Content-Type", res.headers().get("Content-Type").unwrap().to_owned())
.streaming(res)
)
} else {
Err(error::ErrorForbidden("Resource must be from Reddit"))
}
}
Err(_) => Err(error::ErrorBadRequest("Can't parse encoded base64 URL")),
Err(_) => Err(error::ErrorBadRequest("Can't parse base64 into URL")),
}
}
Err(_) => Err(error::ErrorBadRequest("Can't decode base64 URL")),
Err(_) => Err(error::ErrorBadRequest("Can't decode base64")),
}
}

0 comments on commit 0f506fc

Please sign in to comment.