# frozen_string_literal: true module Wayfarer module Networking class HTTP include Strategy CONNECTION_NAME = "wayfarer" def create Net::HTTP::Persistent.new(name: CONNECTION_NAME).tap do |conn| Wayfarer.config[:network][:http_headers].each do |key, val| conn.override_headers[key] = val end end end def destroy(instance) instance.shutdown end def fetch(instance, url) res = instance.request(URI(url)) return redirect(res["location"]) if res.is_a?(Net::HTTPRedirection) success(url: url, status_code: res.code.to_i, body: res.body, headers: res.to_hash.transform_values(&:first)) end end end end