Class: HTTPcap::Message
- Inherits:
-
Object
- Object
- HTTPcap::Message
- Defined in:
- lib/httpcap/message.rb
Overview
Message is a abstract class for Request and Response
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
-
#initialize(type, data) ⇒ Message
constructor
A new instance of Message.
- #on_body(data) ⇒ Object
- #on_header_field(value) ⇒ Object
- #on_header_value(value) ⇒ Object
- #on_headers_complete ⇒ Object
- #on_message_complete ⇒ Object
- #on_url ⇒ Object
- #receive_data(data) ⇒ Object
Constructor Details
#initialize(type, data) ⇒ Message
Returns a new instance of Message.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/httpcap/message.rb', line 13 def initialize(type, data) @parser = HTTP::Parser.new(type) @headers = Headers.new @body = '' %i[on_message_complete on_url on_header_field on_header_value on_headers_complete on_body].each do |name| @parser.send(name, &method(name)) end receive_data(data) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
10 11 12 |
# File 'lib/httpcap/message.rb', line 10 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
10 11 12 |
# File 'lib/httpcap/message.rb', line 10 def headers @headers end |
Instance Method Details
#on_body(data) ⇒ Object
44 45 46 |
# File 'lib/httpcap/message.rb', line 44 def on_body(data) @body += data end |
#on_header_field(value) ⇒ Object
32 33 34 |
# File 'lib/httpcap/message.rb', line 32 def on_header_field(value) @headers.stream(Headers::TYPE_FIELD, value) end |
#on_header_value(value) ⇒ Object
36 37 38 |
# File 'lib/httpcap/message.rb', line 36 def on_header_value(value) @headers.stream(Headers::TYPE_VALUE, value) end |
#on_headers_complete ⇒ Object
40 41 42 |
# File 'lib/httpcap/message.rb', line 40 def on_headers_complete @headers.stream_complete end |
#on_message_complete ⇒ Object
28 |
# File 'lib/httpcap/message.rb', line 28 def ; end |
#on_url ⇒ Object
30 |
# File 'lib/httpcap/message.rb', line 30 def on_url; end |
#receive_data(data) ⇒ Object
24 25 26 |
# File 'lib/httpcap/message.rb', line 24 def receive_data(data) @parser << data end |