about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMIYAGI Hikaru <hcmiya@users.noreply.github.com>2018-05-18 08:47:22 +0900
committerEugen Rochko <eugen@zeonfederated.com>2018-05-18 01:47:22 +0200
commit919eef309820a421d6f5886b8ae811d3924cea97 (patch)
tree0174be003e00cc3addbe3a5e04075eae67c2f7a7
parent7293b9fc6190acd6d2a481c158c718a7a8299c73 (diff)
User agent for WebFinger (#7531)
* User agent for WebFinger

* local_domain → web_domain

* 'http' is away accidentally...
-rw-r--r--app/lib/request.rb6
-rw-r--r--config/initializers/http_client_proxy.rb3
-rw-r--r--lib/mastodon/version.rb4
3 files changed, 7 insertions, 6 deletions
diff --git a/app/lib/request.rb b/app/lib/request.rb
index 731bf7687..397614fac 100644
--- a/app/lib/request.rb
+++ b/app/lib/request.rb
@@ -58,7 +58,7 @@ class Request
 
   def set_common_headers!
     @headers[REQUEST_TARGET]    = "#{@verb} #{@url.path}"
-    @headers['User-Agent']      = user_agent
+    @headers['User-Agent']      = Mastodon::Version.user_agent
     @headers['Host']            = @url.host
     @headers['Date']            = Time.now.utc.httpdate
     @headers['Accept-Encoding'] = 'gzip' if @verb != :head
@@ -83,10 +83,6 @@ class Request
     @headers.keys.join(' ').downcase
   end
 
-  def user_agent
-    @user_agent ||= "#{HTTP::Request::USER_AGENT} (Mastodon/#{Mastodon::Version}; +#{root_url})"
-  end
-
   def key_id
     case @key_id_format
     when :acct
diff --git a/config/initializers/http_client_proxy.rb b/config/initializers/http_client_proxy.rb
index f5026d59e..52c595c5d 100644
--- a/config/initializers/http_client_proxy.rb
+++ b/config/initializers/http_client_proxy.rb
@@ -18,7 +18,8 @@ module Goldfinger
   def self.finger(uri, opts = {})
     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
-    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
   end
 end
diff --git a/lib/mastodon/version.rb b/lib/mastodon/version.rb
index 697f317d8..874dfedb7 100644
--- a/lib/mastodon/version.rb
+++ b/lib/mastodon/version.rb
@@ -48,5 +48,9 @@ module Mastodon
         source_base_url
       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