Class: Hotwire::Spark::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/hotwire/spark/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



2
3
4
# File 'lib/hotwire/spark/middleware.rb', line 2

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/hotwire/spark/middleware.rb', line 6

def call(env)
  status, headers, response = @app.call(env)

  @request = ActionDispatch::Request.new(env)

  if interceptable_request? && html_response?(headers)
    html = html_from(response)
    html = inject_options(html)
    html = inject_javascript(html)
    headers["Content-Length"] = html.bytesize.to_s if html
    response = [ html ]
  end

  [ status, headers, response ]
end