Skip to content

Add option to forward cache-control headers to client #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/Plugin/HeaderRewritePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Proxy\Plugin\AbstractPlugin;
use Proxy\Event\ProxyEvent;
use Proxy\Config;

class HeaderRewritePlugin extends AbstractPlugin {

Expand Down Expand Up @@ -40,7 +41,7 @@ function onHeadersReceived(ProxyEvent $event){

// we need content-encoding (in case server refuses to serve it in plain text)
// content-length: final size of content sent to user may change via plugins, so it makes no sense to send old content-length
$forward_headers = array('content-type', 'zzzcontent-length', 'accept-ranges', 'content-range', 'content-disposition', 'location', 'set-cookie');
$forward_headers = array('cache-control', 'content-type', 'zzzcontent-length', 'accept-ranges', 'content-range', 'content-disposition', 'location', 'set-cookie');

foreach($response->headers->all() as $name => $value){

Expand All @@ -57,13 +58,14 @@ function onHeadersReceived(ProxyEvent $event){

$response->headers->set('Content-Disposition', 'filename="'.$filename.'"');
}

// do not ever cache our proxy pages!
$response->headers->set("cache-control", "no-cache, no-store, must-revalidate");
$response->headers->set("pragma", "no-cache");
$response->headers->set("expires", 0);

if (!Config::get('allow_client_caching')) {
// do not ever cache our proxy pages!
$response->headers->set("cache-control", "no-cache, no-store, must-revalidate");
$response->headers->set("pragma", "no-cache");
$response->headers->set("expires", 0);
}
}

}

?>