Enable to pass options to HTTP.rb, Allow insecure request (#6)

* Enable to pass options to HTTP.rb, Allow insecure request

* Move SSL option to the hash

* fix a bug
This commit is contained in:
MIYAGI Hikaru 2018-01-22 08:11:46 +09:00 committed by Eugen Rochko
parent 114c45f62d
commit d5f16ebeca
2 changed files with 12 additions and 8 deletions

View File

@ -18,8 +18,9 @@ module Goldfinger
# @raise [Goldfinger::NotFoundError] Error raised when the Webfinger resource could not be retrieved
# @raise [Goldfinger::SSLError] Error raised when there was a SSL error when fetching the resource
# @param uri [String] A full resource identifier in the format acct:user@example.com
# @param opts [Hash] Options passed to HTTP.rb client
# @return [Goldfinger::Result]
def self.finger(uri)
Goldfinger::Client.new(uri).finger
def self.finger(uri, opts = {})
Goldfinger::Client.new(uri, opts).finger
end
end

View File

@ -7,12 +7,15 @@ module Goldfinger
class Client
include Goldfinger::Utils
def initialize(uri)
def initialize(uri, opts = {})
@uri = uri
@ssl = opts.delete(:ssl) { true }
@scheme = @ssl ? 'https' : 'http'
@opts = opts
end
def finger
response = perform_get(standard_url)
response = perform_get(standard_url, @opts)
return finger_from_template if response.code != 200
@ -24,11 +27,11 @@ module Goldfinger
private
def finger_from_template
template = perform_get(url)
template = perform_get(url, @opts)
raise Goldfinger::NotFoundError, 'No host-meta on the server' if template.code != 200
response = perform_get(url_from_template(template.body))
response = perform_get(url_from_template(template.body), @opts)
raise Goldfinger::NotFoundError, 'No such user on the server' if response.code != 200
@ -36,11 +39,11 @@ module Goldfinger
end
def url
"https://#{domain}/.well-known/host-meta"
"#{@scheme}://#{domain}/.well-known/host-meta"
end
def standard_url
"https://#{domain}/.well-known/webfinger?resource=#{@uri}"
"#{@scheme}://#{domain}/.well-known/webfinger?resource=#{@uri}"
end
def url_from_template(template)