Class: Rack::Immutable
- Inherits:
-
Object
- Object
- Rack::Immutable
- Defined in:
- lib/rack/immutable.rb
Constant Summary collapse
- DEFAULT_MATCH =
By default, match strings like ‘main.abc123.js’. Assume the fingerprint is a Git SHA value of at least 6 characters, comes before the extension, and has some preceding segment of the path.
/.*\.[A-Za-z\d]{6}[A-Za-z\d]*\.[a-z]+/
- IMMUTABLE =
"public, max-age=604800, immutable"
Instance Method Summary collapse
- #_matches(path, env) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, match: nil, cache_control: nil) ⇒ Immutable
constructor
A new instance of Immutable.
Constructor Details
#initialize(app, match: nil, cache_control: nil) ⇒ Immutable
Returns a new instance of Immutable.
13 14 15 16 17 |
# File 'lib/rack/immutable.rb', line 13 def initialize(app, match: nil, cache_control: nil) @app = app @match = match || DEFAULT_MATCH @cache_control = cache_control || IMMUTABLE end |
Instance Method Details
#_matches(path, env) ⇒ Object
26 27 28 29 30 |
# File 'lib/rack/immutable.rb', line 26 def _matches(path, env) return @match == path if @match.is_a?(String) return @match.match?(path) if @match.is_a?(Regexp) return @match.call(env) end |
#call(env) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/rack/immutable.rb', line 19 def call(env) status, headers, body = @app.call(env) headers[Rack::CACHE_CONTROL] = @cache_control if self._matches(env["PATH_INFO"], env) return status, headers, body end |