From f763692f612b3dcc3a001f05898ec7d0049175ce Mon Sep 17 00:00:00 2001 From: laxa Date: Tue, 26 Apr 2022 20:19:32 +0200 Subject: [PATCH 1/2] Added user-agent option --- README.md | 1 + lib/winrm/connection_opts.rb | 2 ++ lib/winrm/http/transport.rb | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 251f75b6..708c9672 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ There are various connection options you can specify upon initializing a WinRM c * `:operation_timeout` - The maximum amount of time to wait for a response from the endpoint. This defaults to 60 seconds. Note that this will not "timeout" commands that exceed this amount of time to process, it just requires the endpoint to report the status of the command before the given amount of time passes. * `:receive_timeout` - The amount of time given to the underlying HTTP connection to respond before timing out. The defaults to 10 seconds longer than the `:operation_timeout`. * `:retry_limit` - the maximum number of times to retry opening a shell after failure. This defaults to 3. +* `:user_agent` - the user-agent used in the http connection, default to 'Ruby WinRM Client' * `:retry_delay` - the amount of time to wait between retries and defaults to 10 seconds * `:user` - username used to authenticate over the `:transport` * `:password` - password used to authenticate over the `:transport` diff --git a/lib/winrm/connection_opts.rb b/lib/winrm/connection_opts.rb index 313bf19c..db584103 100644 --- a/lib/winrm/connection_opts.rb +++ b/lib/winrm/connection_opts.rb @@ -23,6 +23,7 @@ class ConnectionOpts < Hash DEFAULT_LOCALE = 'en-US'.freeze DEFAULT_RETRY_DELAY = 10 DEFAULT_RETRY_LIMIT = 3 + DEFAULT_USER_AGENT = 'Ruby WinRM Client'.freeze class << self def create_with_defaults(overrides) @@ -51,6 +52,7 @@ def default config[:receive_timeout] = DEFAULT_RECEIVE_TIMEOUT config[:retry_delay] = DEFAULT_RETRY_DELAY config[:retry_limit] = DEFAULT_RETRY_LIMIT + config[:user_agent] = DEFAULT_USER_AGENT config end end diff --git a/lib/winrm/http/transport.rb b/lib/winrm/http/transport.rb index 2daa5be6..33fbf185 100644 --- a/lib/winrm/http/transport.rb +++ b/lib/winrm/http/transport.rb @@ -25,9 +25,10 @@ class HttpTransport def initialize(endpoint, options) @endpoint = endpoint.is_a?(String) ? URI.parse(endpoint) : endpoint - @httpcli = HTTPClient.new(agent_name: 'Ruby WinRM Client') + @httpcli = HTTPClient.new() @logger = Logging.logger[self] @httpcli.receive_timeout = options[:receive_timeout] + @httpcli.default_header = {'User-Agent': options[:user_agent]} end # Sends the SOAP payload to the WinRM service and returns the service's From 3792be37d03bf81d608a5e7ae71a7941562ec6dd Mon Sep 17 00:00:00 2001 From: laxa Date: Tue, 26 Apr 2022 20:40:21 +0200 Subject: [PATCH 2/2] Learning ruby coding style is fun --- lib/winrm/http/transport.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/winrm/http/transport.rb b/lib/winrm/http/transport.rb index 33fbf185..75f50f95 100644 --- a/lib/winrm/http/transport.rb +++ b/lib/winrm/http/transport.rb @@ -25,10 +25,10 @@ class HttpTransport def initialize(endpoint, options) @endpoint = endpoint.is_a?(String) ? URI.parse(endpoint) : endpoint - @httpcli = HTTPClient.new() + @httpcli = HTTPClient.new @logger = Logging.logger[self] @httpcli.receive_timeout = options[:receive_timeout] - @httpcli.default_header = {'User-Agent': options[:user_agent]} + @httpcli.default_header = { 'User-Agent': options[:user_agent] } end # Sends the SOAP payload to the WinRM service and returns the service's