class HttpParser::Instance


Effectively this represents a request instance

def data

Returns:
  • (FFI::Pointer) -
def data
    self[:data]
end

def error

Returns:
  • (StandarError) -
def error
    error = (self[:error_upgrade] & 0b1111111)
    return nil if error == 0
    err = ::HttpParser.err_name(error)[4..-1] # HPE_ is at the start of all these errors
    klass = ERRORS[err.to_sym]
    err = "#{::HttpParser.err_desc(error)} (#{err})"
    return klass.nil? ? Error::UNKNOWN.new(err) : klass.new(err)
end

def error!


Indicates an error has occurred when called in a callback
def error!
    throw :return, -1
end

def error?

Returns:
  • (Boolean) -
def error?
    error = (self[:error_upgrade] & 0b1111111)
    return error != 0
end

def final_chunk?

Returns:
  • (Boolean) -
def final_chunk?
    ::HttpParser.http_body_is_final(self) > 0
end

def flags

Returns:
  • (Integer) -
def flags
    (self[:type_flags] & 0xfc)
end

def http_major

Returns:
  • (Integer) -
def http_major
    self[:http_major]
end

def http_method

Other tags:
    See: http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.1 -

Returns:
  • (Symbol) -
def http_method
    METHODS[self[:method]]
end

def http_minor

Returns:
  • (Integer) -
def http_minor
    self[:http_minor]
end

def http_status

Other tags:
    See: http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1.1 -

Returns:
  • (Integer) -
def http_status
    self[:status_code]
end

def http_version

Returns:
  • (String) -
def http_version
    "%d.%d" % [self[:http_major], self[:http_minor]]
end

def initialize(ptr = nil)

def initialize(ptr = nil)
    if ptr then super(ptr)
    else
        super()
        self.type = :both
    end
    yield self if block_given?
    ::HttpParser.http_parser_init(self, self.type) unless ptr
end

def keep_alive?

Other tags:
    See: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.10 -

Returns:
  • (Boolean) -
def keep_alive?
    ::HttpParser.http_should_keep_alive(self) > 0
end

def reset!(new_type = type)

Parameters:
  • new_type (:request, :response, :both) --
def reset!(new_type = type)
    ::HttpParser.http_parser_init(self, new_type)
end

def stop!


Halts the parser if called in a callback
def stop!
    throw :return, 1
end

def type

Returns:
  • (:request, :response, :both) -
def type
    TYPES[self[:type_flags] & 0x3]
end

def type=(new_type)

Parameters:
  • new_type (:request, :response, :both) --
def type=(new_type)
    self[:type_flags] = (flags | TYPES[new_type])
end

def upgrade?

Other tags:
    See: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.42 -

Returns:
  • (Boolean) -
def upgrade?
    (self[:error_upgrade] & 0b10000000) > 0
end