8
9
10
11
12
13
14
15
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
|
# File 'lib/rdkit/http_responder.rb', line 8
def run(cmd)
method, path = cmd.first.split('|')
status, , body = case method
when 'get'
if @@endpoints_get[path]
status, , body = @@endpoints_get[path].call
[status, .merge(), body]
else
error_404
end
else
error_404
end
response = Rack::Response.new(body, status, )
status, , body = response.finish
out = StringIO.new
out.print "HTTP/1.1: #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]}\r\n"
.each do |k, vs|
vs.split("\n").each { |v| out.print "#{k}: #{v}\r\n"; }
end
out.print "\r\n"
out.flush
body.each do |part|
out.print part; out.flush
end
out.string
end
|