<commit_before>require "faraday"
require "http/cookie_jar"

module Faraday
  class CookieJar < Faraday::Middleware
    def initialize(app, options = {})
      super(app)
      @jar = HTTP::CookieJar.new
    end

    def call(env)
      cookies = @jar.cookies(env[:url])
      unless cookies.empty?
        env[:request_headers]["Cookie"] += ';' + HTTP::Cookie.cookie_value(cookies)
      end

      @app.call(env).on_complete do |res|
        if res[:response_headers]
          if set_cookie = res[:response_headers]["Set-Cookie"]
            @jar.parse(set_cookie, env[:url])
          end
        end
      end
    end
  end
end

if Faraday.respond_to? :register_middleware
  Faraday.register_middleware :cookie_jar => lambda { Faraday::CookieJar }
end<commit_msg>fix request header cookie set error<commit_after>require "faraday"
require "http/cookie_jar"

module Faraday
  class CookieJar < Faraday::Middleware
    def initialize(app, options = {})
      super(app)
      @jar = HTTP::CookieJar.new
    end

    def call(env)
      cookies = @jar.cookies(env[:url])
      unless cookies.empty?
        cookie_value = HTTP::Cookie.cookie_value(cookies)
        if env[:request_headers]["Cookie"]
          env[:request_headers]["Cookie"] = cookie_value + ';' + env[:request_headers]["Cookie"]
        else
          env[:request_headers]["Cookie"] = cookie_value
        end
      end

      @app.call(env).on_complete do |res|
        if res[:response_headers]
          if set_cookie = res[:response_headers]["Set-Cookie"]
            @jar.parse(set_cookie, env[:url])
          end
        end
      end
    end
  end
end

if Faraday.respond_to? :register_middleware
  Faraday.register_middleware :cookie_jar => lambda { Faraday::CookieJar }
end
{'fraction_non_alphanumeric': 0.11815068493150685, 'fraction_numerical': 0.0, 'mean_word_length': 2.8783185840707963, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1429172', 'n_tokens_mistral': 560, 'n_tokens_neox': 547, 'n_words': 111}