diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-03 04:19:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-03 04:19:28 +0300 |
commit | 30f229be4c0c3b8458244da44c37cc0485a875b2 (patch) | |
tree | 44c47024b98f9bd959ef221d30fe1000cc67e154 /lib/gitlab/http_connection_adapter.rb | |
parent | 33bbd0b39bda02f24468184e5e3d8f6d257246d4 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/http_connection_adapter.rb')
-rw-r--r-- | lib/gitlab/http_connection_adapter.rb | 38 |
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..39051e4ec19 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 options[:use_read_total_timeout] + 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 |