Class: GThang::RackHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/g_thang/rack_handler.rb

Constant Summary collapse

StatusCodeMapping =
{
  200 => "OK",
  400 => "Bad Request",
  403 => "Forbidden",
  405 => "Method Not Allowed",
  411 => "Length Required",
  500 => "Internal Server Error"
}
DefaultResponseHeaders =
{
  "Connection" => "close",
  "Content-Type" => "text/html"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket, app, port) ⇒ RackHandler

Returns a new instance of RackHandler.



24
25
26
27
28
29
30
31
32
33
# File 'lib/g_thang/rack_handler.rb', line 24

def initialize(socket, app, port)
  @socket = socket
  @app = app
  @env = {
    "GATEWAY_INTERFACE" => "CGI/1.1", 
    "SCRIPT_NAME" => "",
    "SERVER_NAME" => Socket.gethostname,
    "SERVER_PORT" => port.to_s
  }
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



22
23
24
# File 'lib/g_thang/rack_handler.rb', line 22

def app
  @app
end

#envObject (readonly)

Returns the value of attribute env.



22
23
24
# File 'lib/g_thang/rack_handler.rb', line 22

def env
  @env
end

#portObject (readonly)

Returns the value of attribute port.



22
23
24
# File 'lib/g_thang/rack_handler.rb', line 22

def port
  @port
end

#socketObject (readonly)

Returns the value of attribute socket.



22
23
24
# File 'lib/g_thang/rack_handler.rb', line 22

def socket
  @socket
end

Instance Method Details

#handle_requestObject



35
36
37
38
39
40
41
# File 'lib/g_thang/rack_handler.rb', line 35

def handle_request
  return unless add_rack_variables_to_env
  return unless add_connection_info_to_env
  return unless add_request_line_info_to_env
  return unless add_headers_to_env
  send_response(app.call(env))
end