Class: Steam::Browser::HtmlUnit::Connection
- Inherits:
-
Object
- Object
- Steam::Browser::HtmlUnit::Connection
- Includes:
- Java::Com::Gargoylesoftware::Htmlunit
- Defined in:
- lib/steam/browser/html_unit/connection.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#java ⇒ Object
readonly
Returns the value of attribute java.
Instance Method Summary collapse
- #getResponse(request_settings) ⇒ Object
-
#initialize(connection) ⇒ Connection
constructor
A new instance of Connection.
- #set_response(url, response) ⇒ Object
Constructor Details
#initialize(connection) ⇒ Connection
Returns a new instance of Connection.
36 37 38 39 |
# File 'lib/steam/browser/html_unit/connection.rb', line 36 def initialize(connection) @connection = connection @java = MockWebConnection.new end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
34 35 36 |
# File 'lib/steam/browser/html_unit/connection.rb', line 34 def connection @connection end |
#java ⇒ Object (readonly)
Returns the value of attribute java.
34 35 36 |
# File 'lib/steam/browser/html_unit/connection.rb', line 34 def java @java end |
Instance Method Details
#getResponse(request_settings) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/steam/browser/html_unit/connection.rb', line 41 def getResponse(request_settings) # FIXME preserve original scheme, host + port method = request_settings.getHttpMethod.toString.dup url = request_settings.getUrl.toString.dup body = request_settings.getRequestBody body = body.toString.dup if body params = request_settings.getRequestParameters params = Hash[*params.toArray.map { |e| [e.name, e.value] }.flatten] input = body ? body : Rack::Utils.build_nested_query(params) env = Request.new(:method => method, :url => url, :input => input).env status, headers, response = connection.call(env) response.body.close if response.body.respond_to?(:close) set_response(request_settings.getUrl, response) java.getResponse(request_settings) rescue Exception => e puts "#{e.class.name}: #{e.}" e.backtrace.each { |line| puts line } end |
#set_response(url, response) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/steam/browser/html_unit/connection.rb', line 65 def set_response(url, response) body = response.body.join status = response.status = Rack::Utils::HTTP_STATUS_CODES[status.to_i] charset = Steam.config[:charset] headers = response.header.map { |key, value| NameValuePair.new(key, value) } headers = Java::Util::Arrays.asList(headers) content_type = response.content_type java.setResponse(url, body, status, , content_type, charset, headers) end |