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.
“rack.input” is only supplied if #env is called after parsing the request has finsished, and no listener is set for the stream event, otherwise you must add it yourself to make the environment hash fully Rack compliant
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/http_tools/parser.rb', line 126 def env return unless @header_complete env = PROTOTYPE_ENV.dup env[REQUEST_METHOD] = @request_method env[PATH_INFO] = @path_info env[QUERY_STRING] = @query_string @header.each do |key, value| upper_key = key.tr(LOWERCASE, UPPERCASE) upper_key = HTTP_ + upper_key unless NO_HTTP_.key?(upper_key) env[upper_key] = value end host, port = env[HTTP_HOST].split(COLON) env[SERVER_NAME] = host env[SERVER_PORT] = port || "80" @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 |