Class: RoadForest::HTTP::Message
- Inherits:
-
Object
- Object
- RoadForest::HTTP::Message
- Defined in:
- lib/roadforest/http/message.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
Instance Method Summary collapse
- #body ⇒ Object
- #body=(value) ⇒ Object
- #body_string ⇒ Object
- #body_string=(value) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Message
constructor
A new instance of Message.
- #inspect ⇒ Object
- #inspection_payload ⇒ Object
- #inspection_stream ⇒ Object
Constructor Details
#initialize ⇒ Message
Returns a new instance of Message.
9 10 11 12 |
# File 'lib/roadforest/http/message.rb', line 9 def initialize @body_string = "" @headers = {} end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
7 8 9 |
# File 'lib/roadforest/http/message.rb', line 7 def headers @headers end |
Instance Method Details
#body ⇒ Object
24 25 26 |
# File 'lib/roadforest/http/message.rb', line 24 def body return @body ||= StringIO.new(body_string||"") end |
#body=(value) ⇒ Object
19 20 21 22 |
# File 'lib/roadforest/http/message.rb', line 19 def body=(value) @body = value @body_string = nil end |
#body_string ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/roadforest/http/message.rb', line 28 def body_string @body_string ||= begin case @body when nil nil when StringIO @body.string when IO @body.rewind @body.read else raise "Unknown class for body: #{@body.class.name}" end end end |
#body_string=(value) ⇒ Object
14 15 16 17 |
# File 'lib/roadforest/http/message.rb', line 14 def body_string=(value) @body_string = value @body = nil end |
#empty? ⇒ Boolean
65 66 67 68 69 70 71 |
# File 'lib/roadforest/http/message.rb', line 65 def empty? if @body.nil? @body_string.nil? || @body_string.empty? else @body.respond_to?(:size) && @body.size <= 0 end end |
#inspect ⇒ Object
45 46 47 |
# File 'lib/roadforest/http/message.rb', line 45 def inspect "#<#{self.class.name}:#{'0x%0xd'%object_id}\n #{inspection_payload.join("\n ")}\n>" end |
#inspection_payload ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/roadforest/http/message.rb', line 49 def inspection_payload if body.respond_to? :pos [headers.inspect, inspection_stream] else [headers.inspect, body] end end |
#inspection_stream ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/roadforest/http/message.rb', line 57 def inspection_stream old_pos = body.pos body.rewind body.read ensure body.pos = old_pos end |