Class: HTTP::Parser

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

Constant Summary collapse

TYPE_REQUEST =
0
TYPE_RESPONSE =
1
TYPE_BOTH =
2
CALLBACKS =
%w(on_url on_header_field on_header_value on_headers_complete on_body on_message_begin on_message_complete)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = TYPE_BOTH) ⇒ Parser

Returns a new instance of Parser.



19
20
21
22
# File 'lib/http-parser.rb', line 19

def initialize type = TYPE_BOTH
  @callbacks = {}
  reset(type)
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



17
18
19
# File 'lib/http-parser.rb', line 17

def type
  @type
end

Instance Method Details

#reset(value = nil) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/http-parser.rb', line 24

def reset value = nil
  if value
    raise ArgumentError, "Invalid parser type #{value}" unless [0, 1, 2].include?(value)
    @type = value
  end

  reset!(@type)
end