Class: Steam::Browser::HtmlUnit::WebResponse

Inherits:
Object
  • Object
show all
Includes:
Java::Com::Gargoylesoftware::Htmlunit
Defined in:
lib/steam/browser/html_unit/web_response.rb

Constant Summary collapse

NameValuePair =

HtmlUnit 2.7

Java.import(classifier, :NameValuePair)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, response) ⇒ WebResponse

Returns a new instance of WebResponse.



21
22
23
24
25
26
27
# File 'lib/steam/browser/html_unit/web_response.rb', line 21

def initialize(request, response)
  @request = request
  @response = response
rescue Exception => e
  puts e.message
  e.backtrace.each { |line| puts line }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



109
110
111
# File 'lib/steam/browser/html_unit/web_response.rb', line 109

def method_missing(method, *args)
  puts "Method missing in WebResponse: #{method} #{args.map{ |a| a.inspect }.join(', ')}"
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



19
20
21
# File 'lib/steam/browser/html_unit/web_response.rb', line 19

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



19
20
21
# File 'lib/steam/browser/html_unit/web_response.rb', line 19

def response
  @response
end

Instance Method Details

#getContentAsStreamObject



99
100
101
102
103
104
105
106
107
# File 'lib/steam/browser/html_unit/web_response.rb', line 99

def getContentAsStream
  @content_as_stream ||= begin
    bytes = getContentAsString.unpack('C*')
    Java::Io::ByteArrayInputStream.new_with_sig('[B', bytes)
  end
rescue Exception => e
  puts e.message
  e.backtrace.each { |line| puts line }
end

#getContentAsStringObject



92
93
94
95
96
97
# File 'lib/steam/browser/html_unit/web_response.rb', line 92

def getContentAsString
  @content_as_string ||= response.body.join
rescue Exception => e
  puts e.message
  e.backtrace.each { |line| puts line }
end

#getContentCharsetObject



78
79
80
81
82
83
# File 'lib/steam/browser/html_unit/web_response.rb', line 78

def getContentCharset
  @content_charset ||= Steam.config[:charset]
rescue Exception => e
  puts e.message
  e.backtrace.each { |line| puts line }
end

#getContentCharsetOrNullObject



85
86
87
88
89
90
# File 'lib/steam/browser/html_unit/web_response.rb', line 85

def getContentCharsetOrNull
  @content_charset_or_null ||= Steam.config[:charset]
rescue Exception => e
  puts e.message
  e.backtrace.each { |line| puts line }
end

#getContentTypeObject



67
68
69
70
71
72
73
74
75
76
# File 'lib/steam/browser/html_unit/web_response.rb', line 67

def getContentType
  @content_type ||= begin
    content_type = response.content_type.split(';').first
    content_type = 'application/x-javascript' if content_type == 'application/javascript'
    content_type
  end
rescue Exception => e
  puts e.message
  e.backtrace.each { |line| puts line }
end

#getRequestSettingsObject



29
30
31
32
33
34
# File 'lib/steam/browser/html_unit/web_response.rb', line 29

def getRequestSettings
  @request_settings ||= WebRequestSettings.new(Java::Net::URL.new(request.url))
rescue Exception => e
  puts e.message
  e.backtrace.each { |line| puts line }
end

#getResponseHeadersObject



36
37
38
39
40
41
42
43
44
# File 'lib/steam/browser/html_unit/web_response.rb', line 36

def getResponseHeaders
  @headers ||= begin
    headers = response.header.map { |key, value| NameValuePair.new(key, value) }
    Java::Util::Arrays.asList(headers)
  end
rescue Exception => e
  puts e.message
  e.backtrace.each { |line| puts line }
end

#getResponseHeaderValue(name) ⇒ Object



46
47
48
49
50
51
# File 'lib/steam/browser/html_unit/web_response.rb', line 46

def getResponseHeaderValue(name)
  response.header[name]
rescue Exception => e
  puts e.message
  e.backtrace.each { |line| puts line }
end

#getStatusCodeObject



53
54
55
56
57
58
# File 'lib/steam/browser/html_unit/web_response.rb', line 53

def getStatusCode
  @status ||= response.status
rescue Exception => e
  puts e.message
  e.backtrace.each { |line| puts line }
end

#getStatusMessageObject



60
61
62
63
64
65
# File 'lib/steam/browser/html_unit/web_response.rb', line 60

def getStatusMessage
  @message ||= Rack::Utils::HTTP_STATUS_CODES[getStatusCode.to_i]
rescue Exception => e
  puts e.message
  e.backtrace.each { |line| puts line }
end