af_proxy_http: never print received data directly, always redirect to cached_url

cache/getUrl: basename() passed filename just in case
master
Andrew Dolgov 4 years ago
parent 1ee458b5c1
commit 79f102c25d

@ -273,7 +273,7 @@ class DiskCache {
} }
public function getUrl($filename) { public function getUrl($filename) {
return get_self_url_prefix() . "/public.php?op=cached_url&file=" . basename($this->dir) . "/" . $filename; return get_self_url_prefix() . "/public.php?op=cached_url&file=" . basename($this->dir) . "/" . basename($filename);
} }
// check for locally cached (media) URLs and rewrite to local versions // check for locally cached (media) URLs and rewrite to local versions

@ -62,17 +62,10 @@ class Af_Proxy_Http extends Plugin {
$data = fetch_file_contents(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]); $data = fetch_file_contents(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]);
if ($data) { if ($data) {
if ($this->cache->put($local_filename, $data)) {
$disable_cache = $this->host->get($this, "disable_cache"); header("Location: " . $this->cache->getUrl($local_filename));
return;
if (!$disable_cache) {
if ($this->cache->put($local_filename, $data)) {
header("Location: " . $this->cache->getUrl($local_filename));
return;
}
} }
print $data;
} else { } else {
global $fetch_last_error; global $fetch_last_error;
global $fetch_last_error_code; global $fetch_last_error_code;
@ -232,10 +225,6 @@ class Af_Proxy_Http extends Plugin {
print_checkbox("proxy_all", $proxy_all); print_checkbox("proxy_all", $proxy_all);
print "&nbsp;<label for=\"proxy_all\">" . __("Enable proxy for all remote images.") . "</label><br/>"; print "&nbsp;<label for=\"proxy_all\">" . __("Enable proxy for all remote images.") . "</label><br/>";
$disable_cache = $this->host->get($this, "disable_cache");
print_checkbox("disable_cache", $disable_cache);
print "&nbsp;<label for=\"disable_cache\">" . __("Don't cache files locally.") . "</label>";
print "<p>"; print_button("submit", __("Save")); print "<p>"; print_button("submit", __("Save"));
print "</form>"; print "</form>";
@ -245,10 +234,8 @@ class Af_Proxy_Http extends Plugin {
function save() { function save() {
$proxy_all = checkbox_to_sql_bool($_POST["proxy_all"]); $proxy_all = checkbox_to_sql_bool($_POST["proxy_all"]);
$disable_cache = checkbox_to_sql_bool($_POST["disable_cache"]);
$this->host->set($this, "proxy_all", $proxy_all, false); $this->host->set($this, "proxy_all", $proxy_all, false);
$this->host->set($this, "disable_cache", $disable_cache);
echo __("Configuration saved"); echo __("Configuration saved");
} }

Loading…
Cancel
Save