Method: FTW::WebServer#handle_request

Defined in:
lib/ftw/webserver.rb

#handle_request(request, connection) ⇒ Object

Handle a request. This will set up the rack ‘env’ and invoke the application associated with this handler.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ftw/webserver.rb', line 71

def handle_request(request, connection)
  response = FTW::Response.new
  response.version = request.version
  response["Connection"] = request.headers["Connection"] || "close"

  # Process this request with the handler
  @handler.call(request, response, connection)

  # Write the response
  begin
    connection.write(response.to_s + CRLF)
    if response.body?
      write_http_body(response.body, connection,
                      response["Transfer-Encoding"] == "chunked") 
    end
  rescue => e
    @logger.error(e)
    connection.disconnect(e.inspect)
  end

  if response["Connection"] == "close" or response["Connection"].nil?
    connection.disconnect("'Connection' header was close or nil")
  end
end