<commit_before># frozen_string_literal: true

module Faraday
  class Adapter
    # Excon adapter.
    class Excon < Faraday::Adapter
      dependency 'excon'

      def call(env)
        super

        opts = opts_from_env(env)
        conn = create_connection(env, opts)

        resp = conn.request(method: env[:method].to_s.upcase,
                            headers: env[:request_headers],
                            body: read_body(env))

        req = env[:request]
        if req&.stream_response?
          warn "Streaming downloads for #{self.class.name} are not yet " \
               ' implemented.'
          req.on_data.call(resp.body, resp.body.bytesize)
        end
        save_response(env, resp.status.to_i, resp.body, resp.headers,
                      resp.reason_phrase)

        @app.call(env)<commit_msg>Excon streaming (#1026)<commit_after># frozen_string_literal: true

module Faraday
  class Adapter
    # Excon adapter.
    class Excon < Faraday::Adapter
      dependency 'excon'

      def call(env)
        super

        opts = opts_from_env(env)
        conn = create_connection(env, opts)

        req_opts = {
          method: env[:method].to_s.upcase,
          headers: env[:request_headers],
          body: read_body(env)
        }

        req = env[:request]
        if req&.stream_response?
          total = 0
          req_opts[:response_block] = lambda do |chunk, _remain, _total|
            req.on_data.call(chunk, total += chunk.size)
          end
        end

        resp = conn.request(req_opts)
        save_response(env, resp.status.to_i, resp.body, resp.headers,
                      resp.reason_phrase)

        @app.call(env)
{'fraction_non_alphanumeric': 0.09851632047477744, 'fraction_numerical': 0.002967359050445104, 'mean_word_length': 1.882051282051282, 'pattern_counts': {'":': 0, '<': 5, '<?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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '215271', 'n_tokens_mistral': 516, 'n_tokens_neox': 491, 'n_words': 106}