Class: Wsv::Request::Parser
- Inherits:
-
Object
- Object
- Wsv::Request::Parser
- 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
-
#initialize(io) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
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
#parse ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/wsv/request/parser.rb', line 15 def parse line = @io.gets("\n", 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 |