Class: LLHttp::Parser

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

Overview

Wraps an llhttp context for parsing http requests and responses.

Finishing

Call ‘LLHttp::Parser#finish` when processing is complete for the current request or response.

Introspection

  • ‘LLHttp::Parser#content_length` returns the content length of the current request.

  • ‘LLHttp::Parser#method` returns the method of the current response.

  • ‘LLHttp::Parser#keep_alive?` returns true if there might be any other messages following the last that was successfuly parsed.

Constant Summary collapse

LLHTTP_TYPES =
{both: 0, request: 1, response: 2}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(delegate, type: :both) ⇒ Parser

Returns a new instance of Parser.



21
22
23
24
25
# File 'lib/llhttp/parser.rb', line 21

def initialize(delegate, type: :both)
  @type, @delegate = type.to_sym, delegate

  llhttp_init(LLHTTP_TYPES.fetch(@type))
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



19
20
21
# File 'lib/llhttp/parser.rb', line 19

def type
  @type
end