Class: Protocol::Rack::Adapter::Rack31
- Defined in:
- lib/protocol/rack/adapter/rack31.rb
Overview
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:
-
Better handling of empty request bodies
-
Direct protocol support via RACK_PROTOCOL
-
More efficient body streaming
Instance Method Summary collapse
-
#make_environment(request) ⇒ Object
Create a Rack 3.1 environment hash for the request.
Methods inherited from Rack3
make_response, parse_file, wrap, #wrap_headers
Methods inherited from Generic
#call, extract_protocol, #failure_response, #handle_error, #initialize, #logger, parse_file, #unwrap_headers, #unwrap_request, wrap
Constructor Details
This class inherits a constructor from Protocol::Rack::Adapter::Generic
Instance Method Details
#make_environment(request) ⇒ Object
Create a Rack 3.1 environment hash for the request. Sets up all required Rack 3.1 environment variables and processes the request. Unlike Rack 3, this adapter has improved body handling and protocol support.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/protocol/rack/adapter/rack31.rb', line 27 def make_environment(request) request_path, query_string = request.path.split("?", 2) server_name, server_port = (request. || "").split(":", 2) env = { PROTOCOL_HTTP_REQUEST => request, RACK_ERRORS => $stderr, RACK_LOGGER => self.logger, # The response finished callbacks: RACK_RESPONSE_FINISHED => [], # The HTTP request method, such as "GET" or "POST". This cannot ever be an empty string, and so is always required. CGI::REQUEST_METHOD => request.method, # The initial portion of the request URL's "path" that corresponds to the application object, so that the application knows its virtual "location". This may be an empty string, if the application corresponds to the "root" of the server. CGI::SCRIPT_NAME => "", # The remainder of the request URL's "path", designating the virtual "location" of the request's target within the application. This may be an empty string, if the request URL targets the application root and does not have a trailing slash. This value may be percent-encoded when originating from a URL. CGI::PATH_INFO => request_path, CGI::REQUEST_PATH => request_path, CGI::REQUEST_URI => request.path, # The portion of the request URL that follows the ?, if any. May be empty, but is always required! CGI::QUERY_STRING => query_string || "", # The server protocol (e.g. HTTP/1.1): CGI::SERVER_PROTOCOL => request.version, # The request scheme: RACK_URL_SCHEME => request.scheme, # I'm not sure what sane defaults should be here: CGI::SERVER_NAME => server_name, } # SERVER_PORT is optional but must not be set if it is not present. if server_port env[CGI::SERVER_PORT] = server_port end # The request protocol, either from the upgrade header or the HTTP/2 pseudo header of the same name. if protocol = request.protocol env[RACK_PROTOCOL] = protocol end if body = request.body if body.empty? body.close else env[RACK_INPUT] = Input.new(body) end end self.unwrap_request(request, env) return env end |