lib/sinew/base.rb
# Create the Faraday connection for making requests.
Create the Faraday connection for making requests.
Create the Faraday connection for making requests .
def create_faraday
      faraday_options = options.slice(:headers, :params)
      if options[:insecure]
        faraday_options[:ssl] = { verify: false }
      end
      Faraday.new(nil, faraday_options) do
        if options[:url_prefix]
          _1.url_prefix = options[:url_prefix]
        end
        _1.options.timeout = options[:timeout]
         middleware that runs on both disk/network requests
         cookie middleware
        _1.use :cookie_jar
         auto-encode form bodies
        _1.request :url_encoded
         Before httpdisk so each redirect segment is cached
         Keep track of redirect status for logger
        _1.response :follow_redirects, callback: ->(_old_env, new_env) { new_env[:redirect] = true }
         httpdisk
        httpdisk_options = options.slice(:dir, :expires, :force, :force_errors, :ignore_params, :utf8)
        _1.use :httpdisk, httpdisk_options
         middleware below only used it httpdisk uses the network
         rate limit
        rate_limit = options[:rate_limit]
        _1.request :rate_limiter, interval: rate_limit
         After httpdisk so that only non-cached requests are logged.
         Before retry so that we don't log each retry attempt.
        _1.response :logger, nil, formatter: Middleware::LogFormatter if !options[:silent]
        retry_options = {
          max_interval: rate_limit,  very important, negates Retry-After: 86400
          max: options[:retries],
          methods: %w[delete get head options patch post put trace],
          retry_statuses: (500..600).to_a,
          retry_if: ->(_env, _err) { true },
        }
        _1.request :retry, retry_options
      end
    end
def create_faraday faraday_options = options . slice ( :headers , :params ) if options [ :insecure ] faraday_options [ :ssl ] = { verify : false } end Faraday . new ( nil , faraday_options ) do if options [ :url_prefix ] _1 . url_prefix = options [ :url_prefix ] end _1 . options . timeout = options [ :timeout ] _1 . use :cookie_jar _1 . request :url_encoded _1 . response :follow_redirects , callback : -> ( _old_env , new_env ) { new_env [ :redirect ] = true } httpdisk_options = options . slice ( :dir , :expires , :force , :force_errors , :ignore_params , :utf8 ) _1 . use :httpdisk , httpdisk_options rate_limit = options [ :rate_limit ] _1 . request :rate_limiter , interval : rate_limit _1 . response :logger , nil , formatter : Middleware :: LogFormatter if ! options [ :silent ] retry_options = { max_interval : rate_limit , max : options [ :retries ] , methods : %w[ delete get head options patch post put trace ] , retry_statuses : ( 500 .. 600 ) . to_a , retry_if : -> ( _env , _err ) { true } , } _1 . request :retry , retry_options end end
Create the Faraday connection for making requests.
Create the Faraday connection for making requests .
# options # # middleware that runs on both disk/network requests # # cookie middleware # auto-encode form bodies # Before httpdisk so each redirect segment is cached # Keep track of redirect status for logger # # httpdisk # # # middleware below only used it httpdisk uses the network # # rate limit # After httpdisk so that only non-cached requests are logged. # Before retry so that we don't log each retry attempt. # very important, negates Retry-After: 86400