Class: SidekiqWebTheme::Middleware
- Inherits:
-
Object
- Object
- SidekiqWebTheme::Middleware
- Defined in:
- lib/sidekiq_web_theme/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
5 6 7 |
# File 'lib/sidekiq_web_theme/middleware.rb', line 5 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sidekiq_web_theme/middleware.rb', line 9 def call(env) status, headers, body = @app.call(env) return [status, headers, body] unless html_response?(headers) html = +"" body.each { |part| html << part } body.close if body.respond_to?(:close) return [status, headers, [html]] unless html.include?("</head>") html = html.sub("</head>", "#{style_tag(env[:csp_nonce])}</head>") headers["content-length"] = html.bytesize.to_s [status, headers, [html]] end |