Class: Rack::MiniProfiler::ClientSettings
- Inherits:
-
Object
- Object
- Rack::MiniProfiler::ClientSettings
- Defined in:
- lib/mini_profiler/client_settings.rb
Constant Summary collapse
- COOKIE_NAME =
"__profilin"
- BACKTRACE_DEFAULT =
nil
- BACKTRACE_FULL =
1
- BACKTRACE_NONE =
2
Instance Attribute Summary collapse
-
#backtrace_level ⇒ Object
Returns the value of attribute backtrace_level.
-
#disable_profiling ⇒ Object
Returns the value of attribute disable_profiling.
Instance Method Summary collapse
- #backtrace_default? ⇒ Boolean
- #backtrace_full? ⇒ Boolean
- #backtrace_none? ⇒ Boolean
- #disable_profiling? ⇒ Boolean
- #discard_cookie!(headers) ⇒ Object
- #handle_cookie(result) ⇒ Object
- #has_valid_cookie? ⇒ Boolean
-
#initialize(env, store, start) ⇒ ClientSettings
constructor
A new instance of ClientSettings.
- #write!(headers) ⇒ Object
Constructor Details
#initialize(env, store, start) ⇒ ClientSettings
Returns a new instance of ClientSettings.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mini_profiler/client_settings.rb', line 16 def initialize(env, store, start) @request = ::Rack::Request.new(env) @cookie = @request.[COOKIE_NAME] @store = store @start = start @backtrace_level = nil @orig_disable_profiling = @disable_profiling = nil @allowed_tokens, @orig_auth_tokens = nil if @cookie @cookie.split(",").map { |pair| pair.split("=") }.each do |k, v| @orig_disable_profiling = @disable_profiling = (v == 't') if k == "dp" @backtrace_level = v.to_i if k == "bt" @orig_auth_tokens = v.to_s.split("|") if k == "a" end end if !@backtrace_level.nil? && (@backtrace_level == 0 || @backtrace_level > BACKTRACE_NONE) @backtrace_level = nil end @orig_backtrace_level = @backtrace_level end |
Instance Attribute Details
#backtrace_level ⇒ Object
Returns the value of attribute backtrace_level.
14 15 16 |
# File 'lib/mini_profiler/client_settings.rb', line 14 def backtrace_level @backtrace_level end |
#disable_profiling ⇒ Object
Returns the value of attribute disable_profiling.
13 14 15 |
# File 'lib/mini_profiler/client_settings.rb', line 13 def disable_profiling @disable_profiling end |
Instance Method Details
#backtrace_default? ⇒ Boolean
118 119 120 |
# File 'lib/mini_profiler/client_settings.rb', line 118 def backtrace_default? @backtrace_level == BACKTRACE_DEFAULT end |
#backtrace_full? ⇒ Boolean
114 115 116 |
# File 'lib/mini_profiler/client_settings.rb', line 114 def backtrace_full? @backtrace_level == BACKTRACE_FULL end |
#backtrace_none? ⇒ Boolean
122 123 124 |
# File 'lib/mini_profiler/client_settings.rb', line 122 def backtrace_none? @backtrace_level == BACKTRACE_NONE end |
#disable_profiling? ⇒ Boolean
110 111 112 |
# File 'lib/mini_profiler/client_settings.rb', line 110 def disable_profiling? @disable_profiling end |
#discard_cookie!(headers) ⇒ Object
84 85 86 87 88 |
# File 'lib/mini_profiler/client_settings.rb', line 84 def (headers) if @cookie Rack::Utils.(headers, COOKIE_NAME, path: MiniProfiler.config.) end end |
#handle_cookie(result) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mini_profiler/client_settings.rb', line 42 def (result) status, headers, _body = result if (MiniProfiler.config. == :allow_authorized && !MiniProfiler.) # this is non-obvious, don't kill the profiling cookie on errors or short requests # this ensures that stuff that never reaches the rails stack does not kill profiling if status.to_i >= 200 && status.to_i < 300 && ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - @start) > 0.1) (headers) end else write!(headers) end result end |
#has_valid_cookie? ⇒ Boolean
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/mini_profiler/client_settings.rb', line 90 def = !@cookie.nil? if (MiniProfiler.config. == :allow_authorized) && begin @allowed_tokens ||= @store.allowed_tokens rescue => e if MiniProfiler.config.storage_failure != nil MiniProfiler.config.storage_failure.call(e) end end = @allowed_tokens && (Array === @orig_auth_tokens) && ((@allowed_tokens & @orig_auth_tokens).length > 0) end end |
#write!(headers) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/mini_profiler/client_settings.rb', line 58 def write!(headers) tokens_changed = false if MiniProfiler. && MiniProfiler.config. == :allow_authorized @allowed_tokens ||= @store.allowed_tokens tokens_changed = !@orig_auth_tokens || ((@allowed_tokens - @orig_auth_tokens).length > 0) end if @orig_disable_profiling != @disable_profiling || @orig_backtrace_level != @backtrace_level || @cookie.nil? || tokens_changed settings = { "p" => "t" } settings["dp"] = "t" if @disable_profiling settings["bt"] = @backtrace_level if @backtrace_level settings["a"] = @allowed_tokens.join("|") if @allowed_tokens && MiniProfiler. settings_string = settings.map { |k, v| "#{k}=#{v}" }.join(",") = { value: settings_string, path: MiniProfiler.config., httponly: true } [:secure] = true if @request.ssl? [:same_site] = 'Lax' Rack::Utils.(headers, COOKIE_NAME, ) end end |