config: rework http proxy options.
Replace the http_proxy_host, http_proxy_port, http_proxy_username, http_proxy_password options with a single `Danbooru.config.http_proxy` option.
This commit is contained in:
@@ -131,11 +131,12 @@ module Danbooru
|
||||
use(cache: { expires_in: expires_in })
|
||||
end
|
||||
|
||||
def proxy(host: Danbooru.config.http_proxy_host, port: Danbooru.config.http_proxy_port.to_i, username: Danbooru.config.http_proxy_username, password: Danbooru.config.http_proxy_password)
|
||||
return self if host.blank?
|
||||
def proxy(url: Danbooru.config.http_proxy)
|
||||
return self if url.blank?
|
||||
parsed_url = Danbooru::URL.parse!(url)
|
||||
|
||||
dup.tap do |o|
|
||||
o.http = o.http.via(host, port, username, password)
|
||||
o.http = o.http.via(parsed_url.host, parsed_url.port, parsed_url.http_user, parsed_url.password)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ module Danbooru
|
||||
# @return [Addressable:URI] The parsed and normalized URL.
|
||||
attr_reader :url
|
||||
|
||||
delegate :domain, :host, :site, :path, :query, to: :url
|
||||
delegate :domain, :host, :port, :site, :path, :query, :password, to: :url
|
||||
|
||||
# Parse a string into a URL, or raise an exception if the string is not a valid HTTP or HTTPS URL.
|
||||
#
|
||||
@@ -111,6 +111,11 @@ module Danbooru
|
||||
parsed_domain.trd
|
||||
end
|
||||
|
||||
# @return [String, nil] The username in a `http://username:password@example.com` URL.
|
||||
def http_user
|
||||
url.user
|
||||
end
|
||||
|
||||
# @return [PublicSuffix::Domain]
|
||||
def parsed_domain
|
||||
@parsed_domain ||= PublicSuffix.parse(host)
|
||||
|
||||
@@ -578,16 +578,9 @@ module Danbooru
|
||||
"https://twitter.com/#{Danbooru.config.twitter_username}"
|
||||
end
|
||||
|
||||
def http_proxy_host
|
||||
end
|
||||
|
||||
def http_proxy_port
|
||||
end
|
||||
|
||||
def http_proxy_username
|
||||
end
|
||||
|
||||
def http_proxy_password
|
||||
# The proxy to use for outgoing HTTP requests.
|
||||
def http_proxy
|
||||
# "http://username:password@proxy.example.com:1080"
|
||||
end
|
||||
|
||||
# The URL for the Reportbooru server (https://github.com/evazion/reportbooru).
|
||||
|
||||
Reference in New Issue
Block a user