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

net_http_adapter.rb « http_v2 « gitlab « lib « gitlab-http « gems - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c6af2ed6aff46f5deff1cb94ed1b4b9c3e025d8f (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
# frozen_string_literal: true

require 'net/http'
require 'webmock' if Rails.env.test?
require_relative 'buffered_io'

module Gitlab
  module HTTP_V2
    # Webmock overwrites the Net::HTTP#request method with
    # https://github.com/bblimke/webmock/blob/867f4b290fd133658aa9530cba4ba8b8c52c0d35/lib/webmock/http_lib_adapters/net_http.rb#L74
    # Net::HTTP#request usually calls Net::HTTP#connect but the Webmock overwrite doesn't.
    # This makes sure that, in a test environment, the superclass is the Webmock overwrite.
    parent_class = if defined?(WebMock) && Rails.env.test?
                     WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get(:@webMockNetHTTP)
                   else
                     Net::HTTP
                   end

    class NetHttpAdapter < parent_class
      private

      def connect
        result = super

        @socket = BufferedIo.new(@socket.io,
          read_timeout: @socket.read_timeout,
          write_timeout: @socket.write_timeout,
          continue_timeout: @socket.continue_timeout,
          debug_output: @socket.debug_output)

        result
      end
    end
  end
end