156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/nuhttp/server.rb', line 156
def parse_request(io)
request_line = io.gets("\r\n").chomp
method, request_target, _http_version = request_line.split(' ', 3)
= {}
while line = io.gets("\r\n").chomp
break if line.empty?
, = line.split(':', 2)
[] = .strip
end
path, query = request_target.split('?')
query ||= ''
body =
if length = ['Content-Length'] io.read(length.to_i)
else
nil
end
Request.new(method:, path:, query:, headers:, body:)
end
|