rack-noncache 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +86 -0
- data/Rakefile +1 -0
- data/lib/rack/noncache/engine.rb +63 -0
- data/lib/rack/noncache/version.rb +5 -0
- data/lib/rack/noncache.rb +13 -0
- data/lib/rack-noncache.rb +1 -0
- data/rack-noncache.gemspec +23 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8e3b60bccf86bf63d0f07f3fa7db12ebb8d76ad0
|
4
|
+
data.tar.gz: e159f9555b2e775cf4963f5e2676ac4d17e07c45
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e94c71fecc35fb871a9afa43acd9f10d3cd076a1190f41002e8a4ad7b862c693b629b95056274ecdfe59773e63d07b96f1d01060090ab26b012c828d1c6f134
|
7
|
+
data.tar.gz: 1a27b657526488faad6d76063282e6989e84b6dabe7bb88349e4405250c0cf4ed35213d08ccacae9729d4659c23b7e05b191230c2fe1ef86cd853d97a55347c6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 David Sáenz Tagarro
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
Rack::NonCache
|
2
|
+
==============
|
3
|
+
|
4
|
+
Rack::NonCache is a rack middleware that disables HTTP browser caching.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
From Gem:
|
10
|
+
|
11
|
+
$ sudo gem install rack-noncache
|
12
|
+
|
13
|
+
With a local working copy:
|
14
|
+
|
15
|
+
$ git clone git://github.com/dsaenztagarro/rack-noncache.git
|
16
|
+
$ rake package && sudo rake install
|
17
|
+
|
18
|
+
Basic Usage
|
19
|
+
-----------
|
20
|
+
|
21
|
+
Rack::NonCache is implemented as a piece of Rack middleware and can be used with
|
22
|
+
any Rack-based application. If your application includes a rackup (`.ru`) file
|
23
|
+
or uses Rack::Builder to construct the application pipeline, simply require
|
24
|
+
and use as follows:
|
25
|
+
|
26
|
+
require 'rack/noncache'
|
27
|
+
|
28
|
+
use Rack::NonCache,
|
29
|
+
:metastore => 'file:/var/cache/rack/meta',
|
30
|
+
|
31
|
+
run app
|
32
|
+
|
33
|
+
Assuming you've designed your backend application to take advantage of HTTP's
|
34
|
+
caching features, no further code or configuration is required for basic
|
35
|
+
caching.
|
36
|
+
|
37
|
+
Using with Rails
|
38
|
+
----------------
|
39
|
+
|
40
|
+
Add this to your `config/environment.rb`:
|
41
|
+
|
42
|
+
config.middleware.use Rack::NonCache,
|
43
|
+
:whitelist => ['/path/to/non/caching/url', ...,
|
44
|
+
Regexp.new(/^\/path\/to\/non\/caching\/url/)]
|
45
|
+
or:
|
46
|
+
|
47
|
+
config.middleware.use Rack::NonCache,
|
48
|
+
:blacklist => ['/path/to/non/caching/url', ...,
|
49
|
+
Regexp.new(/^\/path\/to\/non\/caching\/url/)],
|
50
|
+
|
51
|
+
You should now see `Rack::NonCache` listed in the middleware pipeline:
|
52
|
+
|
53
|
+
rake middleware
|
54
|
+
|
55
|
+
See the following for more information:
|
56
|
+
|
57
|
+
http://snippets.aktagon.com/snippets/302
|
58
|
+
|
59
|
+
|
60
|
+
Links
|
61
|
+
-----
|
62
|
+
|
63
|
+
GitHub:
|
64
|
+
http://github.com/dsaenztagarro/rack-noncache/
|
65
|
+
|
66
|
+
License
|
67
|
+
-------
|
68
|
+
|
69
|
+
Copyright (c) 2014 David Saenz Tagarro
|
70
|
+
|
71
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
72
|
+
of this software and associated documentation files (the "Software"), to
|
73
|
+
deal in the Software without restriction, including without limitation the
|
74
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
75
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
76
|
+
furnished to do so, subject to the following conditions:
|
77
|
+
|
78
|
+
The above copyright notice and this permission notice shall be included in
|
79
|
+
all copies or substantial portions of the Software.
|
80
|
+
|
81
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
82
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
83
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
84
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
85
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
86
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Rack
|
2
|
+
module NonCache
|
3
|
+
|
4
|
+
class Engine
|
5
|
+
attr_accessor :whitelist, :blacklist
|
6
|
+
|
7
|
+
def initialize(backend, options)
|
8
|
+
@backend = backend
|
9
|
+
yield self if block_given?
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
# execute the request using our backend
|
14
|
+
status, headers, response = @backend.call(env)
|
15
|
+
|
16
|
+
if target_path? env['REQUEST_URI']
|
17
|
+
|
18
|
+
headers['HTTP_CACHE_CONTROL'] =
|
19
|
+
'no-cache, max-age=0, must-revalidate, no-store, private, '
|
20
|
+
|
21
|
+
# Set standard HTTP/1.0 no-cache header.
|
22
|
+
headers['HTTP_CACHE_CONTROL'] +=
|
23
|
+
'max-stale=0, post-check=0, pre-check=0, ' +
|
24
|
+
'no-cache=\"Set-Cookie, Set-Cookie2\"'
|
25
|
+
|
26
|
+
# Set standard HTTP/1.1 no-cache header.
|
27
|
+
headers['HTTP_PRAGMA'] = 'no-cache'
|
28
|
+
|
29
|
+
# Set to expire far in the past. Prevents caching at the proxy server
|
30
|
+
headers['HTTP_EXPIRES'] = Time.now.httpdate
|
31
|
+
|
32
|
+
# Deprecated header
|
33
|
+
headers['HTTP_KEEP_ALIVE'] = 'timeout=3, max=993'
|
34
|
+
|
35
|
+
headers['X-Content-Type-Options'] = 'nosniff'
|
36
|
+
end
|
37
|
+
|
38
|
+
[status, headers, response]
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def target_path?(uri)
|
44
|
+
if @whitelist
|
45
|
+
return match @whitelist, uri
|
46
|
+
elsif @blacklist
|
47
|
+
return !match @blacklist, uri
|
48
|
+
else
|
49
|
+
false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def match(list, uri)
|
54
|
+
list.index do |path|
|
55
|
+
(path.class.eql?(String) && path.eql?(uri)) ||
|
56
|
+
(path.class.eql?(Regexp) && path.match uri)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rack/noncache'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/noncache/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack-noncache"
|
8
|
+
spec.version = Rack::NonCache::VERSION
|
9
|
+
spec.authors = ["David Saenz Tagarro"]
|
10
|
+
spec.email = ["david@redradix.com"]
|
11
|
+
spec.summary = "HTTP Non caching for Rack"
|
12
|
+
spec.description = "Rack::NonCache is suitable as a quick drop-in component to HTTP caching for Rack-based applications that produce required header metatags (Pragma, Expires, Cache-Control, Keep-Alive)."
|
13
|
+
spec.homepage = "https://github.com/dsaenztagarro/rack-noncache"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-noncache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Saenz Tagarro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Rack::NonCache is suitable as a quick drop-in component to HTTP caching
|
42
|
+
for Rack-based applications that produce required header metatags (Pragma, Expires,
|
43
|
+
Cache-Control, Keep-Alive).
|
44
|
+
email:
|
45
|
+
- david@redradix.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- .gitignore
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/rack-noncache.rb
|
56
|
+
- lib/rack/noncache.rb
|
57
|
+
- lib/rack/noncache/engine.rb
|
58
|
+
- lib/rack/noncache/version.rb
|
59
|
+
- rack-noncache.gemspec
|
60
|
+
homepage: https://github.com/dsaenztagarro/rack-noncache
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.2.1
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: HTTP Non caching for Rack
|
84
|
+
test_files: []
|