mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-01-19 08:57:55 +00:00
use last revision as etag to improve caching
This commit is contained in:
parent
b06dbbe075
commit
36d7d5e1c4
1 changed files with 15 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
function send_response($code, $message) {
|
function send_response($code, $message = "") {
|
||||||
http_response_code($code);
|
http_response_code($code);
|
||||||
echo $message;
|
echo $message;
|
||||||
exit();
|
exit();
|
||||||
|
@ -83,7 +83,20 @@ if (array_key_exists($ext, $mime_types)) {
|
||||||
header("Content-Type: application/octet-stream");
|
header("Content-Type: application/octet-stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
header("Cache-Control: public, max-age=180, immutable");
|
#header("Cache-Control: public, max-age=10, immutable");
|
||||||
|
|
||||||
|
$command = "sh -c \"cd '$git_root' && /usr/bin/git log --format='%H' -1\"";
|
||||||
|
exec($command, $output, $retval);
|
||||||
|
if ($retval == 0 && count($output)) {
|
||||||
|
$revision=$output[0];
|
||||||
|
header('ETag: "' . $revision . '"');
|
||||||
|
if (isset($_SERVER["HTTP_IF_NONE_MATCH"])) {
|
||||||
|
$req_revision = str_replace('"', '', str_replace('W/"', '', $_SERVER["HTTP_IF_NONE_MATCH"]));
|
||||||
|
if ($req_revision === $revision) {
|
||||||
|
send_response(304);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
## We are executing command twice (first for send_response-checking, then for actual raw output to stream),
|
## We are executing command twice (first for send_response-checking, then for actual raw output to stream),
|
||||||
## which seems wasteful, but it seems exec+echo cannot do raw binary output? Is this true?
|
## which seems wasteful, but it seems exec+echo cannot do raw binary output? Is this true?
|
||||||
|
|
Loading…
Reference in a new issue