Skip to content

Commit

Permalink
Merge pull request #337 from laxa/add_user_agent_option
Browse files Browse the repository at this point in the history
Adding user-agent option
  • Loading branch information
mwrock authored Apr 26, 2022
2 parents ef3e56e + 3792be3 commit 033b439
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 2 additions & 0 deletions lib/winrm/connection_opts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/winrm/http/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 033b439

Please sign in to comment.