class WinRM::HTTP::HttpTransport
A generic HTTP transport that utilized HTTPClient to send messages back and forth. This backend will maintain state for every WinRMWebService instance that is instantiated so it is possible to use GSSAPI with Keep-Alive.
Constants
- DEFAULT_RECEIVE_TIMEOUT
Set this to an unreasonable amount because WinRM has its own timeouts
Attributes
endpoint[R]
Public Class Methods
new(endpoint)
click to toggle source
# File lib/winrm/http/transport.rb, line 29 def initialize(endpoint) @endpoint = endpoint.is_a?(String) ? URI.parse(endpoint) : endpoint @httpcli = HTTPClient.new(agent_name: 'Ruby WinRM Client') @httpcli.receive_timeout = DEFAULT_RECEIVE_TIMEOUT @logger = Logging.logger[self] end
Public Instance Methods
basic_auth_only!()
click to toggle source
We'll need this to force basic authentication if desired
# File lib/winrm/http/transport.rb, line 53 def basic_auth_only! auths = @httpcli.www_auth.instance_variable_get('@authenticator') auths.delete_if { |i| i.scheme !~ /basic/i } end
no_ssl_peer_verification!()
click to toggle source
Disable SSL Peer Verification
# File lib/winrm/http/transport.rb, line 65 def no_ssl_peer_verification! @httpcli.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE end
no_sspi_auth!()
click to toggle source
Disable SSPI Auth
# File lib/winrm/http/transport.rb, line 59 def no_sspi_auth! auths = @httpcli.www_auth.instance_variable_get('@authenticator') auths.delete_if { |i| i.is_a? HTTPClient::SSPINegotiateAuth } end
receive_timeout()
click to toggle source
# File lib/winrm/http/transport.rb, line 75 def receive_timeout @httpcli.receive_timeout end
receive_timeout=(sec)
click to toggle source
send_request(message)
click to toggle source
Sends the SOAP payload to the WinRM service and returns the service's SOAP response. If an error occurrs an appropriate error is raised.
@param [String] The XML SOAP message @returns [REXML::Document] The parsed response body
# File lib/winrm/http/transport.rb, line 41 def send_request(message) log_soap_message(message) hdr = { 'Content-Type' => 'application/soap+xml;charset=UTF-8', 'Content-Length' => message.length } resp = @httpcli.post(@endpoint, message, hdr) log_soap_message(resp.http_body.content) handler = WinRM::ResponseHandler.new(resp.http_body.content, resp.status) handler.parse_to_xml end
Protected Instance Methods
log_soap_message(message)
click to toggle source
# File lib/winrm/http/transport.rb, line 81 def log_soap_message(message) return unless @logger.debug? xml_msg = REXML::Document.new(message) formatter = REXML::Formatters::Pretty.new(2) formatter.compact = true formatter.write(xml_msg, @logger) @logger.debug("\n") rescue StandardError => e @logger.debug("Couldn't log SOAP request/response: #{e.message} - #{message}") end