Sha256: 6712ad7ae316b9ab26260a30f9118b911e5e68aa3345d118a13d02c05b25e776
Contents?: true
Size: 1.79 KB
Versions: 17
Compression:
Stored size: 1.79 KB
Contents
module Rack class MiniProfiler class ClientSettings COOKIE_NAME = "__profilin" BACKTRACE_DEFAULT = nil BACKTRACE_FULL = 1 BACKTRACE_NONE = 2 attr_accessor :disable_profiling attr_accessor :backtrace_level def initialize(env) request = ::Rack::Request.new(env) @cookie = request.cookies[COOKIE_NAME] 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" end end @backtrace_level = nil if !@backtrace_level.nil? && (@backtrace_level == 0 || @backtrace_level > BACKTRACE_NONE) @orig_backtrace_level = @backtrace_level end def write!(headers) if @orig_disable_profiling != @disable_profiling || @orig_backtrace_level != @backtrace_level || @cookie.nil? settings = {"p" => "t" } settings["dp"] = "t" if @disable_profiling settings["bt"] = @backtrace_level if @backtrace_level settings_string = settings.map{|k,v| "#{k}=#{v}"}.join(",") Rack::Utils.set_cookie_header!(headers, COOKIE_NAME, :value => settings_string, :path => '/') end end def discard_cookie!(headers) Rack::Utils.delete_cookie_header!(headers, COOKIE_NAME, :path => '/') end def has_cookie? !@cookie.nil? end def disable_profiling? @disable_profiling end def backtrace_full? @backtrace_level == BACKTRACE_FULL end def backtrace_default? @backtrace_level == BACKTRACE_DEFAULT end def backtrace_none? @backtrace_level == BACKTRACE_NONE end end end end
Version data entries
17 entries across 17 versions & 2 rubygems