User agent for WebFinger (#7531)

* User agent for WebFinger

* local_domain → web_domain

* 'http' is away accidentally...
This commit is contained in:
MIYAGI Hikaru 2018-05-18 08:47:22 +09:00 committed by Eugen Rochko
parent 7293b9fc61
commit 919eef3098
3 changed files with 7 additions and 6 deletions

View file

@ -58,7 +58,7 @@ class Request
def set_common_headers! def set_common_headers!
@headers[REQUEST_TARGET] = "#{@verb} #{@url.path}" @headers[REQUEST_TARGET] = "#{@verb} #{@url.path}"
@headers['User-Agent'] = user_agent @headers['User-Agent'] = Mastodon::Version.user_agent
@headers['Host'] = @url.host @headers['Host'] = @url.host
@headers['Date'] = Time.now.utc.httpdate @headers['Date'] = Time.now.utc.httpdate
@headers['Accept-Encoding'] = 'gzip' if @verb != :head @headers['Accept-Encoding'] = 'gzip' if @verb != :head
@ -83,10 +83,6 @@ class Request
@headers.keys.join(' ').downcase @headers.keys.join(' ').downcase
end end
def user_agent
@user_agent ||= "#{HTTP::Request::USER_AGENT} (Mastodon/#{Mastodon::Version}; +#{root_url})"
end
def key_id def key_id
case @key_id_format case @key_id_format
when :acct when :acct

View file

@ -18,7 +18,8 @@ module Goldfinger
def self.finger(uri, opts = {}) def self.finger(uri, opts = {})
to_hidden = /\.(onion|i2p)(:\d+)?$/.match(uri) to_hidden = /\.(onion|i2p)(:\d+)?$/.match(uri)
raise Mastodon::HostValidationError, 'Instance does not support hidden service connections' if !Rails.configuration.x.access_to_hidden_service && to_hidden raise Mastodon::HostValidationError, 'Instance does not support hidden service connections' if !Rails.configuration.x.access_to_hidden_service && to_hidden
opts = opts.merge(Rails.configuration.x.http_client_proxy).merge(ssl: !to_hidden) opts = { ssl: !to_hidden, headers: {} }.merge(Rails.configuration.x.http_client_proxy).merge(opts)
opts[:headers]['User-Agent'] ||= Mastodon::Version.user_agent
Goldfinger::Client.new(uri, opts).finger Goldfinger::Client.new(uri, opts).finger
end end
end end

View file

@ -48,5 +48,9 @@ module Mastodon
source_base_url source_base_url
end end
end end
def user_agent
@user_agent ||= "#{HTTP::Request::USER_AGENT} (Mastodon/#{Version}; +http#{Rails.configuration.x.use_https ? 's' : ''}://#{Rails.configuration.x.web_domain}/)"
end
end end
end end