Class: RackConsole::CookieScriptStorage
- Inherits:
-
Object
- Object
- RackConsole::CookieScriptStorage
- Defined in:
- lib/rack_console/cookie_script_storage.rb
Constant Summary collapse
- WARNING_LIMIT_MSG =
->(max){ 'WARNING: stored script was limited to the first ' + "#{max} chars to avoid issues with cookie overflow\n" }
Instance Attribute Summary collapse
-
#script ⇒ Object
Returns the value of attribute script.
Instance Method Summary collapse
-
#initialize(env, cookie_key: '_rack-console-script', max_length: 4000) ⇒ CookieScriptStorage
constructor
A new instance of CookieScriptStorage.
- #set_cookie_header!(headers = {}) ⇒ Object
Constructor Details
#initialize(env, cookie_key: '_rack-console-script', max_length: 4000) ⇒ CookieScriptStorage
Returns a new instance of CookieScriptStorage.
8 9 10 11 |
# File 'lib/rack_console/cookie_script_storage.rb', line 8 def initialize(env, cookie_key: '_rack-console-script', max_length: 4000) @env, @cookie_key, @max_length = env, , max_length @script = ::CGI::Cookie.parse(env['HTTP_COOKIE'].to_s)[]&.first || '' end |
Instance Attribute Details
#script ⇒ Object
Returns the value of attribute script.
6 7 8 |
# File 'lib/rack_console/cookie_script_storage.rb', line 6 def script @script end |
Instance Method Details
#set_cookie_header!(headers = {}) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/rack_console/cookie_script_storage.rb', line 15 def (headers = {}) script = @script.to_s puts WARNING_LIMIT_MSG[@max_length] if script.size > @max_length = { value: script[0...@max_length], path: @env['REQUEST_PATH'], domain: @env['SERVER_NAME'] } ::Rack::Utils. headers, @cookie_key, headers end |