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 GenericThe base adapter class that provides common functionality for all Rack adapters. It handles the conversion between
Protocol::HTTPand Rack environments.class Rack2The Rack 2 adapter provides compatibility with Rack 2.x applications. It handles the conversion between
Protocol::HTTPand Rack 2 environments.class Rack3The Rack 3 adapter provides compatibility with Rack 3.x applications. It handles the conversion between
Protocol::HTTPand Rack 3 environments. Unlike Rack 2, this adapter supports streaming responses and has a simpler environment setup.class Rack31The 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:
- Better handling of empty request bodies
- Direct protocol support via
RACK_PROTOCOL = "rack.protocol" - More efficient body streaming
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
appInterface(: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
envHash The Rack environment.
-
parameter
responseArray 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
pathString The path to the Rackup file.
-
returns
Interface(:call) The parsed Rack application.
Implementation
def self.parse_file(...)
IMPLEMENTATION.parse_file(...)
end