Sha256: d3d5e040a8cf5f4146f8c5ef08a9fc21ee3b3a3ab8870215f3a8d4e0970c1954
Contents?: true
Size: 962 Bytes
Versions: 48
Compression:
Stored size: 962 Bytes
Contents
# frozen_string_literal: true module Excon module Middleware class CaptureCookies < Excon::Middleware::Base def extract_cookies_from_set_cookie(set_cookie) set_cookie.split(',').map { |full| full.split(';').first.strip }.join('; ') end def get_header(datum, header) _, header_value = datum[:response][:headers].detect do |key, _| key.casecmp(header) == 0 end header_value end def response_call(datum) cookie = get_header(datum, 'Set-Cookie') if cookie cookie = extract_cookies_from_set_cookie(cookie) unless datum[:headers].key?("Cookie") datum[:headers]["Cookie"] = cookie else original_cookies = datum[:headers]["Cookie"] datum[:headers]["Cookie"] = original_cookies.empty? ? cookie : [original_cookies,cookie].join('; ') end end super(datum) end end end end
Version data entries
48 entries across 47 versions & 2 rubygems