perform_request

in lib/elastic/transport/transport/http/curb.rb [32:70]


          def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
            super do |connection, url|
              capture_otel_span_attributes(connection, url)
              connection.connection.url = connection.full_url(path, params)
              body = body ? __convert_to_json(body) : nil
              body, headers = compress_request(body, headers)

              case method
              when 'HEAD'
                connection.connection.set :nobody, true
              when 'GET', 'POST', 'PUT', 'DELETE'
                connection.connection.set :nobody, false
                connection.connection.put_data = body if body

                if headers
                  if connection.connection.headers
                    connection.connection.headers.merge!(headers)
                  else
                    connection.connection.headers = headers
                  end
                end

              else raise ArgumentError, "Unsupported HTTP method: #{method}"
              end

              connection.connection.http(method.to_sym)
              header_string = connection.connection.header_str.to_s

              _response_status, *response_headers = header_string.split(/[\r\n]+/).map(&:strip)
              response_headers = Hash[response_headers.flat_map { |s| s.scan(/^(\S+): (.+)/) }].transform_keys(&:downcase)

              Response.new(
                connection.connection.response_code,
                decompress_response(connection.connection.body_str),
                response_headers
              )
            end
          end