Welcome to mirror list, hosted at ThFree Co, Russian Federation.

net_http_patch.rb « initializers « config - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8231423e1a518d8041bb0833a93c6c5876529393 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

# Monkey patch Net::HTTP to fix missing URL decoding for username and password in proxy settings
#
# See proposed upstream fix https://github.com/ruby/net-http/pull/5
# See Ruby-lang issue https://bugs.ruby-lang.org/issues/17542
# See issue on GitLab https://gitlab.com/gitlab-org/gitlab/-/issues/289836

require 'net/http'

# This file can be removed once Ruby 3.0 is no longer supported:
# https://gitlab.com/gitlab-org/gitlab/-/issues/396223
return if Gem::Version.new(Net::HTTP::VERSION) >= Gem::Version.new('0.2.0')

module Net
  class HTTP < Protocol
    def proxy_user
      if environment_variable_is_multiuser_safe? && @proxy_from_env
        user = proxy_uri&.user
        CGI.unescape(user) unless user.nil?
      else
        @proxy_user
      end
    end

    def proxy_pass
      if environment_variable_is_multiuser_safe? && @proxy_from_env
        pass = proxy_uri&.password
        CGI.unescape(pass) unless pass.nil?
      else
        @proxy_pass
      end
    end

    def environment_variable_is_multiuser_safe?
      ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE
    end
  end
end