module Adapter

The Rack adapter provides a bridge between Protocol::HTTP and Rack applications. It automatically selects the appropriate implementation based on the installed Rack version.

app = ->(env) { [200, {"content-type" => "text/plain"}, ["Hello World"]] }
adapter = Protocol::Rack::Adapter.new(app)
response = adapter.call(request)

Nested Classes and Modules

class Generic

The base adapter class that provides common functionality for all Rack adapters. It handles the conversion between Protocol::HTTP and Rack environments.

class Rack2

The Rack 2 adapter provides compatibility with Rack 2.x applications. It handles the conversion between Protocol::HTTP and Rack 2 environments.

class Rack3

The Rack 3 adapter provides compatibility with Rack 3.x applications. It handles the conversion between Protocol::HTTP and Rack 3 environments. Unlike Rack 2, this adapter supports streaming responses and has a simpler environment setup.

class Rack31

The Rack 3.1 adapter provides compatibility with Rack 3.1.x applications. It extends the Rack 3 adapter with improved request body handling and protocol support. Key improvements include:

Definitions

VERSION = ENV.fetch("PROTOCOL_RACK_ADAPTER_VERSION", ::Rack.release)

The version of Rack being used. Can be overridden using the PROTOCOL_RACK_ADAPTER_VERSION environment variable.

def self.new(app)

Creates a new adapter instance for the given Rack application.

Signature

parameter app Interface(:call)

A Rack application that responds to call.

returns Protocol::HTTP::Middleware

An adapter that can handle HTTP requests.

Implementation

def self.new(app)
	IMPLEMENTATION.wrap(app)
end

def self.make_response(env, response)

Converts a Rack response into a Protocol::HTTP::Response.

Signature

parameter env Hash

The Rack environment.

parameter response Array

The Rack response tuple [status, headers, body].

returns Protocol::HTTP::Response

A Protocol::HTTP response.

Implementation

def self.make_response(env, response)
	IMPLEMENTATION.make_response(env, response)
end

def self.parse_file(...)

Parses a Rackup file and returns the application.

Signature

parameter path String

The path to the Rackup file.

returns Interface(:call)

The parsed Rack application.

Implementation

def self.parse_file(...)
	IMPLEMENTATION.parse_file(...)
end