Class: Yarn::RackHandler

Inherits:
RequestHandler show all
Defined in:
lib/yarn/rack_handler.rb

Instance Attribute Summary

Attributes inherited from RequestHandler

#parser, #request, #response, #session

Instance Method Summary collapse

Methods inherited from RequestHandler

#client_address, #close_connection, #execute_script, #extract_path, #get_mime_type, #parse_request, #persistent?, #read_file, #read_request, #request_path, #return_response, #run, #serve_directory, #serve_file, #set_common_headers

Methods included from ErrorPage

#serve_404_page, #serve_500_page

Methods included from Logging

#debug, #log, #output, #timestamp

Constructor Details

#initialize(app, opts) ⇒ RackHandler

Returns a new instance of RackHandler.



7
8
9
10
11
# File 'lib/yarn/rack_handler.rb', line 7

def initialize(app, opts)
  super(opts)
  @host,@port = opts[:host], opts[:port]
  @app = app
end

Instance Method Details

#make_envObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/yarn/rack_handler.rb', line 23

def make_env
  env = {
    "REQUEST_METHOD"    => @request[:method].to_s,
    "PATH_INFO"         => @request[:uri][:path].to_s,
    "QUERY_STRING"      => @request[:uri][:query].to_s,
    "SERVER_NAME"       => @host || @request[:uri][:host].to_s,
    "SERVER_PORT"       => @port.to_s || @request[:uri][:port].to_s,
    "SCRIPT_NAME"       => "",
    "rack.input"        => StringIO.new("").set_encoding(Encoding::ASCII_8BIT),
    "rack.version"      => Rack::VERSION,
    "rack.errors"       => $output,
    "rack.multithread"  => true,
    "rack.multiprocess" => false,
    "rack.run_once"     => false,
    "rack.url_scheme"   => "http"
  }
end

#prepare_responseObject



13
14
15
16
17
18
19
20
21
# File 'lib/yarn/rack_handler.rb', line 13

def prepare_response
  begin
    env = make_env
    @response.content = @app.call(env)
  rescue Exception => e
    log e.message
    log e.backtrace
  end
end