Class: Hatetepe::Server::RackApp

Inherits:
Object
  • Object
show all
Defined in:
lib/hatetepe/server/rack_app.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, connection) ⇒ RackApp

Returns a new instance of RackApp.



3
4
5
# File 'lib/hatetepe/server/rack_app.rb', line 3

def initialize(app, connection)
  @app, @connection = app, connection
end

Instance Method Details

#async_callback(response, &respond) ⇒ Object



21
22
23
24
25
# File 'lib/hatetepe/server/rack_app.rb', line 21

def async_callback(response, &respond)
  if response[0] >= 0
    respond.call(Hatetepe::Response.new(*response))
  end
end

#call(request, &respond) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/hatetepe/server/rack_app.rb', line 7

def call(request, &respond)
  env = env_for(request)
  env["async.callback"] = proc do |response|
    async_callback(response, &respond)
  end

  response = [ -1 ]
  catch :async do
    response = @app.call(env)
  end

  async_callback(response, &respond)
end

#env_for(request) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hatetepe/server/rack_app.rb', line 27

def env_for(request)
  request.to_h.merge({
    "SERVER_NAME"       => @connection.config[:host],
    "SERVER_PORT"       => @connection.config[:port].to_s,
    "rack.errors"       => $stderr,
    "rack.multithread"  => false,
    "rack.multiprocess" => false,
    "rack.run_once"     => false,
    "rack.url_scheme"   => "http"
  })
end