class LLHttp::Parser
Call ‘LLHttp::Parser#finish` when processing is complete for the current request or response.
Finishing
* `LLHttp::Parser#keep_alive?` returns `true` if there might be more messages.
* `LLHttp::Parser#http_minor` returns the minor http version of the current request/response.
* `LLHttp::Parser#http_major` returns the major http version of the current request/response.
* `LLHttp::Parser#status_code` returns the status code of the current response.
* `LLHttp::Parser#method_name` returns the method name of the current response.
* `LLHttp::Parser#content_length` returns the content length of the current request.
Introspection
…
parser.finish
parser << “GET / HTTP/1.1rnrn”
parser = LLHttp::Parser.new(Delegate.new, type: :request)
end
…
end
…
def on_message_begin
class Delegate < LLHttp::Delegate<br><br> Wraps an llhttp context for parsing http requests and responses.
def self.free(pointer)
def self.free(pointer) proc { LLHttp.rb_llhttp_free(pointer) } end
def build_error(errno)
def build_error(errno) new("Error Parsing data: #{LLHttp.llhttp_errno_name(errno)} #{LLHttp.llhttp_get_error_reason(@pointer)}")
def content_length
[public] Get the content length of the current request.
def content_length LLHttp.rb_llhttp_content_length(@pointer) end
def finish
[public] Tells the parser we are finished.
def finish LLHttp.llhttp_finish(@pointer) end
def http_major
[public] Get the major http version of the current request/response.
def http_major LLHttp.rb_llhttp_http_major(@pointer) end
def http_minor
[public] Get the minor http version of the current request/response.
def http_minor LLHttp.rb_llhttp_http_minor(@pointer) end
def initialize(delegate, type: :both)
def initialize(delegate, type: :both) @type, @delegate = type.to_sym, delegate @callbacks = Callbacks.new (CALLBACKS + CALLBACKS_WITH_DATA).each do |callback| if delegate.respond_to?(callback) @callbacks[callback] = method(callback).to_proc end end @pointer = LLHttp.rb_llhttp_init(LLHTTP_TYPES.fetch(@type), @callbacks) ObjectSpace.define_finalizer(self, self.class.free(@pointer)) end
def keep_alive?
[public] Returns `true` if there might be more messages.
def keep_alive? LLHttp.llhttp_should_keep_alive(@pointer) == 1 end
def method_name
[public] Get the method of the current response.
def method_name LLHttp.rb_llhttp_method_name(@pointer) end
def parse(data)
[public] Parse the given data.
def parse(data) errno = LLHttp.llhttp_execute(@pointer, data, data.length) raise build_error(errno) if errno > 0 end
def reset
[public] Get ready to parse the next request/response.
def reset LLHttp.llhttp_reset(@pointer) end
def status_code
[public] Get the status code of the current response.
def status_code LLHttp.rb_llhttp_status_code(@pointer) end