diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 09:45:46 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 09:45:46 +0000 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /lib/gitlab/http_connection_adapter.rb | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) | |
download | gitlab-ce-a7b3560714b4d9cc4ab32dffcd1f74a284b93580.tar.gz |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
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..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 |