<commit_before>module WinRM
  module HTTP

    # A generic HTTP transport that utilized HTTPClient to send messages back and forth.
    # This backend will maintain state for every WinRMWebService instance that is instatiated so it
    # is possible to use GSSAPI with Keep-Alive.
    class HttpTransport

      attr_reader :endpoint

      def initialize(endpoint)
        @endpoint = endpoint.is_a?(String) ? URI.parse(endpoint) : endpoint
        @httpcli = HTTPClient.new(:agent_name => 'Ruby WinRM Client')
        @httpcli.receive_timeout = 3600 # Set this to an unreasonable amount for now because WinRM has timeouts
        @logger = Logging.logger[self]
      end

      def send_request(message)
        hdr = {'Content-Type' => 'application/soap+xml;charset=UTF-8', 'Content-Length' => message.length}
        resp = @httpcli.post(@endpoint, message, hdr)
        if(resp.status == 200)
          # Version 1.1 of WinRM adds the namespaces in the document instead of the envelope so we have to
          # add them ourselves here. This should have no affect version 2.
          doc = Nokogiri::XML(resp.http_body.content)
          doc.collect_namespaces.each_pair do |k,v|
            doc.root.add_namespace((k.split(/:/).last),v) unless doc.namespaces.has_key?(k)
          end
          return doc
        else
          raise WinRMHTTPTransportError, "Bad HTTP response returned from server (#{resp.status})."
        end
      end

      # We'll need this to force basic authentication if desired
      def basic_auth_only!
        auths = @httpcli.www_auth.instance_variable_get('@authenticator')
        auths.delete_if {|i| i.scheme !~ /basic/i}
      end
    end

    class HttpPlaintext < HttpTransport
      def initialize(endpoint, user, pass, opts)
        super(endpoint)
        @httpcli.set_auth(nil, user, pass)
        HTTPClient.const_set(:GSSAPIEnabled , false) if opts[:disable_gssapi]
        basic_auth_only! if opts[:basic_auth_only]
      end
    end

    # Uses SSL to secure the transport
    class HttpSSL < HttpTransport
      def initialize(endpoint, user, pass, ca_trust_path = nil, opts)
        super(endpoint)
        @httpcli.set_auth(endpoint, user, pass)
        @httpcli.ssl_config.set_trust_ca(ca_trust_path) unless ca_trust_path.nil?
        HTTPClient.const_set(:GSSAPIEnabled , false) if opts[:disable_gssapi]
        basic_auth_only! if opts[:basic_auth_only]
      end
    end

    # Uses Kerberos/GSSAPI to authenticate and encrypt messages
    class HttpGSSAPI < HttpTransport
      # @param [String,URI] endpoint the WinRM webservice endpoint
      # @param [String] realm the Kerberos realm we are authenticating to
      # @param [String<optional>] service the service name, default is HTTP
      # @param [String<optional>] keytab the path to a keytab file if you are using one
      def initialize(endpoint, realm, service = nil, keytab = nil, opts)
        super(endpoint)
        # Remove the GSSAPI auth from HTTPClient because we are doing our own thing
        auths = @httpcli.www_auth.instance_variable_get('@authenticator')
        auths.delete_if {|i| i.is_a?(HTTPClient::SSPINegotiateAuth)}
        service ||= 'HTTP'
        @service = "#{service}/#{@endpoint.host}@#{realm}"
        init_krb
      end<commit_msg>Just provide an option to turn off GSSAPI<commit_after>module WinRM
  module HTTP

    # A generic HTTP transport that utilized HTTPClient to send messages back and forth.
    # This backend will maintain state for every WinRMWebService instance that is instatiated so it
    # is possible to use GSSAPI with Keep-Alive.
    class HttpTransport

      attr_reader :endpoint

      def initialize(endpoint)
        @endpoint = endpoint.is_a?(String) ? URI.parse(endpoint) : endpoint
        @httpcli = HTTPClient.new(:agent_name => 'Ruby WinRM Client')
        @httpcli.receive_timeout = 3600 # Set this to an unreasonable amount for now because WinRM has timeouts
        @logger = Logging.logger[self]
      end

      def send_request(message)
        hdr = {'Content-Type' => 'application/soap+xml;charset=UTF-8', 'Content-Length' => message.length}
        resp = @httpcli.post(@endpoint, message, hdr)
        if(resp.status == 200)
          # Version 1.1 of WinRM adds the namespaces in the document instead of the envelope so we have to
          # add them ourselves here. This should have no affect version 2.
          doc = Nokogiri::XML(resp.http_body.content)
          doc.collect_namespaces.each_pair do |k,v|
            doc.root.add_namespace((k.split(/:/).last),v) unless doc.namespaces.has_key?(k)
          end
          return doc
        else
          raise WinRMHTTPTransportError, "Bad HTTP response returned from server (#{resp.status})."
        end
      end

      # We'll need this to force basic authentication if desired
      def basic_auth_only!
        auths = @httpcli.www_auth.instance_variable_get('@authenticator')
        auths.delete_if {|i| i.scheme !~ /basic/i}
      end

      # Disable SSPI Auth
      def no_sspi_auth!
        auths = @httpcli.www_auth.instance_variable_get('@authenticator')
        auths.delete_if {|i| i.is_a? HTTPClient::SSPINegotiateAuth }
      end
    end

    class HttpPlaintext < HttpTransport
      def initialize(endpoint, user, pass, opts)
        super(endpoint)
        @httpcli.set_auth(nil, user, pass)
        no_sspi_auth! if opts[:disable_sspi]
        basic_auth_only! if opts[:basic_auth_only]
      end
    end

    # Uses SSL to secure the transport
    class HttpSSL < HttpTransport
      def initialize(endpoint, user, pass, ca_trust_path = nil, opts)
        super(endpoint)
        @httpcli.set_auth(endpoint, user, pass)
        @httpcli.ssl_config.set_trust_ca(ca_trust_path) unless ca_trust_path.nil?
        no_sspi_auth! if opts[:disable_sspi]
        basic_auth_only! if opts[:basic_auth_only]
      end
    end

    # Uses Kerberos/GSSAPI to authenticate and encrypt messages
    class HttpGSSAPI < HttpTransport
      # @param [String,URI] endpoint the WinRM webservice endpoint
      # @param [String] realm the Kerberos realm we are authenticating to
      # @param [String<optional>] service the service name, default is HTTP
      # @param [String<optional>] keytab the path to a keytab file if you are using one
      def initialize(endpoint, realm, service = nil, keytab = nil, opts)
        super(endpoint)
        # Remove the GSSAPI auth from HTTPClient because we are doing our own thing
        auths = @httpcli.www_auth.instance_variable_get('@authenticator')
        auths.delete_if {|i| i.is_a?(HTTPClient::SSPINegotiateAuth)}
        service ||= 'HTTP'
        @service = "#{service}/#{@endpoint.host}@#{realm}"
        init_krb
      end
{'fraction_non_alphanumeric': 0.08691782853752596, 'fraction_numerical': 0.003263126668644319, 'mean_word_length': 2.861970217640321, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 5, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2104857', 'n_tokens_mistral': 2014, 'n_tokens_neox': 1957, 'n_words': 596}