Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding user-agent option #337

Merged
merged 2 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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