Skip to content

Commit

Permalink
[handler] fix regression in api_request for Ruby >= 2.0
Browse files Browse the repository at this point in the history
Comparing the arguments for `Net::HTTPGenericRequest` on
[1.9.1](https://ruby-doc.org/stdlib-1.9.1/libdoc/net/http/rdoc/Net/HTTPGenericRequest.html)
vs
[2.3.0](https://ruby-doc.org/stdlib-2.3.0/libdoc/net/http/rdoc/Net/HTTPGenericRequest.html),
I see that 1.9.1 expects argument `path` where as 2.3.0 takes `uri_or_path`
argument. If the `uri_or_path` is not a `URI` object, it is treated as the path.

I believe we can unconditionally pass the value of  `uri.path` to
`net_http_req_class(method).new` on both ruby 1.9 and 2.x, as the hostname, port
and scheme are explicitly set when calling `Net::HTTP.start`.

Closes sensu-plugins/sensu-plugins-sensu#18
Closes #160
Closes #161
  • Loading branch information
cwjohnston committed Dec 5, 2016
1 parent 8cc4610 commit ead9fd0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- Fixed a regression in Sensu::Handler `api_request` method, introduced in
v1.4.3, which broke silence stashes and check dependencies on Ruby 2.x.

## [v1.4.3] - 2016-10-04

- Fixed an incompatibility with Ruby 1.9 introduced in Sensu::Handler api_request circa sensu-plugin 1.3.0
Expand Down
2 changes: 1 addition & 1 deletion lib/sensu-handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def api_request(method, path, &blk)
end
domain = api_settings['host'].start_with?('http') ? api_settings['host'] : 'http://' + api_settings['host']
uri = URI("#{domain}:#{api_settings['port']}#{path}")
req = net_http_req_class(method).new(uri.to_s)
req = net_http_req_class(method).new(uri.path)
if api_settings['user'] && api_settings['password']
req.basic_auth(api_settings['user'], api_settings['password'])
end
Expand Down

0 comments on commit ead9fd0

Please sign in to comment.