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 instatiated 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.



11
12
13
14
15
# File 'lib/winrm/http/transport.rb', line 11

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
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



9
10
11
# File 'lib/winrm/http/transport.rb', line 9

def endpoint
  @endpoint
end

Instance Method Details

#basic_auth_only!Object

We’ll need this to force basic authentication if desired



34
35
36
37
# File 'lib/winrm/http/transport.rb', line 34

def basic_auth_only!
  auths = @httpcli.www_auth.instance_variable_get('@authenticator')
  auths.delete_if {|i| i.scheme !~ /basic/i}
end

#send_request(message) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/winrm/http/transport.rb', line 17

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