class Sidekiq::WebApplication

Constants

CSP_HEADER_TEMPLATE
METRICS_PERIODS
QUEUE_NAME
REDIS_KEYS

Public Class Methods

after(path = nil, &block) click to toggle source
# File lib/sidekiq/web/application.rb, line 429
def self.after(path = nil, &block)
  afters << [path && Regexp.new("\\A#{path.gsub("*", ".*")}\\z"), block]
end
afters() click to toggle source
# File lib/sidekiq/web/application.rb, line 450
def self.afters
  @afters ||= []
end
before(path = nil, &block) click to toggle source
# File lib/sidekiq/web/application.rb, line 425
def self.before(path = nil, &block)
  befores << [path && Regexp.new("\\A#{path.gsub("*", ".*")}\\z"), block]
end
befores() click to toggle source
# File lib/sidekiq/web/application.rb, line 446
def self.befores
  @befores ||= []
end
helpers(mod = nil, &block) click to toggle source
# File lib/sidekiq/web/application.rb, line 417
def self.helpers(mod = nil, &block)
  if block
    WebAction.class_eval(&block)
  else
    WebAction.send(:include, mod)
  end
end
new(klass) click to toggle source
# File lib/sidekiq/web/application.rb, line 30
def initialize(klass)
  @klass = klass
end
run_afters(app, action) click to toggle source
# File lib/sidekiq/web/application.rb, line 437
def self.run_afters(app, action)
  run_hooks(afters, app, action)
end
run_befores(app, action) click to toggle source
# File lib/sidekiq/web/application.rb, line 433
def self.run_befores(app, action)
  run_hooks(befores, app, action)
end
run_hooks(hooks, app, action) click to toggle source
# File lib/sidekiq/web/application.rb, line 441
def self.run_hooks(hooks, app, action)
  hooks.select { |p, _| !p || p =~ action.env[WebRouter::PATH_INFO] }
    .each { |_, b| action.instance_exec(action.env, app, &b) }
end
set(key, val) click to toggle source
# File lib/sidekiq/web/application.rb, line 46
def self.set(key, val)
  # nothing, backwards compatibility
end
settings() click to toggle source
# File lib/sidekiq/web/application.rb, line 38
def self.settings
  Sidekiq::Web.settings
end
tabs() click to toggle source
# File lib/sidekiq/web/application.rb, line 42
def self.tabs
  Sidekiq::Web.tabs
end

Public Instance Methods

call(env) click to toggle source
# File lib/sidekiq/web/application.rb, line 383
def call(env)
  action = self.class.match(env)
  return [404, {Rack::CONTENT_TYPE => "text/plain", Web::X_CASCADE => "pass"}, ["Not Found"]] unless action

  app = @klass
  resp = catch(:halt) do
    self.class.run_befores(app, action)
    action.instance_exec env, &action.block
  ensure
    self.class.run_afters(app, action)
  end

  case resp
  when Array
    # redirects go here
    resp
  else
    # rendered content goes here
    headers = {
      Rack::CONTENT_TYPE => "text/html",
      Rack::CACHE_CONTROL => "private, no-store",
      Web::CONTENT_LANGUAGE => action.locale,
      Web::CONTENT_SECURITY_POLICY => process_csp(env, CSP_HEADER_TEMPLATE),
      Web::X_CONTENT_TYPE_OPTIONS => "nosniff"
    }
    # we'll let Rack calculate Content-Length for us.
    [200, headers, [resp]]
  end
end
process_csp(env, input) click to toggle source
# File lib/sidekiq/web/application.rb, line 413
def process_csp(env, input)
  input.gsub("!placeholder!", env[:csp_nonce])
end
settings() click to toggle source
# File lib/sidekiq/web/application.rb, line 34
def settings
  @klass.settings
end