Class: HttpReactor::Response
- Inherits:
-
Object
- Object
- HttpReactor::Response
- Defined in:
- lib/http_reactor/response.rb
Overview
A class that represents an HTTP response which wraps the Java HTTP NIO response object and provides methods for accessing the data using ruby idioms.
Instance Method Summary collapse
-
#body ⇒ Object
Get the body text.
- #code ⇒ Object
-
#content_length ⇒ Object
Get the response content length.
-
#content_type ⇒ Object
Get the response content type.
-
#entity ⇒ Object
Delegates to the HTTP NIO response.
- #headers ⇒ Object
-
#initialize(response_impl) ⇒ Response
constructor
A new instance of Response.
-
#status_line ⇒ Object
Delegates to the HTTP NIO response.
Constructor Details
#initialize(response_impl) ⇒ Response
Returns a new instance of Response.
6 7 8 |
# File 'lib/http_reactor/response.rb', line 6 def initialize(response_impl) @response_impl = response_impl end |
Instance Method Details
#body ⇒ Object
Get the body text
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/http_reactor/response.rb', line 49 def body @body ||= begin begin io = Java.java_to_ruby( org.jruby.RubyIO.new(JRuby.runtime, entity.content).java_object ) io.read rescue Exception => e puts "Error in Response#body: #{e.}" end end end |
#code ⇒ Object
20 21 22 |
# File 'lib/http_reactor/response.rb', line 20 def code status_line.status_code end |
#content_length ⇒ Object
Get the response content length
30 31 32 |
# File 'lib/http_reactor/response.rb', line 30 def content_length @content_length ||= @response_impl.entity.content_length end |
#content_type ⇒ Object
Get the response content type
25 26 27 |
# File 'lib/http_reactor/response.rb', line 25 def content_type @content_type ||= @response_impl.entity.content_type.value end |
#entity ⇒ Object
Delegates to the HTTP NIO response
16 17 18 |
# File 'lib/http_reactor/response.rb', line 16 def entity @response_impl.entity end |
#headers ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/http_reactor/response.rb', line 34 def headers @headers ||= begin h = Hash.new @response_impl.all_headers.each do |header| if h[header.name] h[header.name] = [h[header.name], header.value] else h[header.name] = header.value end end h end end |
#status_line ⇒ Object
Delegates to the HTTP NIO response
11 12 13 |
# File 'lib/http_reactor/response.rb', line 11 def status_line @response_impl.status_line end |