<commit_before>module EventStore
  module Client
    module HTTP
      class Client
        setting :host
        setting :port

        dependency :logger, Telemetry::Logger

        attr_writer :socket

        def self.build
          logger.debug "Building HTTP client"

          new.tap do |instance|
            Telemetry::Logger.configure instance
            Settings.instance.set(instance)
            logger.trace "Built HTTP client"
          end
        end

        def self.configure(receiver)
          logger.trace "Configuring client (Receiver: #{receiver})"
          client = build
          receiver.client = client
          logger.debug "Configured client (Receiver: #{receiver})"

          client
        end

        def get(request)
          response = self.! request

          content_length = response["Content-Length"].to_i
          body = socket.read content_length

          [response, body]
        end

        def post(request, data)
          request["Content-Length"] = data.size

          response = self.! request do
            socket.write data
          end

          response
        end

        def !(request)
          request["Host"] = host

          socket.write request
          yield if block_given?

          builder = ::HTTP::Protocol::Response.builder
          builder << socket.gets until builder.finished_headers?
          response = builder.message

          reset_socket if response["Connection"] == "close"

          response
        end

        def socket
          @socket ||= TCPSocket.new host, port
        end

        def reset_socket
          socket.close
          self.socket = nil
        end

        def self.logger
          @logger ||= Telemetry::Logger.get self
        end
      end
    end
  end
end
<commit_msg>Write the in/out data to the logger<commit_after>module EventStore
  module Client
    module HTTP
      class Client
        setting :host
        setting :port

        dependency :logger, Telemetry::Logger

        attr_writer :socket

        def self.build
          logger.debug "Building HTTP client"

          new.tap do |instance|
            Telemetry::Logger.configure instance
            Settings.instance.set(instance)
            logger.trace "Built HTTP client"
          end
        end

        def self.configure(receiver)
          logger.trace "Configuring client (Receiver: #{receiver})"
          client = build
          receiver.client = client
          logger.debug "Configured client (Receiver: #{receiver})"

          client
        end

        def get(request)
          response = self.! request

          content_length = response["Content-Length"].to_i
          body = socket.read content_length

          [response, body]
        end

        def post(request, data)
          request["Content-Length"] = data.size

          response = self.! request do
            socket.write data
          end

          response
        end

        def !(request)
          request["Host"] = host

          logger.data "Writing request to #{socket}:\n\n#{request}"
          socket.write request
          yield if block_given?

          builder = ::HTTP::Protocol::Response.builder
          until builder.finished_headers?
            next_line = socket.gets
            logger.data "Read #{next_line.chomp}"
            builder << next_line
          end
          response = builder.message

          reset_socket if response["Connection"] == "close"

          response
        end

        def socket
          @socket ||= TCPSocket.new host, port
        end

        def reset_socket
          socket.close
          self.socket = nil
        end

        def self.logger
          @logger ||= Telemetry::Logger.get self
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.07488176563321072, 'fraction_numerical': 0.0, 'mean_word_length': 1.5636363636363637, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5200627', 'n_tokens_mistral': 950, 'n_tokens_neox': 909, 'n_words': 269}