Sha256: 3baea52883ebe83d4110527ea5524d69b8b471331cd8ec804b0966b9ee062daa

Contents?: true

Size: 1.79 KB

Versions: 6

Compression:

Stored size: 1.79 KB

Contents

module Fog
  module XML
    class SAXParserConnection < ::Fog::Core::Connection
      # Makes a request using the connection using Excon
      #
      # @param [Hash] params
      # @option params [String] :body text to be sent over a socket
      # @option params [Hash<Symbol, String>] :headers The default headers to supply in a request
      # @option params [String] :host The destination host"s reachable DNS name or IP, in the form of a String
      # @option params [String] :path appears after "scheme://host:port/"
      # @option params [Fixnum] :port The port on which to connect, to the destination host
      # @option params [Hash]   :query appended to the "scheme://host:port/path/" in the form of "?key=value"
      # @option params [String] :scheme The protocol; "https" causes OpenSSL to be used
      # @option params [Proc] :response_block
      # @option params [Nokogiri::XML::SAX::Document] :parser
      #
      # @return [Excon::Response]
      #
      # @raise [Excon::Errors::StubNotFound]
      # @raise [Excon::Errors::Timeout]
      # @raise [Excon::Errors::SocketError]
      #
      def request(parser, params)
        reset unless @persistent

        # Prepare the SAX parser
        data_stream = Nokogiri::XML::SAX::PushParser.new(parser)
        response_string = ""
        params[:response_block] = lambda do |chunk, _remaining, _total|
          response_string << chunk if ENV["DEBUG_RESPONSE"]
          data_stream << chunk
        end

        # Make request which read chunks into parser
        response = @excon.request(params)
        Fog::Logger.debug "\n#{response_string}" if ENV["DEBUG_RESPONSE"]

        # Cease parsing and override response.body with parsed data
        data_stream.finish
        response.body = parser.response
        response
      end
    end
  end
end

Version data entries

6 entries across 4 versions & 3 rubygems

Version Path
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-xml-0.1.3/lib/fog/xml/sax_parser_connection.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-xml-0.1.3/lib/fog/xml/sax_parser_connection.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-xml-0.1.3/lib/fog/xml/sax_parser_connection.rb
fog-xml-0.1.3 lib/fog/xml/sax_parser_connection.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-xml-0.1.2/lib/fog/xml/sax_parser_connection.rb
fog-xml-0.1.2 lib/fog/xml/sax_parser_connection.rb