Class: Patron::Response
- Inherits:
-
Object
- Object
- Patron::Response
- Defined in:
- lib/patron/response.rb
Overview
Represents the response from the HTTP server.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#charset ⇒ Object
readonly
Returns the value of attribute charset.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#redirect_count ⇒ Object
readonly
Returns the value of attribute redirect_count.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#status_line ⇒ Object
readonly
Returns the value of attribute status_line.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url, status, redirect_count, header_data, body, default_charset = nil) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
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
#body ⇒ Object (readonly)
Returns the value of attribute body.
51 52 53 |
# File 'lib/patron/response.rb', line 51 def body @body end |
#charset ⇒ Object (readonly)
Returns the value of attribute charset.
51 52 53 |
# File 'lib/patron/response.rb', line 51 def charset @charset end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
51 52 53 |
# File 'lib/patron/response.rb', line 51 def headers @headers end |
#redirect_count ⇒ Object (readonly)
Returns the value of attribute redirect_count.
51 52 53 |
# File 'lib/patron/response.rb', line 51 def redirect_count @redirect_count end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
51 52 53 |
# File 'lib/patron/response.rb', line 51 def status @status end |
#status_line ⇒ Object (readonly)
Returns the value of attribute status_line.
51 52 53 |
# File 'lib/patron/response.rb', line 51 def status_line @status_line end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
51 52 53 |
# File 'lib/patron/response.rb', line 51 def url @url end |
Instance Method Details
#inspect ⇒ Object
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 |