4 public function __construct($score_id) {
5 $this->score_id = $score_id;
8 public function show($dir, $ext, $content_type)
10 $dirname = sprintf("%s/%d", $dir, floor($this->score_id / 1000) * 1000);
11 $filename = sprintf("%s/%d.%s.gz", $dirname, $this->score_id, $ext);
13 if (!file_exists($filename)) {
14 http_response_code(404);
18 $content_encoding = self::get_content_encoding();
20 header("Content-Type: ".$content_type);
21 if ($content_encoding !== FALSE) {
22 header("Content-Encoding: ".$content_encoding);
25 readgzfile($filename);
29 private static function browser_accept_encodings()
31 if (!isset($_SERVER["HTTP_ACCEPT_ENCODING"])) return [];
33 return array_map('trim', explode(",", $_SERVER["HTTP_ACCEPT_ENCODING"]));
37 private static function get_content_encoding()
39 $supported_gzip_encodings = array_intersect(
40 self::browser_accept_encodings(),
43 return count($supported_gzip_encodings) > 0 ?
44 $supported_gzip_encodings[0] : FALSE;