diff options
author | David Yip <yipdw@member.fsf.org> | 2018-05-03 17:23:44 -0500 |
---|---|---|
committer | David Yip <yipdw@member.fsf.org> | 2018-05-03 17:23:44 -0500 |
commit | c816701550d7cdb593371dc47d0b9430c78308b0 (patch) | |
tree | cc4417d14de20e69fd5f9a58d66f84af4a623329 /app/lib/request.rb | |
parent | 3a47842223ff93d8c057f804809f1b111dfd6f76 (diff) | |
parent | a7e71bbd08e089938fbf20ddef5768c2f3ee0702 (diff) |
Merge remote-tracking branch 'origin/master' into gs-master
Conflicts: .travis.yml Gemfile.lock README.md app/controllers/settings/follower_domains_controller.rb app/controllers/statuses_controller.rb app/javascript/mastodon/locales/ja.json app/lib/feed_manager.rb app/models/media_attachment.rb app/models/mute.rb app/models/status.rb app/services/mute_service.rb app/views/home/index.html.haml app/views/stream_entries/_simple_status.html.haml config/locales/ca.yml config/locales/en.yml config/locales/es.yml config/locales/fr.yml config/locales/nl.yml config/locales/pl.yml config/locales/pt-BR.yml config/themes.yml
Diffstat (limited to 'app/lib/request.rb')
-rw-r--r-- | app/lib/request.rb | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/app/lib/request.rb b/app/lib/request.rb index dca93a6e9..00f94dacf 100644 --- a/app/lib/request.rb +++ b/app/lib/request.rb @@ -9,11 +9,15 @@ class Request include RoutingHelper def initialize(verb, url, **options) + raise ArgumentError if url.blank? + @verb = verb @url = Addressable::URI.parse(url).normalize - @options = options.merge(socket_class: Socket) + @options = options.merge(use_proxy? ? Rails.configuration.x.http_client_proxy : { socket_class: Socket }) @headers = {} + raise Mastodon::HostValidationError, 'Instance does not support hidden service connections' if block_hidden_service? + set_common_headers! set_digest! if options.key?(:body) end @@ -99,6 +103,14 @@ class Request @http_client ||= HTTP.timeout(:per_operation, timeout).follow(max_hops: 2) end + def use_proxy? + Rails.configuration.x.http_client_proxy.present? + end + + def block_hidden_service? + !Rails.configuration.x.access_to_hidden_service && /\.(onion|i2p)$/.match(@url.host) + end + module ClientLimit def body_with_limit(limit = 1.megabyte) raise Mastodon::LengthValidationError if content_length.present? && content_length > limit @@ -129,6 +141,7 @@ class Request class Socket < TCPSocket class << self def open(host, *args) + return super host, *args if thru_hidden_service? host outer_e = nil Addrinfo.foreach(host, nil, nil, :SOCK_STREAM) do |address| begin @@ -142,6 +155,10 @@ class Request end alias new open + + def thru_hidden_service?(host) + Rails.configuration.x.hidden_service_via_transparent_proxy && /\.(onion|i2p)$/.match(host) + end end end |