summaryrefslogtreecommitdiff
path: root/lib/gitlab/http_connection_adapter.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
commitf64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch)
treea2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /lib/gitlab/http_connection_adapter.rb
parentbfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff)
downloadgitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'lib/gitlab/http_connection_adapter.rb')
-rw-r--r--lib/gitlab/http_connection_adapter.rb31
1 files changed, 25 insertions, 6 deletions
diff --git a/lib/gitlab/http_connection_adapter.rb b/lib/gitlab/http_connection_adapter.rb
index 84eb60f3a5d..37f618ae879 100644
--- a/lib/gitlab/http_connection_adapter.rb
+++ b/lib/gitlab/http_connection_adapter.rb
@@ -11,13 +11,18 @@
# This option will take precedence over the global setting.
module Gitlab
class HTTPConnectionAdapter < HTTParty::ConnectionAdapter
+ extend ::Gitlab::Utils::Override
+
+ override :connection
def connection
- begin
- @uri, hostname = Gitlab::UrlBlocker.validate!(uri, allow_local_network: allow_local_requests?,
- allow_localhost: allow_local_requests?,
- dns_rebind_protection: dns_rebind_protection?)
- rescue Gitlab::UrlBlocker::BlockedUrlError => e
- raise Gitlab::HTTP::BlockedUrlError, "URL '#{uri}' is blocked: #{e.message}"
+ @uri, hostname = validate_url!(uri)
+
+ if options.key?(:http_proxyaddr)
+ proxy_uri_with_port = uri_with_port(options[:http_proxyaddr], options[:http_proxyport])
+ proxy_uri_validated = validate_url!(proxy_uri_with_port).first
+
+ @options[:http_proxyaddr] = proxy_uri_validated.omit(:port).to_s
+ @options[:http_proxyport] = proxy_uri_validated.port
end
super.tap do |http|
@@ -27,6 +32,14 @@ module Gitlab
private
+ def validate_url!(url)
+ Gitlab::UrlBlocker.validate!(url, allow_local_network: allow_local_requests?,
+ allow_localhost: allow_local_requests?,
+ dns_rebind_protection: dns_rebind_protection?)
+ rescue Gitlab::UrlBlocker::BlockedUrlError => e
+ raise Gitlab::HTTP::BlockedUrlError, "URL '#{url}' is blocked: #{e.message}"
+ end
+
def allow_local_requests?
options.fetch(:allow_local_requests, allow_settings_local_requests?)
end
@@ -40,5 +53,11 @@ module Gitlab
def allow_settings_local_requests?
Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?
end
+
+ def uri_with_port(address, port)
+ uri = Addressable::URI.parse(address)
+ uri.port = port if port.present?
+ uri
+ end
end
end