Class: ODDB::HttpSession::ResponseWrapper

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
src/util/http.rb

Instance Method Summary (collapse)

Constructor Details

- (ResponseWrapper) initialize(resp)

A new instance of ResponseWrapper



33
34
35
36
# File 'src/util/http.rb', line 33

def initialize(resp)
  @response = resp
  super
end

Instance Method Details

- (Object) body



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'src/util/http.rb', line 37

def body
  body = @response.body
  charset = self.charset
  unless(charset.nil? || charset.downcase == 'utf-8')
    cd = Iconv.new('UTF-8', charset)
    begin
      cd.iconv body
    rescue
      body
    end
  else
    body
  end
end

- (Object) charset



51
52
53
54
55
56
57
# File 'src/util/http.rb', line 51

def charset
  if((ct = @response['Content-Type']) \
    && (match = /charset=([^;])+/u.match(ct)))
    arr = match[0].split("=")
    arr[1].strip.downcase
  end
end