mirror of https://github.com/mastodon/goldfinger
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:
parent
114c45f62d
commit
d5f16ebeca
|
@ -18,8 +18,9 @@ module Goldfinger
|
||||||
# @raise [Goldfinger::NotFoundError] Error raised when the Webfinger resource could not be retrieved
|
# @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
|
# @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 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]
|
# @return [Goldfinger::Result]
|
||||||
def self.finger(uri)
|
def self.finger(uri, opts = {})
|
||||||
Goldfinger::Client.new(uri).finger
|
Goldfinger::Client.new(uri, opts).finger
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,12 +7,15 @@ module Goldfinger
|
||||||
class Client
|
class Client
|
||||||
include Goldfinger::Utils
|
include Goldfinger::Utils
|
||||||
|
|
||||||
def initialize(uri)
|
def initialize(uri, opts = {})
|
||||||
@uri = uri
|
@uri = uri
|
||||||
|
@ssl = opts.delete(:ssl) { true }
|
||||||
|
@scheme = @ssl ? 'https' : 'http'
|
||||||
|
@opts = opts
|
||||||
end
|
end
|
||||||
|
|
||||||
def finger
|
def finger
|
||||||
response = perform_get(standard_url)
|
response = perform_get(standard_url, @opts)
|
||||||
|
|
||||||
return finger_from_template if response.code != 200
|
return finger_from_template if response.code != 200
|
||||||
|
|
||||||
|
@ -24,11 +27,11 @@ module Goldfinger
|
||||||
private
|
private
|
||||||
|
|
||||||
def finger_from_template
|
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
|
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
|
raise Goldfinger::NotFoundError, 'No such user on the server' if response.code != 200
|
||||||
|
|
||||||
|
@ -36,11 +39,11 @@ module Goldfinger
|
||||||
end
|
end
|
||||||
|
|
||||||
def url
|
def url
|
||||||
"https://#{domain}/.well-known/host-meta"
|
"#{@scheme}://#{domain}/.well-known/host-meta"
|
||||||
end
|
end
|
||||||
|
|
||||||
def standard_url
|
def standard_url
|
||||||
"https://#{domain}/.well-known/webfinger?resource=#{@uri}"
|
"#{@scheme}://#{domain}/.well-known/webfinger?resource=#{@uri}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def url_from_template(template)
|
def url_from_template(template)
|
||||||
|
|
Loading…
Reference in New Issue