Class: Patron::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/patron/response.rb

Overview

Represents the response from the HTTP server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, status, redirect_count, header_data, body, default_charset = nil) ⇒ Response

Returns a new instance of Response.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/patron/response.rb', line 31

def initialize(url, status, redirect_count, header_data, body, default_charset = nil)
  # Don't let a response clear out the default charset, which would cause encoding to fail
  default_charset = "ASCII-8BIT" unless default_charset
  @url            = url
  @status         = status
  @redirect_count = redirect_count
  @body           = body
  
  @charset        = determine_charset(header_data, body) || default_charset
  
  [url, header_data].each do |attr|
    convert_to_default_encoding!(attr)
  end
  
  parse_headers(header_data)
  if @headers["Content-Type"] && @headers["Content-Type"][0, 5] == "text/"
    convert_to_default_encoding!(@body)
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



51
52
53
# File 'lib/patron/response.rb', line 51

def body
  @body
end

#charsetObject (readonly)

Returns the value of attribute charset.



51
52
53
# File 'lib/patron/response.rb', line 51

def charset
  @charset
end

#headersObject (readonly)

Returns the value of attribute headers.



51
52
53
# File 'lib/patron/response.rb', line 51

def headers
  @headers
end

#redirect_countObject (readonly)

Returns the value of attribute redirect_count.



51
52
53
# File 'lib/patron/response.rb', line 51

def redirect_count
  @redirect_count
end

#statusObject (readonly)

Returns the value of attribute status.



51
52
53
# File 'lib/patron/response.rb', line 51

def status
  @status
end

#status_lineObject (readonly)

Returns the value of attribute status_line.



51
52
53
# File 'lib/patron/response.rb', line 51

def status_line
  @status_line
end

#urlObject (readonly)

Returns the value of attribute url.



51
52
53
# File 'lib/patron/response.rb', line 51

def url
  @url
end

Instance Method Details

#inspectObject



53
54
55
56
# File 'lib/patron/response.rb', line 53

def inspect
  # Avoid spamming the console with the header and body data
  "#<Patron::Response @status_line='#{@status_line}'>"
end