Class: Explorer::Server::HTTP

Inherits:
Reel::Server::HTTP
  • Object
show all
Defined in:
lib/explorer/server/http.rb

Instance Method Summary collapse

Constructor Details

#initialize(port, options = {}) ⇒ HTTP

Returns a new instance of HTTP.



6
7
8
9
10
# File 'lib/explorer/server/http.rb', line 6

def initialize(port, options={})
  @map = options.fetch(:hostmap) { Explorer.hostmap }

  super '0.0.0.0', port, {}, &method(:on_connection)
end

Instance Method Details

#handle_request(request) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/explorer/server/http.rb', line 18

def handle_request(request)
  map = @map.resolve(request.headers['Host'])
  if map
    Proxy.new(map[:host], map[:port]).handle(request)
  else
    request.respond 404, "Map not found (#{request.headers['Host']})"
  end

end

#on_connection(connection) ⇒ Object



12
13
14
15
16
# File 'lib/explorer/server/http.rb', line 12

def on_connection(connection)
  connection.each_request do |request|
    handle_request(request)
  end
end