Class: Xomponent::Server

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

Instance Method Summary collapse

Constructor Details

#initialize(port, content) ⇒ Server

Returns a new instance of Server.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/Xomponent/server.rb', line 5

def initialize(port, content)
  server = TCPServer.new port.to_i
  loop do
    client = server.accept
    headers = []
    while header = client.gets
      break if header.chomp.empty?
      headers << header.chomp
    end
    p headers

    client.puts "HTTP/1.0 200 OK"
    client.puts "Content-Type: text/html"
    client.puts
    client.puts content.render
    client.close
  end
end