sinatra-cookie_thief 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,41 @@
1
+ Sinatra::CookieThief
2
+ ==============================================
3
+
4
+ Rack middleware for Sinatra that disables cookies when content being served is a static asset.
5
+ Some HTTP accelerators (particularly Varnish) will not cache when Set-Cookie is present. This prevents files from not being cached. It is kind of a hack.
6
+
7
+ Installation and Usage
8
+ -------------
9
+
10
+ gem install sinatra-cookie_thief
11
+
12
+ There are two requirements. First, this must be registered before the cookie middleware is added. Second, you must use Rack::Session::Cookie directly (cannot use enable :sessions). This is because CookieThief must be loaded before the Cookie middleware, and Sinatra internally loads Cookie first.
13
+
14
+ For classic-style:
15
+
16
+ require 'sinatra'
17
+ require 'sinatra/cookie_thief'
18
+ register Sinatra::CookieThief
19
+ use Rack::Session::Cookie, :key => 'app.session', :path => '/', :expire_after => 2592000, :secret => 'PUT SOMETHING HERE!'
20
+
21
+ For classy-style:
22
+
23
+ require 'sinatra/base'
24
+ class App < Sinatra::Base
25
+ register Sinatra::CookieThief
26
+ use Rack::Session::Cookie, :key => 'app.session', :path => '/', :expire_after => 2592000, :secret => 'PUT SOMETHING HERE!'
27
+ end
28
+
29
+ Another warning: DO NOT USE SINATRA'S INTERNAL SESSIONS (enable :sessions)! CookieThief must be placed before sessions in the middleware chain, and Sinatra loads its internal middleware first. You shouldn't use it anyways because it doesn't create an encryption key for you, which is a bad security issue.
30
+
31
+ DO NOT DO THIS:
32
+
33
+ require 'sinatra/base'
34
+ class App < Sinatra::Base
35
+ register Sinatra::CookieThief
36
+ enable :sessions # BAD! WILL NOT WORK! Must use use Rack::Session::Cookie directly.
37
+ end
38
+
39
+ Improvements
40
+ ---
41
+ Send a pull request! Note that there are tests to demonstrate the current behavior.
@@ -0,0 +1,10 @@
1
+ module Rack
2
+ class CookieThief
3
+ def initialize(app); @app = app end
4
+ def call(env)
5
+ status, headers, body = @app.call env
6
+ headers.delete 'Set-Cookie' if env['sinatra.static_file']
7
+ [status, headers, body]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ require 'sinatra/base'
2
+ require File.join(File.join(File.expand_path(File.dirname(__FILE__))), '..', 'rack', 'cookie_thief')
3
+
4
+ module Sinatra
5
+ module CookieThief
6
+ def self.registered(app)
7
+ raise ArgumentError, 'Cannot use sessions directly from Sinatra with CookieThief because it needs to happen before Session::Cookie. See the README.' if app.sessions?
8
+ app.use Rack::CookieThief
9
+ end
10
+ end
11
+ register CookieThief
12
+ end
Binary file
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-cookie_thief
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Kyle Drake
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-30 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: sinatra
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "1.0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description: Rack middleware to disable cookies when static content is being served, which can prevent caching on some HTTP accelerators (Varnish).
28
+ email:
29
+ - kyledrake@gmail.com
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files: []
35
+
36
+ files:
37
+ - lib/sinatra/cookie_thief.rb
38
+ - lib/rack/cookie_thief.rb
39
+ - test/public/hagio.jpg
40
+ - README.markdown
41
+ has_rdoc: true
42
+ homepage: https://github.com/kyledrake/sinatra-cookie_thief
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project: sinatra-cookie_thief
65
+ rubygems_version: 1.5.2
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Rack middleware to disable cookies when static content is being served.
69
+ test_files: []
70
+