Skip to content

Commit e27c5f2

Browse files
author
epriestley
committed
Allow Celerity to return "304 Not Modified" responses
Summary: We always return HTTP 200 right now and don't send a "Last-Modified" header, so browsers download more data then necessary if you sit on a page mashing reload (for example). Test Plan: Used Charles to verify HTTP response codes from 400, 404 and 304 responses. Mashed reload a bunch and saw that the server sent back 304s. Changed the resource hash seed and saw 200s, then 304s on reload. Reviewed By: tuomaspelkonen Reviewers: tuomaspelkonen, jungejason, aran CC: bmaurer, aran, tuomaspelkonen Differential Revision: 253
1 parent e32fd1a commit e27c5f2

File tree

13 files changed

+299
-198
lines changed

13 files changed

+299
-198
lines changed

conf/default.conf.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,12 @@
337337
// track running daemons.
338338
'phd.pid-directory' => '/var/tmp/phd',
339339

340+
// This value is an input to the hash function when building resource hashes.
341+
// It has no security value, but if you accidentally poison user caches (by
342+
// pushing a bad patch or having something go wrong with a CDN, e.g.) you can
343+
// change this to something else and rebuild the Celerity map to break user
344+
// caches. Unless you are doing Celerity development, it is exceptionally
345+
// unlikely that you need to modify this.
346+
'celerity.resource-hash' => 'd9455ea150622ee044f7931dabfa52aa',
347+
340348
);

scripts/celerity_mapper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171

7272

7373
require_once dirname(__FILE__).'/__init_script__.php';
74+
require_once dirname(__FILE__).'/__init_env__.php';
7475

7576
if ($argc != 2) {
7677
$self = basename($argv[0]);
@@ -96,12 +97,14 @@
9697

9798
echo "Processing ".count($files)." files";
9899

100+
$resource_hash = PhabricatorEnv::getEnvConfig('celerity.resource-hash');
101+
99102
$file_map = array();
100103
foreach ($files as $path => $hash) {
101104
echo ".";
102105
$name = '/'.Filesystem::readablePath($path, $root);
103106
$file_map[$name] = array(
104-
'hash' => $hash,
107+
'hash' => md5($hash.$name.$resource_hash),
105108
'disk' => $path,
106109
);
107110
}

0 commit comments

Comments
 (0)