Class: Wsv::Request::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/wsv/request/parser.rb

Constant Summary collapse

REQUEST_LINE_LIMIT =
8192
HEADER_LINE_LIMIT =
8192
HEADER_COUNT_LIMIT =
100
HEADER_TOTAL_LIMIT =
16_384

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Parser

Returns a new instance of Parser.



11
12
13
# File 'lib/wsv/request/parser.rb', line 11

def initialize(io)
  @io = io
end

Instance Method Details

#parseObject

Raises:



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wsv/request/parser.rb', line 15

def parse
  line = @io.gets(REQUEST_LINE_LIMIT)
  return :empty unless line
  raise TooLarge, 414 if line.bytesize >= REQUEST_LINE_LIMIT && !line.end_with?("\n")

  method, target, version = line.split(/\s+/, 3)
  version = version&.strip
  return :malformed unless method && target && version&.start_with?("HTTP/")

  Request.new(method: method, target: target, version: version, headers: read_headers)
end