Class: Rack::Protection::MaximumCookie
- Inherits:
-
Object
- Object
- Rack::Protection::MaximumCookie
- Defined in:
- lib/rack/protection/maximum_cookie.rb,
lib/rack/protection/maximum_cookie/version.rb
Constant Summary collapse
- HEADER_SEP_RE =
%r{\r?\n|\0}.freeze
- COOKIE_DOMAIN_RE =
%r{;\s*[Dd][Oo][Mm][Aa][Ii][Nn]=([^;]+)}.freeze
- COOKIE_KEY_RE =
%r{\A[^=]+}.freeze
- VERSION =
'0.4.2'.freeze
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#public_suffix_list ⇒ Object
readonly
Returns the value of attribute public_suffix_list.
Instance Method Summary collapse
- #bytesize_limit ⇒ Object
- #bytesize_limit? ⇒ Boolean
- #call(env) ⇒ Object
-
#initialize(app, options = {}, &block) ⇒ MaximumCookie
constructor
A new instance of MaximumCookie.
- #limit ⇒ Object
- #limit? ⇒ Boolean
- #overhead ⇒ Object
- #per_domain? ⇒ Boolean
- #stateful? ⇒ Boolean
- #strict? ⇒ Boolean
Constructor Details
#initialize(app, options = {}, &block) ⇒ MaximumCookie
Returns a new instance of MaximumCookie.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rack/protection/maximum_cookie.rb', line 66 def initialize(app, ={}, &block) @app = app @handler = block @options = {}.tap do |h| h[:limit] = Integer(.fetch(:limit, 50)) h[:bytesize_limit] = Integer(.fetch(:bytesize_limit, 4_096)) h[:overhead] = Integer(.fetch(:overhead, 3)) h[:stateful?] = !!.fetch(:stateful?, .fetch(:stateful, false)) h[:strict?] = h[:stateful?] || !!.fetch(:strict?, .fetch(:strict, false)) h[:per_domain?] = h[:strict?] || !!.fetch(:per_domain?, .fetch(:per_domain, true)) h.freeze end if strict? # Allow non-ICANN domains to be handled the same as ICANN domains. @public_suffix_list = PublicSuffix::List.parse(::File.read(PublicSuffix::List::DEFAULT_LIST_PATH), :private_domains=>false) end unless limit? || bytesize_limit? abort 'No limits, nothing to do!' end end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
30 31 32 |
# File 'lib/rack/protection/maximum_cookie.rb', line 30 def app @app end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
31 32 33 |
# File 'lib/rack/protection/maximum_cookie.rb', line 31 def handler @handler end |
#public_suffix_list ⇒ Object (readonly)
Returns the value of attribute public_suffix_list.
32 33 34 |
# File 'lib/rack/protection/maximum_cookie.rb', line 32 def public_suffix_list @public_suffix_list end |
Instance Method Details
#bytesize_limit ⇒ Object
42 43 44 |
# File 'lib/rack/protection/maximum_cookie.rb', line 42 def bytesize_limit @options[:bytesize_limit] end |
#bytesize_limit? ⇒ Boolean
46 47 48 |
# File 'lib/rack/protection/maximum_cookie.rb', line 46 def bytesize_limit? @options[:bytesize_limit] >= 0 end |
#call(env) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/rack/protection/maximum_cookie.rb', line 91 def call(env) status, headers, body = app.call(env) if headers.key?(SET_COOKIE) env, Rack::Request.new(env), (headers[SET_COOKIE]) end [status, headers, body] end |
#limit ⇒ Object
34 35 36 |
# File 'lib/rack/protection/maximum_cookie.rb', line 34 def limit @options[:limit] end |
#limit? ⇒ Boolean
38 39 40 |
# File 'lib/rack/protection/maximum_cookie.rb', line 38 def limit? @options[:limit] >= 0 end |
#overhead ⇒ Object
50 51 52 |
# File 'lib/rack/protection/maximum_cookie.rb', line 50 def overhead @options[:overhead] end |
#per_domain? ⇒ Boolean
54 55 56 |
# File 'lib/rack/protection/maximum_cookie.rb', line 54 def per_domain? @options[:per_domain?] end |
#stateful? ⇒ Boolean
62 63 64 |
# File 'lib/rack/protection/maximum_cookie.rb', line 62 def stateful? @options[:stateful?] end |
#strict? ⇒ Boolean
58 59 60 |
# File 'lib/rack/protection/maximum_cookie.rb', line 58 def strict? @options[:strict?] end |