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
|
# File 'lib/hoof/http_server.rb', line 16
def process_http_request
p 'DATA'
p @buffer
begin
host = @http_headers.scan(/Host:\s*([-a-zA-z.]*)\000/)[0][0].gsub(/:\d+$/, '')
close_connection and return unless host =~ /.dev$/
name = host.gsub(/.dev$/, '')
application = Hoof.find name
if application
if application.static_file? @http_path_info
puts "Serve static #{host}#{@http_request_uri}"
send_data application.serve_static(@http_path_info)
close_connection_after_writing
else
application.start
puts "Serve #{host}#{@http_request_uri}"
EventMachine.defer(proc {
application.serve @buffer
}, proc { |result|
send_data result
close_connection_after_writing
})
end
else
close_connection
end
rescue => e
puts e.message
puts e.backtrace.join("\n")
close_connection
end
end
|