summaryrefslogtreecommitdiff
path: root/lib/gitlab/http_connection_adapter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/http_connection_adapter.rb')
-rw-r--r--lib/gitlab/http_connection_adapter.rb38
1 files changed, 29 insertions, 9 deletions
diff --git a/lib/gitlab/http_connection_adapter.rb b/lib/gitlab/http_connection_adapter.rb
index f7a3da53fdb..dfecf3a669e 100644
--- a/lib/gitlab/http_connection_adapter.rb
+++ b/lib/gitlab/http_connection_adapter.rb
@@ -1,14 +1,23 @@
# frozen_string_literal: true
-# This class is part of the Gitlab::HTTP wrapper. Depending on the value
-# of the global setting allow_local_requests_from_web_hooks_and_services this adapter
-# will allow/block connection to internal IPs and/or urls.
+# This class is part of the Gitlab::HTTP wrapper. It handles local requests and header timeouts
#
-# This functionality can be overridden by providing the setting the option
-# allow_local_requests = true in the request. For example:
-# Gitlab::HTTP.get('http://www.gitlab.com', allow_local_requests: true)
+# 1. Local requests
+# Depending on the value of the global setting allow_local_requests_from_web_hooks_and_services,
+# this adapter will allow/block connection to internal IPs and/or urls.
#
-# This option will take precedence over the global setting.
+# This functionality can be overridden by providing the setting the option
+# allow_local_requests = true in the request. For example:
+# Gitlab::HTTP.get('http://www.gitlab.com', allow_local_requests: true)
+#
+# This option will take precedence over the global setting.
+#
+# 2. Header timeouts
+# When the use_read_total_timeout option is used, that means the receiver
+# of the HTTP request cannot be trusted. Gitlab::BufferedIo will be used,
+# to read header data. It is a modified version of Net::BufferedIO that
+# raises a timeout error if reading header data takes too much time.
+
module Gitlab
class HTTPConnectionAdapter < HTTParty::ConnectionAdapter
extend ::Gitlab::Utils::Override
@@ -17,9 +26,20 @@ module Gitlab
def connection
@uri, hostname = validate_url!(uri)
- super.tap do |http|
- http.hostname_override = hostname if hostname
+ http = super
+ http.hostname_override = hostname if hostname
+
+ if Feature.enabled?(:header_read_timeout_buffered_io)
+ gitlab_http = Gitlab::NetHttpAdapter.new(http.address, http.port)
+
+ http.instance_variables.each do |variable|
+ gitlab_http.instance_variable_set(variable, http.instance_variable_get(variable))
+ end
+
+ return gitlab_http
end
+
+ http
end
private