class Rack2
Definitions
def call(request)
Build a rack env
from the incoming request and apply it to the rack middleware.
Signature
-
parameter
request
Protocol::HTTP::Request
The incoming request.
Implementation
def call(request)
env = self.make_environment(request)
status, headers, body = @app.call(env)
headers, meta = self.wrap_headers(headers)
# Rack 2 spec does not allow only partial hijacking.
# if hijack_body = meta[RACK_HIJACK]
# body = hijack_body
# end
return Response.wrap(env, status, headers, meta, body, request)
rescue => exception
Console.error(self, exception)
body&.close if body.respond_to?(:close)
return failure_response(exception)
end
def wrap_headers(fields)
Process the rack response headers into into a Protocol::HTTP::Headers
instance, along with any extra rack.
metadata.
Signature
-
returns
Tuple(Protocol::HTTP::Headers, Hash)
Implementation
def wrap_headers(fields)
headers = ::Protocol::HTTP::Headers.new
meta = {}
fields.each do |key, value|
key = key.downcase
if key.start_with?("rack.")
meta[key] = value
elsif value.is_a?(String)
value.split("\n").each do |value|
headers[key] = value
end
else
headers[key] = value
end
end
return headers, meta
end