Class: Rack::Policy::CookieLimiter
- Inherits:
-
Object
- Object
- Rack::Policy::CookieLimiter
- Includes:
- Utils
- Defined in:
- lib/rack/policy/cookie_limiter.rb
Overview
This is the class for limiting cookie storage on client machine.
Constant Summary collapse
- HTTP_COOKIE =
"HTTP_COOKIE".freeze
- SET_COOKIE =
"Set-Cookie".freeze
- CACHE_CONTROL =
"Cache-Control".freeze
- CONSENT_TOKEN =
"cookie_limiter".freeze
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
-
#allowed?(request) ⇒ Boolean
Returns ‘false` if the cookie policy disallows cookie storage for a given request, or `true` otherwise.
- #call(env) ⇒ Object
- #call!(env) ⇒ Object
- #consent_token ⇒ Object
- #expires ⇒ Object
-
#finish(env) ⇒ Object
Finish http response with proper headers.
-
#initialize(app, options = {}) ⇒ CookieLimiter
constructor
A new instance of CookieLimiter.
Constructor Details
#initialize(app, options = {}) ⇒ CookieLimiter
Returns a new instance of CookieLimiter.
19 20 21 |
# File 'lib/rack/policy/cookie_limiter.rb', line 19 def initialize(app, ={}) @app, @options = app, end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
14 15 16 |
# File 'lib/rack/policy/cookie_limiter.rb', line 14 def app @app end |
#body ⇒ Object
Returns the value of attribute body.
15 16 17 |
# File 'lib/rack/policy/cookie_limiter.rb', line 15 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
15 16 17 |
# File 'lib/rack/policy/cookie_limiter.rb', line 15 def headers @headers end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/rack/policy/cookie_limiter.rb', line 14 def @options end |
#status ⇒ Object
Returns the value of attribute status.
15 16 17 |
# File 'lib/rack/policy/cookie_limiter.rb', line 15 def status @status end |
Instance Method Details
#allowed?(request) ⇒ Boolean
Returns ‘false` if the cookie policy disallows cookie storage for a given request, or `true` otherwise.
46 47 48 49 50 51 52 53 |
# File 'lib/rack/policy/cookie_limiter.rb', line 46 def allowed?(request) if ( request..has_key?(.to_s) || .has_key?(.to_s) ) true else false end end |
#call(env) ⇒ Object
31 32 33 |
# File 'lib/rack/policy/cookie_limiter.rb', line 31 def call(env) dup.call!(env) end |
#call!(env) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/rack/policy/cookie_limiter.rb', line 35 def call!(env) self.status, self.headers, self.body = @app.call(env) request = Rack::Request.new(env) response = Rack::Response.new body, status, headers (request, response) unless allowed?(request) finish(env) end |
#consent_token ⇒ Object
23 24 25 |
# File 'lib/rack/policy/cookie_limiter.rb', line 23 def @consent_token ||= [:consent_token] || CONSENT_TOKEN end |
#expires ⇒ Object
27 28 29 |
# File 'lib/rack/policy/cookie_limiter.rb', line 27 def expires Time.parse([:expires]) if [:expires] end |
#finish(env) ⇒ Object
Finish http response with proper headers
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rack/policy/cookie_limiter.rb', line 56 def finish(env) if [204, 304].include?(status.to_i) || (status.to_i / 100 == 1) headers.delete "Content-Length" headers.delete "Content-Type" [status.to_i, headers, []] elsif env['REQUEST_METHOD'] == 'HEAD' [status.to_i, headers, []] else [status.to_i, headers, body] end end |