Sha256: c67e868746b922a6313b892f04f289d06481d4ab645e79d6bcfc3aeb35205e1a

Contents?: true

Size: 1.79 KB

Versions: 44

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

44 entries across 44 versions & 3 rubygems

Version Path
fog-1.22.0 lib/fog/xml/sax_parser_connection.rb
fog-1.21.0 lib/fog/xml/sax_parser_connection.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/xml/sax_parser_connection.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/xml/sax_parser_connection.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/xml/sax_parser_connection.rb
fog-1.20.0 lib/fog/xml/sax_parser_connection.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/xml/sax_parser_connection.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/xml/sax_parser_connection.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/xml/sax_parser_connection.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/xml/sax_parser_connection.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/xml/sax_parser_connection.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/xml/sax_parser_connection.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/xml/sax_parser_connection.rb
fog-1.19.0 lib/fog/xml/sax_parser_connection.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/xml/sax_parser_connection.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/xml/sax_parser_connection.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/xml/sax_parser_connection.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/xml/sax_parser_connection.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/xml/sax_parser_connection.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/xml/sax_parser_connection.rb