lib/falcon/adapters/rack.rb in falcon-0.18.7 vs lib/falcon/adapters/rack.rb in falcon-0.18.8

- old
+ new

@@ -30,10 +30,23 @@ @app = app @logger = logger end + # Rack separates multiple headers with the same key, into a single field with multiple "lines". + def unwrap_headers(headers, env) + headers.each do |key, value| + http_key = "HTTP_#{key.upcase.tr('-', '_')}" + + if current_value = env[http_key] + env[http_key] = "#{current_value}\n#{value}" + else + env[http_key] = value + end + end + end + def call(request) request_path, query_string = request.path.split('?', 2) server_name, server_port = (request.authority || '').split(':', 2) env = { @@ -73,13 +86,11 @@ if content_length = request.headers.delete('content-length') env['CONTENT_LENGTH'] = content_length end - request.headers.each do |key, value| - env["HTTP_#{key.upcase.tr('-', '_')}"] = value - end + self.unwrap_headers(request.headers, env) if remote_address = request.remote_address env['REMOTE_ADDR'] = remote_address.ip_address if remote_address.ip? end @@ -113,10 +124,10 @@ # if env['rack.hijack_io'] # return nil # end @logger.debug(request) {"Rack response: #{status} #{headers.inspect} #{body.class}"} - return Response.new(status, headers, body) + return Response.wrap(status, headers, body) rescue => exception @logger.error "#{exception.class}: #{exception.message}\n\t#{$!.backtrace.join("\n\t")}" return failure_response(exception) end