Sha256: 232d8376a911a4bf3671a5eb000fbb37a7458565a8e8454e802ee75f7b9fbf19

Contents?: true

Size: 887 Bytes

Versions: 1

Compression:

Stored size: 887 Bytes

Contents

module WebSpeak
  class ResponseAccessor
    def initialize(response)
      @response = response
    end

    def http_response
      @response
    end
    
    def headers
      res = ""
      @response.each_header do |name, values|
        values.each {|val| res << "#{name} => #{val}\n"} unless name == 'set-cookie'
      end
      res
    end
    
    def cookies
      res = ""
      @response.get_fields('set-cookie').each do |full_cookie|
        elems = full_cookie.split(";")
        cookie = elems.shift # the rest of the elements are expiry, domain, path, ...
        name, value = cookie.split("=", 2)
        res << "#{name.strip} => #{value.strip}\n"
        elems.each do |attr|
          name, value = attr.split("=", 2)
          res << "  #{name.strip}: #{value.strip}\n"
        end
      end
      res
    end
    
    def body
      @response.body
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
webspeak-0.0.1 lib/webspeak/response_accessor.rb