Permalink
Browse files

send Connection: close if the client requested

  • Loading branch information...
1 parent f78cb0f commit fdfe9fc38975b47ba8b043bc9687a61672b2024c @dj2 dj2 committed Feb 16, 2011
Showing with 9 additions and 3 deletions.
  1. +2 −1 lib/goliath/connection.rb
  2. +7 −2 lib/goliath/response.rb
@@ -26,6 +26,7 @@ def receive_data(data)
end
def process
+ response.send_close = request.env[Goliath::Request::HEADERS]['Connection']
@igrigorik

igrigorik Feb 16, 2011

Owner

Response should already have all the headers parsed, this seems redundant. I think all you need is something like "response.persistent?" later in the code.

@dj2

dj2 Feb 16, 2011

Owner

Response doesn't have the headers from the client. Only the headers to respond to the client with.

@raggi

raggi Feb 18, 2011

Member

I'm with Ilya on this, I'd set the response up at construction time, not later on.

@dj2

dj2 Feb 18, 2011

Owner

The response is created when the connection is created. We can't set this option into the response until after we've received and parsed the headers from the client.

@igrigorik

igrigorik Feb 18, 2011

Owner

I think this goes away anyway.. working on it in the "keepalive" branch.

post_process(@app.call(@request.env))
rescue Exception => e
@@ -43,7 +44,7 @@ def async_process(results)
def stream_start(status, headers)
send_data(@response.head)
- send_data(@response.headers_output(:keep_alive => true))
+ send_data(@response.headers_output)
end
def stream_send(data)
View
@@ -17,14 +17,19 @@ class Response
def initialize
@headers = Goliath::Headers.new
@status = 200
+ @send_close = false
+ end
+
+ def send_close=(header)
+ @send_close = true if header && header.downcase == 'close'
end
def head
"HTTP/1.1 #{status} #{HTTP_STATUS_CODES[status.to_i]}\r\n"
end
- def headers_output(opts = {})
- headers[CONNECTION] = CLOSE unless opts[:keep_alive]
+ def headers_output
+ headers[CONNECTION] = CLOSE if @send_close
headers[SERVER] = Goliath::Request::SERVER
headers[DATE] = Time.now.httpdate

0 comments on commit fdfe9fc

Please sign in to comment.