Class: Curl::Response
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#hash ⇒ Object
(also: #headers)
readonly
Returns the value of attribute hash.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#req ⇒ Object
readonly
Returns the value of attribute req.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(easy) ⇒ Response
constructor
A new instance of Response.
- #is(klass) ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(easy) ⇒ Response
Returns a new instance of Response.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rhack/curl/response.rb', line 25 def initialize(easy) @hash = {} @timestamp = @date = @header = nil if easy.base.error @error = easy.base.error else if headers = easy.header_str || easy.base.headers headers /= "\r\n" @header = headers.shift headers.each {|h| h /= ': ' if h[0] h[0].downcase! if h[0] == 'set-cookie' (@hash. ||= []) << h[1] else @hash[h[0]] = h[1] end end } @timestamp = if @hash.date begin @date = @hash.date.to_time rescue => e (@date = Time.now).strftime("%H:%M:%S") L < "Error #{e.class}:#{e.} with @hash.date = #{@hash.date.inspect}" end @hash.date[/\d\d:\d\d:\d\d/] else (@date = Time.now).strftime("%H:%M:%S") end end @code = easy.response_code @body = easy.body_str.dup @time = easy.total_time end @req = {} @req.url = easy.last_effective_url @req.headers = easy.headers if range = easy.headers.Range and range[/(\d+)-(\d+)/] @req.range = $1.to_i .. $2.to_i end if easy.base and @req.meth = easy.base.last_method and @req.meth.in [:post, :put] if @req.meth == :post @req.body = easy.post_body.dup @req.mp = easy.multipart_form_post? else @req.body = easy.base.body.dup end end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/rhack/curl/response.rb', line 6 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/rhack/curl/response.rb', line 6 def code @code end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
6 7 8 |
# File 'lib/rhack/curl/response.rb', line 6 def date @date end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/rhack/curl/response.rb', line 6 def error @error end |
#hash ⇒ Object (readonly) Also known as: headers
Returns the value of attribute hash.
6 7 8 |
# File 'lib/rhack/curl/response.rb', line 6 def hash @hash end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
6 7 8 |
# File 'lib/rhack/curl/response.rb', line 6 def header @header end |
#req ⇒ Object (readonly)
Returns the value of attribute req.
6 7 8 |
# File 'lib/rhack/curl/response.rb', line 6 def req @req end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
6 7 8 |
# File 'lib/rhack/curl/response.rb', line 6 def time @time end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
6 7 8 |
# File 'lib/rhack/curl/response.rb', line 6 def @timestamp end |
Instance Method Details
#[](key) ⇒ Object
87 88 89 90 |
# File 'lib/rhack/curl/response.rb', line 87 def [](key) #@error ? @error[key_or_index] : @hash[key_or_index.downcase] # old @hash[key.downcase] end |
#is(klass) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/rhack/curl/response.rb', line 78 def is(klass) if @error $log.warn "obsolete comparison with Array", caller: 1 if klass == Array klass == Array || klass = Curl::Response # obsolete else klass == Curl::Response end end |
#to_s ⇒ Object Also known as: inspect
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rhack/curl/response.rb', line 8 def to_s str = '<#' if @error str << "#{@error.class.name}: #{@error.}" else str << (@header[/\d{3}/] == @code.to_s ? @header : "#{@header[/\S+/]} #{@code}") if @header if @hash.location str << ' '+@req.url if $panic str << ' -> '+@hash.location end str << " (#{@body ? @body.size.bytes : 'No'} Body)" str << " [#{@timestamp}]" if @timestamp end str << '>' end |