Class: Sidekiq::WebApplication
- Inherits:
-
Object
- Object
- Sidekiq::WebApplication
show all
- Extended by:
- WebRouter
- Defined in:
- lib/sidekiq/web/application.rb
Constant Summary
collapse
- REDIS_KEYS =
%w[redis_version uptime_in_days connected_clients used_memory_human used_memory_peak_human]
[
"default-src 'self' https: http:",
"child-src 'self'",
"connect-src 'self' https: http: wss: ws:",
"font-src 'self' https: http:",
"frame-src 'self'",
"img-src 'self' https: http: data:",
"manifest-src 'self'",
"media-src 'self'",
"object-src 'none'",
"script-src 'self' 'nonce-!placeholder!'",
"style-src 'self' https: http: 'unsafe-inline'", "worker-src 'self'",
"base-uri 'self'"
].join("; ").freeze
- METRICS_PERIODS =
{
"1h" => 60,
"2h" => 120,
"4h" => 240,
"8h" => 480
}
- QUEUE_NAME =
/\A[a-z_:.\-0-9]+\z/i
Constants included
from WebRouter
Sidekiq::WebRouter::DELETE, Sidekiq::WebRouter::GET, Sidekiq::WebRouter::HEAD, Sidekiq::WebRouter::PATCH, Sidekiq::WebRouter::PATH_INFO, Sidekiq::WebRouter::POST, Sidekiq::WebRouter::PUT, Sidekiq::WebRouter::REQUEST_METHOD, Sidekiq::WebRouter::ROUTE_PARAMS
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from WebRouter
delete, get, head, match, patch, post, put, route
Constructor Details
Returns a new instance of WebApplication.
30
31
32
|
# File 'lib/sidekiq/web/application.rb', line 30
def initialize(klass)
@klass = klass
end
|
Class Method Details
.after(path = nil, &block) ⇒ Object
454
455
456
|
# File 'lib/sidekiq/web/application.rb', line 454
def self.after(path = nil, &block)
afters << [path && Regexp.new("\\A#{path.gsub("*", ".*")}\\z"), block]
end
|
.afters ⇒ Object
475
476
477
|
# File 'lib/sidekiq/web/application.rb', line 475
def self.afters
@afters ||= []
end
|
.before(path = nil, &block) ⇒ Object
450
451
452
|
# File 'lib/sidekiq/web/application.rb', line 450
def self.before(path = nil, &block)
befores << [path && Regexp.new("\\A#{path.gsub("*", ".*")}\\z"), block]
end
|
.befores ⇒ Object
471
472
473
|
# File 'lib/sidekiq/web/application.rb', line 471
def self.befores
@befores ||= []
end
|
.helpers(mod = nil, &block) ⇒ Object
442
443
444
445
446
447
448
|
# File 'lib/sidekiq/web/application.rb', line 442
def self.helpers(mod = nil, &block)
if block
WebAction.class_eval(&block)
else
WebAction.send(:include, mod)
end
end
|
.run_afters(app, action) ⇒ Object
462
463
464
|
# File 'lib/sidekiq/web/application.rb', line 462
def self.run_afters(app, action)
run_hooks(afters, app, action)
end
|
.run_befores(app, action) ⇒ Object
458
459
460
|
# File 'lib/sidekiq/web/application.rb', line 458
def self.run_befores(app, action)
run_hooks(befores, app, action)
end
|
.run_hooks(hooks, app, action) ⇒ Object
466
467
468
469
|
# File 'lib/sidekiq/web/application.rb', line 466
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) ⇒ Object
46
47
48
|
# File 'lib/sidekiq/web/application.rb', line 46
def self.set(key, val)
end
|
.settings ⇒ Object
38
39
40
|
# File 'lib/sidekiq/web/application.rb', line 38
def self.settings
Sidekiq::Web.settings
end
|
.tabs ⇒ Object
42
43
44
|
# File 'lib/sidekiq/web/application.rb', line 42
def self.tabs
Sidekiq::Web.tabs
end
|
Instance Method Details
#call(env) ⇒ Object
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
|
# File 'lib/sidekiq/web/application.rb', line 409
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
resp
else
= {
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)
}
[200, , [resp]]
end
end
|
#process_csp(env, input) ⇒ Object
438
439
440
|
# File 'lib/sidekiq/web/application.rb', line 438
def process_csp(env, input)
input.gsub("!placeholder!", env[:csp_nonce])
end
|
#settings ⇒ Object
34
35
36
|
# File 'lib/sidekiq/web/application.rb', line 34
def settings
@klass.settings
end
|