Method: HTTPTools::Parser#env
- Defined in:
- lib/http_tools/parser.rb
#env ⇒ Object
:call-seq: parser.env -> hash or nil
Returns a Rack compatible environment hash. Will return nil if called before headers are complete.
“SERVER_NAME” and “SERVER_PORT” are only supplied if they can be determined from the request (eg, they are present in the “Host” header).
“rack.input” is only supplied if #env is called after parsing the request has finsished, and no listener is set for the stream event
If not supplied, you must ensure “SERVER_NAME”, “SERVER_PORT”, and “rack.input” are present to make the environment hash fully Rack compliant
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/http_tools/parser.rb', line 138 def env return unless @header_complete env = PROTOTYPE_ENV.dup env[REQUEST_METHOD] = @request_method.upcase env[PATH_INFO] = @path_info env[QUERY_STRING] = @query_string @header.each do |key, value| upper_key = key.tr(LOWERCASE, UPPERCASE) upper_key[0,0] = HTTP_ unless NO_HTTP_.key?(upper_key) env[upper_key.freeze] = value end host, port = env[HTTP_HOST].split(COLON) if env.key?(HTTP_HOST) env[SERVER_NAME] = host if host env[SERVER_PORT] = port if port @trailer.each {|k, val| env[HTTP_ + k.tr(LOWERCASE, UPPERCASE)] = val} if @body || @stream_callback == method(:setup_stream_callback) env[RACK_INPUT] = StringIO.new(@body || "") end env end |