Class: Rack::Handler::Trusted

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/handler/trusted.rb

Class Method Summary collapse

Class Method Details

.run(app, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rack/handler/trusted.rb', line 8

def self.run(app, options = {})
  ::Trusted::Server.new("0.0.0.0:3000").listen do |request, response|
    puts "REQUEST: [#{request.method}] #{request.uri}"
    puts "PATH_INFO: #{request.path_info}"
    puts "QUERY_STRING: #{request.query_string}"
    puts "REMOTE_ADDR: #{request.remote_addr.inspect}"
    puts "SERVER_PORT: #{request.server_port.inspect}"
    puts "REQUEST HEADERS: #{request.headers.inspect}"

    rack_input = StringIO::new(request.body)

    env = {
      'REQUEST_METHOD' => request.method,
      'REQUEST_URI' => request.uri,
      'PATH_INFO' => request.path_info,
      'QUERY_STRING' => request.query_string,
      'REMOTE_ADDR' => request.remote_addr,
      'SERVER_PORT' => '3000',
      'SERVER_NAME' => 'localhost',
      'SCRIPT_NAME' => '',
      'rack.version' => Rack::VERSION,
      'rack.input' => rack_input,
      'rack.errors' => $stderr,
      'rack.multithread' => false,
      'rack.multiprocess' => false,
      'rack.run_once' => false,
      'rack.url_scheme' => 'http',
      'rack.hijack?' => false
    }

    env.merge!(request.headers)

    status, headers, body = app.call(env)

    response.status = status
    response.headers = headers

    response.body = ''

    body.each { |b| response.body.concat(b) }

    body.close if body.respond_to?(:close)
  end
end