3
4
5
6
7
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
|
# File 'lib/MLserver/request_parser.rb', line 3
def self.parse_request(client)
keepReading = true
= {}
data = ""
req = client.gets.to_s
while req.gsub("\r\n", "") == "" do
req = client.gets.to_s
end
if req.to_s.length < 14
client.puts ErrorResponse.new(400).response.to_s
client.close
Thread.exit
end
while keepReading do
x = client.gets.to_s
if x.chomp.length == 0
keepReading = false
else
if x.split(": ").length < 2
client.puts ErrorResponse.new(400).response.to_s
client.close
Thread.exit
end
[x.split(": ")[0].to_sym] = x.split(": ")[1].chomp
end
end
data = client.read([:"Content-Length"].to_i)
return Request.new(headers: , request: req, data: data, client: client)
end
|