class Sidekiq::Web::Application
Constants
- CSP_HEADER_TEMPLATE
- METRICS_PERIODS
- QUEUE_NAME
- REDIS_KEYS
Public Class Methods
Source
# File lib/sidekiq/web/application.rb, line 450 def self.helpers(mod) Sidekiq::Web::Action.send(:include, mod) end
Used by extensions to add helper methods accessible to any defined endpoints in Application
. Careful with generic method naming as there’s no namespacing so collisions are possible.
Source
# File lib/sidekiq/web/application.rb, line 40 def initialize(inst) @app = inst end
Public Instance Methods
Source
# File lib/sidekiq/web/application.rb, line 412 def call(env) action = match(env) return [404, {"content-type" => "text/plain", "x-cascade" => "pass"}, ["Not Found"]] unless action headers = { "content-type" => "text/html", "cache-control" => "private, no-store", "content-language" => action.locale, "content-security-policy" => process_csp(env, CSP_HEADER_TEMPLATE), "x-content-type-options" => "nosniff" } env["response_headers"] = headers resp = catch(:halt) do Thread.current[:sidekiq_redis_pool] = env[:redis_pool] action.instance_exec env, &action.block ensure Thread.current[:sidekiq_redis_pool] = nil end case resp when Array # redirects go here resp else # rendered content goes here # we'll let Rack calculate Content-Length for us. [200, env["response_headers"], [resp]] end end
Source
# File lib/sidekiq/web/application.rb, line 442 def process_csp(env, input) input.gsub("!placeholder!", env[:csp_nonce]) end
Source
# File lib/sidekiq/web/application.rb, line 408 def redis(&) Thread.current[:sidekiq_redis_pool].with(&) end