Top Level Namespace

Defined Under Namespace

Modules: Polyphony Classes: Agent, HTTP1Adapter, HTTP2Adapter, InputStream, Response, SiteConnectionManager, WebsocketConnection

Constant Summary collapse

ResourcePool =
import '../../core/resource_pool'

Instance Method Summary collapse

Instance Method Details

#env(request) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/polyphony/http/server/rack.rb', line 34

def env(request)
  {
    'REQUEST_METHOD'                 => request.method,
    'SCRIPT_NAME'                    => '',
    'PATH_INFO'                      => request.path,
    'QUERY_STRING'                   => request.query_string || '',
    'SERVER_NAME'                    => request.headers['Host'], # ?
    'SERVER_PORT'                    => '80', # ?
    'rack.version'                   => Rack::VERSION,
    'rack.url_scheme'                => 'https', # ?
    'rack.input'                     => InputStream.new(request),
    'rack.errors'                    => STDERR, # ?
    'rack.multithread'               => false,
    'rack.run_once'                  => false,
    'rack.hijack?'                   => false,
    'rack.hijack'                    => nil,
    'rack.hijack_io'                 => nil,
    'rack.session'                   => nil,
    'rack.logger'                    => nil,
    'rack.multipart.buffer_size'     => nil,
    'rack.multipar.tempfile_factory' => nil
  }.tap do |env|
    request.headers.each { |k, v| env["HTTP_#{k.upcase}"] = v }
  end
end

#handler(&block) ⇒ Object



55
56
57
58
59
# File 'lib/polyphony/websocket.rb', line 55

def handler(&block)
  proc { |client, header|
    block.(WebsocketConnection.new(client, header))
  }
end

#load(path) ⇒ Object



11
12
13
14
# File 'lib/polyphony/http/server/rack.rb', line 11

def load(path)
  src = IO.read(path)
  instance_eval(src, path, 1)
end

#respond(request, status_code, headers, body) ⇒ Object



60
61
62
63
64
# File 'lib/polyphony/http/server/rack.rb', line 60

def respond(request, (status_code, headers, body))
  headers[':status'] = status_code.to_s
  puts "headers: #{headers.inspect}"
  request.respond(body.first, headers)
end

#run(app) ⇒ Object



7
8
9
# File 'lib/polyphony/http/server/rack.rb', line 7

def run(app)
  ->(req) { respond(req, app.(env(req))) }
end