Class: Stella::Data::HTTP::Response
- Inherits:
-
Storable
- Object
- Storable
- Stella::Data::HTTP::Response
- Includes:
- Gibbler::Complex
- Defined in:
- lib/stella/data/http/response.rb
Instance Attribute Summary collapse
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
Instance Method Summary collapse
- #body ⇒ Object
- #cookies ⇒ Object
- #has_body? ⇒ Boolean
- #has_request? ⇒ Boolean
- #has_response? ⇒ Boolean
- #headers ⇒ Object
-
#initialize(raw_data = nil) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
- #is_binary? ⇒ Boolean
- #is_gzip? ⇒ Boolean
- #is_text? ⇒ Boolean
- #parse(raw) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(raw_data = nil) ⇒ Response
Returns a new instance of Response.
19 20 21 22 |
# File 'lib/stella/data/http/response.rb', line 19 def initialize(raw_data=nil) @raw_data = raw_data parse(@raw_data) end |
Instance Attribute Details
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
8 9 10 |
# File 'lib/stella/data/http/response.rb', line 8 def raw_data @raw_data end |
Instance Method Details
#body ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/stella/data/http/response.rb', line 40 def body return nil unless @body #TODO: Move to HTTPResponse::Body.to_s if is_binary? "[skipping binary content]" elsif is_gzip? #require 'zlib' #Zlib::Inflate.inflate(@body) "[skipping gzip content]" else @body end end |
#cookies ⇒ Object
87 88 89 90 |
# File 'lib/stella/data/http/response.rb', line 87 def return [] unless header.is_a?(Array) && !header[:Set_Cookie].empty? header[:Set_Cookie] end |
#has_body? ⇒ Boolean
29 30 31 |
# File 'lib/stella/data/http/response.rb', line 29 def has_body? !@body.nil? && !@body.empty? end |
#has_request? ⇒ Boolean
32 33 34 |
# File 'lib/stella/data/http/response.rb', line 32 def has_request? false end |
#has_response? ⇒ Boolean
35 36 37 |
# File 'lib/stella/data/http/response.rb', line 35 def has_response? false end |
#headers ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/stella/data/http/response.rb', line 54 def headers headers = [] header.each_pair do |n,v| headers << [n.to_s.gsub('_', '-'), v[0]] end headers end |
#inspect ⇒ Object
74 75 76 77 78 79 |
# File 'lib/stella/data/http/response.rb', line 74 def inspect str = "HTTP/%s %s (%s)" % [@http_version, @status, @message] str << $/ + headers.join($/) str << $/ + $/ + body if body str end |
#is_binary? ⇒ Boolean
62 63 64 |
# File 'lib/stella/data/http/response.rb', line 62 def is_binary? (!is_text?) == true end |
#is_gzip? ⇒ Boolean
70 71 72 |
# File 'lib/stella/data/http/response.rb', line 70 def is_gzip? (!header[:Content_Encoding].nil? && (header[:Content_Encoding][0].is_a? String) && header[:Content_Encoding][0][/gzip/] != nil) end |
#is_text? ⇒ Boolean
66 67 68 |
# File 'lib/stella/data/http/response.rb', line 66 def is_text? (!header[:Content_Type].nil? && (header[:Content_Type][0].is_a? String) && header[:Content_Type][0][/text/] != nil) end |
#parse(raw) ⇒ Object
24 25 26 27 |
# File 'lib/stella/data/http/response.rb', line 24 def parse(raw) return unless raw @status, @http_version, @message, @header, @body = HTTPUtil::parse_http_response(raw) end |
#to_s ⇒ Object
81 82 83 84 |
# File 'lib/stella/data/http/response.rb', line 81 def to_s str = "%s: HTTP/%s %s (%s)" % [time.strftime(NICE_TIME_FORMAT), @http_version, @status, @message] str end |