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
|
# File 'lib/envoy/server/web.rb', line 18
def receive_line line
@first_line ||= line
if line == ""
trunk = Trunk.trunks[@host].sample || raise("No trunk for #{@host}.#{$zone}")
@header << "Connection: #{@connection}\r\n\r\n"
@channel = Channel.new(trunk, self, @header)
@channel.message "%s %s" % [Socket.unpack_sockaddr_in(get_peername)[1], @first_line]
set_text_mode
elsif line =~ /^connection:\s*upgrade$/i
@connection = "upgrade"
elsif line =~ /^keep-alive:/i
elsif line =~ /^host:\s*([^:]*)/i
@host = $1
raise "Request for #{@host} is not in #{$zone}" unless @host.end_with?($zone)
@host = @host[0...-$zone.length]
@host = @host.split(".").last
@header << line + "\r\n"
elsif @header.size > 4096
raise "Header's too long for my liking"
else
@header << line + "\r\n"
end
rescue RuntimeError => e
send_data "HTTP/1.0 500 Internal Server Error\r\n"
send_data "Content-Type: text/plain\r\n"
send_data "\r\n"
send_data "#{e.message}\r\n"
close_connection true
end
|