class RoadForest::HTTP::Message

Attributes

headers[RW]

Public Class Methods

new() click to toggle source
# File lib/roadforest/http/message.rb, line 9
def initialize
  @body_string = ""
  @headers = {}
end

Public Instance Methods

body() click to toggle source
# File lib/roadforest/http/message.rb, line 24
def body
  return @body ||= StringIO.new(body_string||"")
end
body=(value) click to toggle source
# File lib/roadforest/http/message.rb, line 19
def body=(value)
  @body = value
  @body_string = nil
end
body_string() click to toggle source
# 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) click to toggle source
# File lib/roadforest/http/message.rb, line 14
def body_string=(value)
  @body_string = value
  @body = nil
end
empty?() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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