lib/reel/connection.rb
# Send a response back to the client
# Response can be a symbol indicating the status code or a Reel::Response
Send a response back to the client
Response can be a symbol indicating the status code or a Reel::Response
Send a response back to the client Response can be a symbol indicating the status code or a Reel :: Response
def respond(response, headers_or_body = {}, body = nil)
      raise StateError "not in header state" if @response_state != :header
      if headers_or_body.is_a? Hash
        headers = headers_or_body
      else
        headers = {}
        body = headers_or_body
      end
      if @keepalive
        headers[CONNECTION] = KEEP_ALIVE
      else
        headers[CONNECTION] = CLOSE
      end
      case response
      when Symbol
        response = Response.new(response, headers, body)
      when Response
      else raise TypeError, "invalid response: #{response.inspect}"
      end
      response.render(@socket)
      if response.headers[TRANSFER_ENCODING] == CHUNKED and response.body.nil?
        @response_state = :chunked_body
      end
    rescue IOError, Errno::ECONNRESET, Errno::EPIPE
      @keepalive = false
    ensure
      if @keepalive
        reset_request(:header)
      else
        @socket.close unless @socket.closed?
        reset_request(:closed)
      end
    end
def respond ( response , headers_or_body = { } , body = nil ) raise StateError "not in header state" if @response_state != :header if headers_or_body . is_a? Hash headers = headers_or_body else headers = { } body = headers_or_body end if @keepalive headers [ CONNECTION ] = KEEP_ALIVE else headers [ CONNECTION ] = CLOSE end case response when Symbol response = Response . new ( response , headers , body ) when Response else raise TypeError , "invalid response: #{response.inspect}" end response . render ( @socket ) if response . headers [ TRANSFER_ENCODING ] == CHUNKED and response . body . nil? @response_state = :chunked_body end rescue IOError , Errno :: ECONNRESET , Errno :: EPIPE @keepalive = false ensure if @keepalive reset_request ( :header ) else @socket . close unless @socket . closed? reset_request ( :closed ) end end
Send a response back to the client
Response can be a symbol indicating the status code or a Reel::Response
Send a response back to the client Response can be a symbol indicating the status code or a Reel :: Response
# Enable streaming mode # The client disconnected early
response
<not_specific>
headers_or_body
<not_specific>
body
<not_specific>