Class: WinRM::HTTP::HttpTransport

Inherits:
Object
  • Object
show all
Defined in:
lib/winrm/http/transport.rb

Overview

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.

Direct Known Subclasses

HttpGSSAPI, HttpPlaintext, HttpSSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint) ⇒ HttpTransport

Returns a new instance of HttpTransport.



29
30
31
32
33
34
# 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 = 3600 # Set this to an unreasonable amount for now because WinRM has timeouts
  @logger = Logging.logger[self]
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



27
28
29
# File 'lib/winrm/http/transport.rb', line 27

def endpoint
  @endpoint
end

Instance Method Details

#basic_auth_only!Object

We’ll need this to force basic authentication if desired



53
54
55
56
# 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!Object

Disable SSL Peer Verification



65
66
67
# 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!Object

Disable SSPI Auth



59
60
61
62
# 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

#send_request(message) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/winrm/http/transport.rb', line 36

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