Class: Rack::Unpoly::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/unpoly/middleware.rb

Overview

Rack Middleware that implements the server protocol expected by Unpoly, and provides an entry point into the Rack::Unpoly::Inspector for the current request.

Accessing the Rack::Unpoly::Inspector

An inspector for the current request is available inside env. You can access any of the inspector methods through this env variable.

env["rack.unpoly"].up?

Middleware Usage Example

require "rack"
require "rack/unpoly/middleware"

use Rack::Unpoly::Middleware

run ->(env) { [200, {}, ["Hello World"]] }

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Middleware.



28
29
30
# File 'lib/rack/unpoly/middleware.rb', line 28

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



33
34
35
36
37
38
39
40
41
# File 'lib/rack/unpoly/middleware.rb', line 33

def call(env)
  request = Rack::Request.new(env)
  env["rack.unpoly"] = Inspector.new(request)

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

  [status, headers, response]
end