set cache headers, can't get rack/cache to behave though
This commit is contained in:
parent
86ab67feb2
commit
ba685b1593
19
assets/static/index.html
Normal file
19
assets/static/index.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta rel="travis.api_endpoint" href="https://api.travis-ci.org">
|
||||
<meta name="travis.pusher_key" value="23ed642e81512118260e">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Travis CI - Distributed Continuous Integration Platform for the Open Source Community</title>
|
||||
<link rel="icon" type="image/png" href="/favicon.ico">
|
||||
<link rel="stylesheet" href="/styles/app.css">
|
||||
<script src="/scripts/app.js"></script>
|
||||
<script>
|
||||
minispade.require('travis')
|
||||
Travis.run()
|
||||
</script>
|
||||
</head>
|
||||
<body id="home"></body>
|
||||
</html>
|
||||
|
|
@ -33,7 +33,8 @@ class Travis::Web::App
|
|||
|
||||
use Travis::Web::App::Api, config if config.run_api?
|
||||
|
||||
use Rack::Cache, verbose: true, metastore: 'heap:/', entitystore: 'heap:/' if config.production?
|
||||
# TODO breaks with wrong content length
|
||||
# use Rack::Cache, verbose: true, metastore: 'heap:/', entitystore: 'heap:/' if config.production?
|
||||
use Rack::Deflater if config.deflate?
|
||||
|
||||
use Travis::Web::App::Assets, config
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
class Travis::Web::App
|
||||
class Files < Rack::Cascade
|
||||
MUST_REVALIDATE = %w(/ /index.html /version)
|
||||
|
||||
def self.last_modified
|
||||
@last_modified ||= File.mtime("public/version").httpdate
|
||||
end
|
||||
|
||||
def initialize
|
||||
super([public_dir, index])
|
||||
end
|
||||
|
@ -11,9 +17,21 @@ class Travis::Web::App
|
|||
def index
|
||||
proc do |env|
|
||||
status, headers, body = Rack::File.new(nil).tap { |f| f.path = 'public/index.html' }.serving(env)
|
||||
headers.delete 'Last-Modified'
|
||||
headers.merge!(cache_headers(env['PATH_INFO'])) # TODO unless development?
|
||||
[status, headers, body]
|
||||
end
|
||||
end
|
||||
|
||||
def cache_headers(path)
|
||||
{ 'Cache-Control' => cache_control(path), 'Last-Modified' => self.class.last_modified }
|
||||
end
|
||||
|
||||
def cache_control(path)
|
||||
must_revalidate?(path) ? 'public, must-revalidate' : 'public, max-age=31536000'
|
||||
end
|
||||
|
||||
def must_revalidate?(path)
|
||||
MUST_REVALIDATE.include?(path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1 +1 @@
|
|||
2d6e5c78
|
||||
b9f79cf9
|
Loading…
Reference in New Issue
Block a user