lib/goliath/connection.rb in goliath-1.0.5 vs lib/goliath/connection.rb in goliath-1.0.6

- old
+ new

@@ -21,16 +21,17 @@ @pending = [] @parser = Http::Parser.new @parser.on_headers_complete = proc do |h| env = Goliath::Env.new - env[SERVER_PORT] = port.to_s - env[RACK_LOGGER] = logger - env[OPTIONS] = options - env[STATUS] = status - env[CONFIG] = config - env[REMOTE_ADDR] = remote_address + env[SERVER_PORT] = port.to_s + env[RACK_LOGGER] = logger + env[OPTIONS] = options + env[STATUS] = status + env[CONFIG] = config + env[REMOTE_ADDR] = remote_address + env[RACK_URL_SCHEME] = options[:ssl] ? "https" : "http" r = Goliath::Request.new(@app, self, env) r.parse_header(h, @parser) do env[ASYNC_HEADERS] = api.method(:on_headers) if api.respond_to?(:on_headers) env[ASYNC_BODY] = api.method(:on_body) if api.respond_to?(:on_body) @@ -39,11 +40,12 @@ @requests.push(r) end @parser.on_body = proc do |data| - @requests.first.parse(data) + req = @requests.first + req.parse(data) unless req.env[:terminate_connection] end @parser.on_message_complete = proc do req = @requests.shift @@ -81,18 +83,20 @@ @pending.map { |r| r.close } @current.close if @current end def terminate_request(keep_alive) - if req = @pending.shift - @current = req - @current.succeed - elsif @current + if @current @current.close @current = nil end close_connection_after_writing rescue nil if !keep_alive + + if req = @pending.shift + @current = req + @current.succeed + end end def remote_address Socket.unpack_sockaddr_in(get_peername)[1] rescue Exception