diff --git a/lib/nexpose/connection.rb b/lib/nexpose/connection.rb index 5b985638..c06b0ba1 100644 --- a/lib/nexpose/connection.rb +++ b/lib/nexpose/connection.rb @@ -94,8 +94,7 @@ def execute(xml, version = '1.1', options = {}) end # Download a specific URL, typically a report. - # Include an optional file_name parameter to stream the output to a file. - # Pass a block to get the response as it is returned from the server + # Include an optional file_name parameter to write the output to a file. # # Note: XML and HTML reports have charts not downloaded by this method. # Would need to do something more sophisticated to grab @@ -103,29 +102,16 @@ def execute(xml, version = '1.1', options = {}) def download(url, file_name = nil) return nil if url.nil? or url.empty? uri = URI.parse(url) - + http = Net::HTTP.new(@host, @port) + http.use_ssl = true + http.verify_mode = OpenSSL::SSL::VERIFY_NONE # XXX: security issue headers = {'Cookie' => "nexposeCCSessionID=#{@session_id}"} + resp = http.get(uri.to_s, headers) - Net::HTTP.start(@host, @port, - use_ssl: true, - verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http| - request = Net::HTTP::Get.new(uri.to_s, headers) - - http.request(request) do |response| - if file_name - ::File.open(file_name, 'wb') do |f| - response.read_body do |chunk| - f.write chunk - end - end - elsif block_given? - response.read_body do |chunk| - yield chunk - end - else - return response.body - end - end + if file_name + ::File.open(file_name, 'wb') { |file| file.write(resp.body) } + else + resp.body end end end