Hello community, here is the log from the commit of package rubygem-faraday_middleware for openSUSE:Factory checked in at 2020-05-11 13:40:52 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-faraday_middleware (Old) and /work/SRC/openSUSE:Factory/.rubygem-faraday_middleware.new.2738 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-faraday_middleware" Mon May 11 13:40:52 2020 rev:14 rq:802333 version:1.0.0 Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-faraday_middleware/rubygem-faraday_middleware.changes 2020-03-07 21:38:02.680264295 +0100 +++ /work/SRC/openSUSE:Factory/.rubygem-faraday_middleware.new.2738/rubygem-faraday_middleware.changes 2020-05-11 13:40:59.377073110 +0200 @@ -1,0 +2,6 @@ +Thu May 7 20:42:03 UTC 2020 - Stephan Kulow <co...@suse.com> + +- updated to version 1.0.0 + no changelog found + +------------------------------------------------------------------- Old: ---- faraday_middleware-0.14.0.gem New: ---- faraday_middleware-1.0.0.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-faraday_middleware.spec ++++++ --- /var/tmp/diff_new_pack.FY7SFi/_old 2020-05-11 13:41:00.581075665 +0200 +++ /var/tmp/diff_new_pack.FY7SFi/_new 2020-05-11 13:41:00.585075673 +0200 @@ -24,13 +24,13 @@ # Name: rubygem-faraday_middleware -Version: 0.14.0 +Version: 1.0.0 Release: 0 %define mod_name faraday_middleware %define mod_full_name %{mod_name}-%{version} BuildRoot: %{_tmppath}/%{name}-%{version}-build +BuildRequires: %{ruby >= 2.3} BuildRequires: %{rubygem gem2rpm} -BuildRequires: %{ruby} BuildRequires: ruby-macros >= 5 URL: https://github.com/lostisland/faraday_middleware Source: https://rubygems.org/gems/%{mod_full_name}.gem ++++++ faraday_middleware-0.14.0.gem -> faraday_middleware-1.0.0.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/README.md new/README.md --- old/README.md 2020-01-19 11:31:37.000000000 +0100 +++ new/README.md 2020-03-29 12:15:52.000000000 +0200 @@ -1,7 +1,7 @@ Faraday Middleware ================== [![Gem Version](https://badge.fury.io/rb/faraday_middleware.svg)](https://rubygems.org/gems/faraday_middleware) -[![Build Status](https://travis-ci.org/lostisland/faraday_middleware.svg)](https://travis-ci.org/lostisland/faraday_middleware) +![GitHub Actions CI](https://github.com/lostisland/faraday_middleware/workflows/CI/badge.svg) [![Maintainability](https://api.codeclimate.com/v1/badges/a971ee5025b269c39d93/maintainability)](https://codeclimate.com/github/lostisland/faraday_middleware/maintainability) A collection of useful [Faraday][] middleware. [See the documentation][docs]. @@ -11,6 +11,10 @@ Dependencies ------------ +Ruby >= 2.3.0 + +#### As of v0.16.0, `faraday` and `faraday_middleware` no longer officially support JRuby or Rubinius. + Some dependent libraries are needed only when using specific middleware: | Middleware | Library | Notes | @@ -28,29 +32,16 @@ ``` rb require 'faraday_middleware' -## in Faraday 0.8 or above: connection = Faraday.new 'http://example.com/api' do |conn| conn.request :oauth2, 'TOKEN' conn.request :json - conn.response :xml, :content_type => /\bxml$/ - conn.response :json, :content_type => /\bjson$/ + conn.response :xml, content_type: /\bxml$/ + conn.response :json, content_type: /\bjson$/ conn.use :instrumentation conn.adapter Faraday.default_adapter end - -## with Faraday 0.7: -connection = Faraday.new 'http://example.com/api' do |builder| - builder.use FaradayMiddleware::OAuth2, 'TOKEN' - builder.use FaradayMiddleware::EncodeJson - - builder.use FaradayMiddleware::ParseXml, :content_type => /\bxml$/ - builder.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/ - - builder.use FaradayMiddleware::Instrumentation - builder.adapter Faraday.default_adapter -end ``` Binary files old/checksums.yaml.gz and new/checksums.yaml.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/backwards_compatibility.rb new/lib/faraday_middleware/backwards_compatibility.rb --- old/lib/faraday_middleware/backwards_compatibility.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/backwards_compatibility.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,11 +1,13 @@ -# deprecated constants +# frozen_string_literal: true module Faraday + # Autoload classes for Faraday::Request. class Request autoload :OAuth, 'faraday_middleware/request/oauth' autoload :OAuth2, 'faraday_middleware/request/oauth2' end + # Autoload classes for Faraday::Request. class Response autoload :Mashify, 'faraday_middleware/response/mashify' autoload :Rashify, 'faraday_middleware/response/rashify' @@ -15,4 +17,3 @@ autoload :ParseYaml, 'faraday_middleware/response/parse_yaml' end end - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/gzip.rb new/lib/faraday_middleware/gzip.rb --- old/lib/faraday_middleware/gzip.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/gzip.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday' module FaradayMiddleware @@ -28,11 +30,10 @@ encodings end - ACCEPT_ENCODING = 'Accept-Encoding'.freeze - CONTENT_ENCODING = 'Content-Encoding'.freeze - CONTENT_LENGTH = 'Content-Length'.freeze + ACCEPT_ENCODING = 'Accept-Encoding' + CONTENT_ENCODING = 'Content-Encoding' + CONTENT_LENGTH = 'Content-Length' SUPPORTED_ENCODINGS = supported_encodings.join(',').freeze - RUBY_ENCODING = '1.9'.respond_to?(:force_encoding) def call(env) env[:request_headers][ACCEPT_ENCODING] ||= SUPPORTED_ENCODINGS @@ -60,11 +61,7 @@ def uncompress_gzip(body) io = StringIO.new(body) - gzip_reader = if RUBY_ENCODING - Zlib::GzipReader.new(io, :encoding => 'ASCII-8BIT') - else - Zlib::GzipReader.new(io) - end + gzip_reader = Zlib::GzipReader.new(io, encoding: 'ASCII-8BIT') gzip_reader.read end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/instrumentation.rb new/lib/faraday_middleware/instrumentation.rb --- old/lib/faraday_middleware/instrumentation.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/instrumentation.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday' module FaradayMiddleware @@ -7,11 +9,15 @@ # # Examples # - # ActiveSupport::Notifications.subscribe('request.faraday') do |name, starts, ends, _, env| + # ActiveSupport::Notifications. + # subscribe('request.faraday') do |name, starts, ends, _, env| # url = env[:url] # http_method = env[:method].to_s.upcase # duration = ends - starts - # $stderr.puts '[%s] %s %s (%.3f s)' % [url.host, http_method, url.request_uri, duration] + # $stderr.puts '[%s] %s %s (%.3f s)' % [url.host, + # http_method, + # url.request_uri, + # duration] # end class Instrumentation < Faraday::Middleware dependency 'active_support/notifications' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/rack_compatible.rb new/lib/faraday_middleware/rack_compatible.rb --- old/lib/faraday_middleware/rack_compatible.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/rack_compatible.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,7 +1,9 @@ +# frozen_string_literal: true + require 'stringio' module FaradayMiddleware - # Wraps a handler originally written for Rack to make it compatible with Faraday. + # Wraps a handler originally written for Rack for Faraday compatibility. # # Experimental. Only handles changes in request headers. class RackCompatible @@ -22,7 +24,7 @@ finalize_response(env, rack_response) end - NonPrefixedHeaders = %w[CONTENT_LENGTH CONTENT_TYPE] + NON_PREFIXED_HEADERS = %w[CONTENT_LENGTH CONTENT_TYPE].freeze # faraday to rack-compatible def prepare_env(faraday_env) @@ -31,7 +33,11 @@ url = faraday_env[:url] env['rack.url_scheme'] = url.scheme env['PATH_INFO'] = url.path - env['SERVER_PORT'] = url.respond_to?(:inferred_port) ? url.inferred_port : url.port + env['SERVER_PORT'] = if url.respond_to?(:inferred_port) + url.inferred_port + else + url.port + end env['QUERY_STRING'] = url.query env['REQUEST_METHOD'] = faraday_env[:method].to_s.upcase @@ -45,7 +51,7 @@ rack_env = {} env[:request_headers].each do |name, value| name = name.upcase.tr('-', '_') - name = "HTTP_#{name}" unless NonPrefixedHeaders.include? name + name = "HTTP_#{name}" unless NON_PREFIXED_HEADERS.include? name rack_env[name] = value end rack_env @@ -58,8 +64,9 @@ headers.clear rack_env.each do |name, value| - next unless String === name && String === value - if NonPrefixedHeaders.include? name or name.index('HTTP_') == 0 + next unless name.is_a?(String) && value.is_a?(String) + + if NON_PREFIXED_HEADERS.include?(name) || name.start_with?('HTTP_') name = name.sub(/^HTTP_/, '').downcase.tr('_', '-') headers[name] = value end @@ -72,12 +79,14 @@ def finalize_response(env, rack_response) status, headers, body = rack_response - body = body.inject() { |str, part| str << part } - headers = Faraday::Utils::Headers.new(headers) unless Faraday::Utils::Headers === headers + body = body.inject { |str, part| str << part } + unless headers.is_a?(Faraday::Utils::Headers) + headers = Faraday::Utils::Headers.new(headers) + end - env.update :status => status.to_i, - :body => body, - :response_headers => headers + env.update status: status.to_i, + body: body, + response_headers: headers env[:response] ||= Faraday::Response.new(env) env[:response] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/redirect_limit_reached.rb new/lib/faraday_middleware/redirect_limit_reached.rb --- old/lib/faraday_middleware/redirect_limit_reached.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/faraday_middleware/redirect_limit_reached.rb 2020-03-29 12:15:52.000000000 +0200 @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'faraday' + +module FaradayMiddleware + # Exception thrown when the maximum amount of requests is + # exceeded. + class RedirectLimitReached < Faraday::ClientError + attr_reader :response + + def initialize(response) + super "too many redirects; last one to: #{response['location']}" + @response = response + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/request/encode_json.rb new/lib/faraday_middleware/request/encode_json.rb --- old/lib/faraday_middleware/request/encode_json.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/request/encode_json.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday' module FaradayMiddleware @@ -9,9 +11,9 @@ # # Doesn't try to encode bodies that already are in string form. class EncodeJson < Faraday::Middleware - CONTENT_TYPE = 'Content-Type'.freeze - MIME_TYPE = 'application/json'.freeze - MIME_TYPE_REGEX = /^application\/(vnd\..+\+)?json$/ + CONTENT_TYPE = 'Content-Type' + MIME_TYPE = 'application/json' + MIME_TYPE_REGEX = %r{^application/(vnd\..+\+)?json$}.freeze dependency do require 'json' unless defined?(::JSON) @@ -29,19 +31,19 @@ end def match_content_type(env) - if process_request?(env) - env[:request_headers][CONTENT_TYPE] ||= MIME_TYPE - yield env[:body] unless env[:body].respond_to?(:to_str) - end + return unless process_request?(env) + + env[:request_headers][CONTENT_TYPE] ||= MIME_TYPE + yield env[:body] unless env[:body].respond_to?(:to_str) end def process_request?(env) type = request_type(env) - has_body?(env) and (type.empty? or MIME_TYPE_REGEX =~ type) + has_body?(env) && (type.empty? || MIME_TYPE_REGEX =~ type) end def has_body?(env) - body = env[:body] and !(body.respond_to?(:to_str) and body.empty?) + (body = env[:body]) && !(body.respond_to?(:to_str) && body.empty?) end def request_type(env) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/request/method_override.rb new/lib/faraday_middleware/request/method_override.rb --- old/lib/faraday_middleware/request/method_override.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/request/method_override.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday' module FaradayMiddleware @@ -11,8 +13,7 @@ # Rack::MethodOverride module. See # http://rack.rubyforge.org/doc/classes/Rack/MethodOverride.html class MethodOverride < Faraday::Middleware - - HEADER = "X-Http-Method-Override".freeze + HEADER = 'X-Http-Method-Override' # Public: Initialize the middleware. # @@ -22,10 +23,10 @@ # (default: all but GET and POST) def initialize(app, options = nil) super(app) - @methods = options && options.fetch(:rewrite).map { |method| + @methods = options&.fetch(:rewrite)&.map do |method| method = method.downcase if method.respond_to? :downcase method.to_sym - } + end end def call(env) @@ -35,8 +36,8 @@ end def rewrite_request?(method) - if @methods.nil? or @methods.empty? - method != :get and method != :post + if @methods.nil? || @methods.empty? + (method != :get) && (method != :post) else @methods.include? method end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/request/oauth.rb new/lib/faraday_middleware/request/oauth.rb --- old/lib/faraday_middleware/request/oauth.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/request/oauth.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday' require 'forwardable' @@ -23,14 +25,12 @@ class OAuth < Faraday::Middleware dependency 'simple_oauth' - AUTH_HEADER = 'Authorization'.freeze - CONTENT_TYPE = 'Content-Type'.freeze - TYPE_URLENCODED = 'application/x-www-form-urlencoded'.freeze + AUTH_HEADER = 'Authorization' + CONTENT_TYPE = 'Content-Type' + TYPE_URLENCODED = 'application/x-www-form-urlencoded' extend Forwardable - parser_method = :parse_nested_query - parser_module = ::Faraday::Utils.respond_to?(parser_method) ? 'Faraday::Utils' : 'Rack::Utils' - def_delegator parser_module, parser_method + def_delegator :'Faraday::Utils', :parse_nested_query def initialize(app, options) super(app) @@ -38,7 +38,9 @@ end def call(env) - env[:request_headers][AUTH_HEADER] ||= oauth_header(env).to_s if sign_request?(env) + if sign_request?(env) + env[:request_headers][AUTH_HEADER] ||= oauth_header(env).to_s + end @app.call(env) end @@ -54,7 +56,7 @@ end def oauth_options(env) - if extra = env[:request][:oauth] and extra.is_a? Hash and !extra.empty? + if (extra = env[:request][:oauth]) && extra.is_a?(Hash) && !extra.empty? @options.merge extra else @options @@ -73,12 +75,15 @@ def include_body_params?(env) # see RFC 5849, section 3.4.1.3.1 for details - !(type = env[:request_headers][CONTENT_TYPE]) or type == TYPE_URLENCODED + !(type = env[:request_headers][CONTENT_TYPE]) || (type == TYPE_URLENCODED) end def signature_params(params) - params.empty? ? params : - params.reject {|k,v| v.respond_to?(:content_type) } + if params.empty? + params + else + params.reject { |_k, v| v.respond_to?(:content_type) } + end end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/request/oauth2.rb new/lib/faraday_middleware/request/oauth2.rb --- old/lib/faraday_middleware/request/oauth2.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/request/oauth2.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,14 +1,17 @@ +# frozen_string_literal: true + require 'faraday' require 'forwardable' module FaradayMiddleware # Public: A simple middleware that adds an access token to each request. # - # By default, the token is added as both "access_token" query parameter and the - # "Authorization" HTTP request header. It can alternatively be added exclusively - # as a bearer token "Authorization" header by specifying a "token_type" option - # of "bearer". However, an explicit "access_token" parameter or "Authorization" - # header for the current request are not overriden. + # By default, the token is added as both "access_token" query parameter + # and the "Authorization" HTTP request header. It can alternatively be + # added exclusively as a bearer token "Authorization" header by specifying + # a "token_type" option of "bearer". However, an explicit "access_token" + # parameter or "Authorization" header for the current request are not + # overriden. # # Examples # @@ -24,10 +27,9 @@ # # default token value is optional: # OAuth2.new(app, :param_name => 'my_oauth_token') class OAuth2 < Faraday::Middleware - - PARAM_NAME = 'access_token'.freeze - TOKEN_TYPE = 'param'.freeze - AUTH_HEADER = 'Authorization'.freeze + PARAM_NAME = 'access_token' + TOKEN_TYPE = 'param' + AUTH_HEADER = 'Authorization' attr_reader :param_name, :token_type @@ -53,8 +55,11 @@ def initialize(app, token = nil, options = {}) super(app) - options, token = token, nil if token.is_a? Hash - @token = token && token.to_s + if token.is_a? Hash + options = token + token = nil + end + @token = token&.to_s @param_name = options.fetch(:param_name, PARAM_NAME).to_s @token_type = options.fetch(:token_type, TOKEN_TYPE).to_s @@ -62,17 +67,17 @@ raise ArgumentError, ":param_name can't be blank" end - if options[:token_type].nil? - warn "\nWarning: FaradayMiddleware::OAuth2 initialized with default "\ - "token_type - token will be added as both a query string parameter "\ - "and an Authorization header. In the next major release, tokens will "\ - "be added exclusively as an Authorization header by default. Please "\ - "visit https://github.com/lostisland/faraday_middleware/wiki for more information." - end + return unless options[:token_type].nil? + + warn "\nWarning: FaradayMiddleware::OAuth2 initialized with default "\ + 'token_type - token will be added as both a query string parameter '\ + 'and an Authorization header. In the next major release, tokens will '\ + 'be added exclusively as an Authorization header by default. Please '\ + 'see https://github.com/lostisland/faraday_middleware/wiki.' end def query_params(url) - if url.query.nil? or url.query.empty? + if url.query.nil? || url.query.empty? {} else parse_query url.query diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/response/caching.rb new/lib/faraday_middleware/response/caching.rb --- old/lib/faraday_middleware/response/caching.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/response/caching.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday' require 'forwardable' require 'digest/sha1' @@ -14,7 +16,7 @@ # * 302 - 'Found' # * 404 - 'Not Found' # * 410 - 'Gone' - CACHEABLE_STATUS_CODES = [200, 203, 300, 301, 302, 404, 410] + CACHEABLE_STATUS_CODES = [200, 203, 300, 301, 302, 404, 410].freeze extend Forwardable def_delegators :'Faraday::Utils', :parse_query, :build_query @@ -23,31 +25,36 @@ # # cache - An object that responds to read and write (default: nil). # options - An options Hash (default: {}): - # :ignore_params - String name or Array names of query params - # that should be ignored when forming the cache - # key (default: []). - # :write_options - Hash of settings that should be passed as the third - # options parameter to the cache's #write method. If not - # specified, no options parameter will be passed. - # :full_key - Boolean - use full URL (url.host + url.request_uri) as cache key + # :ignore_params - String name or Array names of query + # params that should be ignored when forming + # the cache key (default: []). + # :write_options - Hash of settings that should be passed as the + # third options parameter to the cache's #write + # method. If not specified, no options parameter + # will be passed. + # :full_key - Boolean - use full URL as cache key: + # (url.host + url.request_uri) # # Yields if no cache is given. The block should return a cache object. def initialize(app, cache = nil, options = {}) super(app) - options, cache = cache, nil if cache.is_a? Hash and block_given? + if cache.is_a?(Hash) && block_given? + options = cache + cache = nil + end @cache = cache || yield @options = options end def call(env) - if :get == env[:method] + if env[:method] == :get if env[:parallel_manager] # callback mode cache_on_complete(env) else # synchronous mode key = cache_key(env) - unless response = cache.read(key) and response + unless (response = cache.read(key)) && response response = @app.call(env) store_response_in_cache(key, response) end @@ -62,15 +69,16 @@ url = env[:url].dup if url.query && params_to_ignore.any? params = parse_query url.query - params.reject! {|k,| params_to_ignore.include? k } + params.reject! { |k,| params_to_ignore.include? k } url.query = params.any? ? build_query(params) : nil end url.normalize! - Digest::SHA1.hexdigest(full_key? ? url.host + url.request_uri : url.request_uri) + digest = full_key? ? url.host + url.request_uri : url.request_uri + Digest::SHA1.hexdigest(digest) end def params_to_ignore - @params_to_ignore ||= Array(@options[:ignore_params]).map { |p| p.to_s } + @params_to_ignore ||= Array(@options[:ignore_params]).map(&:to_s) end def full_key? @@ -79,10 +87,11 @@ def cache_on_complete(env) key = cache_key(env) - if cached_response = cache.read(key) + if (cached_response = cache.read(key)) finalize_response(cached_response, env) else - # response.status is nil at this point, any checks need to be done inside on_complete block + # response.status is nil at this point + # any checks need to be done inside on_complete block @app.call(env).on_complete do |response_env| store_response_in_cache(key, response_env.response) response_env diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/response/chunked.rb new/lib/faraday_middleware/response/chunked.rb --- old/lib/faraday_middleware/response/chunked.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/response/chunked.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,16 +1,19 @@ +# frozen_string_literal: true + require 'faraday_middleware/response_middleware' module FaradayMiddleware - # Public: Parse a Transfer-Encoding: Chunked response to just the original data + # Public: Parse a Transfer-Encoding. Chunks response to just the original data class Chunked < FaradayMiddleware::ResponseMiddleware - TRANSFER_ENCODING = 'transfer-encoding'.freeze + TRANSFER_ENCODING = 'transfer-encoding' define_parser do |raw_body| decoded_body = [] until raw_body.empty? chunk_len, raw_body = raw_body.split("\r\n", 2) - chunk_len = chunk_len.split(';',2).first.hex - break if chunk_len == 0 + chunk_len = chunk_len.split(';', 2).first.hex + break if chunk_len.zero? + decoded_body << raw_body[0, chunk_len] # The 2 is to strip the extra CRLF at the end of the chunk raw_body = raw_body[chunk_len + 2, raw_body.length - chunk_len - 2] @@ -19,11 +22,12 @@ end def parse_response?(env) - super and chunked_encoding?(env[:response_headers]) + super && chunked_encoding?(env[:response_headers]) end def chunked_encoding?(headers) - encoding = headers[TRANSFER_ENCODING] and encoding.split(',').include?('chunked') + (encoding = headers[TRANSFER_ENCODING]) && + encoding.split(',').include?('chunked') end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/response/follow_redirects.rb new/lib/faraday_middleware/response/follow_redirects.rb --- old/lib/faraday_middleware/response/follow_redirects.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/response/follow_redirects.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,17 +1,9 @@ +# frozen_string_literal: true + require 'faraday' require 'set' module FaradayMiddleware - # Public: Exception thrown when the maximum amount of requests is exceeded. - class RedirectLimitReached < Faraday::Error::ClientError - attr_reader :response - - def initialize(response) - super "too many redirects; last one to: #{response['location']}" - @response = response - end - end - # Public: Follow HTTP 301, 302, 303, 307, and 308 redirects. # # For HTTP 301, 302, and 303, the original GET, POST, PUT, DELETE, or PATCH @@ -32,20 +24,20 @@ # end class FollowRedirects < Faraday::Middleware # HTTP methods for which 30x redirects can be followed - ALLOWED_METHODS = Set.new [:head, :options, :get, :post, :put, :patch, :delete] + ALLOWED_METHODS = Set.new %i[head options get post put patch delete] # HTTP redirect status codes that this middleware implements REDIRECT_CODES = Set.new [301, 302, 303, 307, 308] # Keys in env hash which will get cleared between requests - ENV_TO_CLEAR = Set.new [:status, :response, :response_headers] + ENV_TO_CLEAR = Set.new %i[status response response_headers] # Default value for max redirects followed FOLLOW_LIMIT = 3 # Regex that matches characters that need to be escaped in URLs, sans # the "%" character which we assume already represents an escaped sequence. - URI_UNSAFE = /[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]%]/ + URI_UNSAFE = %r{[^\-_.!~*'()a-zA-Z\d;/?:@&=+$,\[\]%]}.freeze - AUTH_HEADER = 'Authorization'.freeze + AUTH_HEADER = 'Authorization' # Public: Initialize the middleware. # @@ -54,7 +46,7 @@ # :standards_compliant - A Boolean indicating whether to respect # the HTTP spec when following 301/302 # (default: false) - # :callback - A callable that will be called on redirects + # :callback - A callable used on redirects # with the old and new envs # :cookies - An Array of Strings (e.g. # ['cookie1', 'cookie2']) to choose @@ -78,7 +70,7 @@ private def convert_to_get?(response) - ![:head, :options].include?(response.env[:method]) && + !%i[head options].include?(response.env[:method]) && @convert_to_get.include?(response.status) end @@ -89,8 +81,9 @@ response.on_complete do |response_env| if follow_redirect?(response_env, response) raise RedirectLimitReached, response if follows.zero? + new_request_env = update_env(response_env.dup, request_body, response) - callback.call(response_env, new_request_env) if callback + callback&.call(response_env, new_request_env) response = perform_with_redirection(new_request_env, follows - 1) end end @@ -102,6 +95,8 @@ redirect_to_url = safe_escape(response['location'] || '') env[:url] += redirect_to_url + ENV_TO_CLEAR.each { |key| env.delete key } + if convert_to_get?(response) env[:method] = :get env[:body] = nil @@ -111,14 +106,12 @@ clear_authorization_header(env, redirect_from_url, redirect_to_url) - ENV_TO_CLEAR.each {|key| env.delete key } - env end def follow_redirect?(env, response) - ALLOWED_METHODS.include? env[:method] and - REDIRECT_CODES.include? response.status + ALLOWED_METHODS.include?(env[:method]) && + REDIRECT_CODES.include?(response.status) end def follow_limit @@ -139,9 +132,9 @@ # risk double-escaping. def safe_escape(uri) uri = uri.split('#')[0] # we want to remove the fragment if present - uri.to_s.gsub(URI_UNSAFE) { |match| + uri.to_s.gsub(URI_UNSAFE) do |match| '%' + match.unpack('H2' * match.bytesize).join('%').upcase - } + end end def clear_authorization_header(env, from_url, to_url) @@ -157,7 +150,8 @@ from_uri = URI.parse(from_url) to_uri = URI.parse(to_url) - [from_uri.scheme, from_uri.host, from_uri.port] == [to_uri.scheme, to_uri.host, to_uri.port] + [from_uri.scheme, from_uri.host, from_uri.port] == + [to_uri.scheme, to_uri.host, to_uri.port] end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/response/mashify.rb new/lib/faraday_middleware/response/mashify.rb --- old/lib/faraday_middleware/response/mashify.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/response/mashify.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday' module FaradayMiddleware diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/response/parse_dates.rb new/lib/faraday_middleware/response/parse_dates.rb --- old/lib/faraday_middleware/response/parse_dates.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/response/parse_dates.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,10 +1,13 @@ -require "time" -require "faraday" +# frozen_string_literal: true + +require 'time' +require 'faraday' module FaradayMiddleware # Parse dates from response body class ParseDates < ::Faraday::Response::Middleware - ISO_DATE_FORMAT = /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|((\+|-)\d{2}:?\d{2}))\Z/m + ISO_DATE_FORMAT = /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)? + (Z|((\+|-)\d{2}:?\d{2}))\Z/xm.freeze def initialize(app, options = {}) @regexp = options[:match] || ISO_DATE_FORMAT diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/response/parse_json.rb new/lib/faraday_middleware/response/parse_json.rb --- old/lib/faraday_middleware/response/parse_json.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/response/parse_json.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday_middleware/response_middleware' module FaradayMiddleware @@ -18,7 +20,7 @@ # This is to fix responses from certain API providers that insist on serving # JSON with wrong MIME-types such as "text/javascript". class MimeTypeFix < ResponseMiddleware - MIME_TYPE = 'application/json'.freeze + MIME_TYPE = 'application/json' def process_response(env) old_type = env[:response_headers][CONTENT_TYPE].to_s @@ -27,19 +29,17 @@ env[:response_headers][CONTENT_TYPE] = new_type end - BRACKETS = %w- [ { - - WHITESPACE = [ " ", "\n", "\r", "\t" ] + BRACKETS = %w-[ {-.freeze + WHITESPACE = [' ', "\n", "\r", "\t"].freeze def parse_response?(env) - super and BRACKETS.include? first_char(env[:body]) + super && BRACKETS.include?(first_char(env[:body])) end def first_char(body) idx = -1 - begin - char = body[idx += 1] - char = char.chr if char - end while char and WHITESPACE.include? char + char = body[idx += 1] + char = body[idx += 1] while char && WHITESPACE.include?(char) char end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/response/parse_marshal.rb new/lib/faraday_middleware/response/parse_marshal.rb --- old/lib/faraday_middleware/response/parse_marshal.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/response/parse_marshal.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday_middleware/response_middleware' module FaradayMiddleware diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/response/parse_xml.rb new/lib/faraday_middleware/response/parse_xml.rb --- old/lib/faraday_middleware/response/parse_xml.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/response/parse_xml.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday_middleware/response_middleware' module FaradayMiddleware diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/response/parse_yaml.rb new/lib/faraday_middleware/response/parse_yaml.rb --- old/lib/faraday_middleware/response/parse_yaml.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/response/parse_yaml.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,13 +1,16 @@ +# frozen_string_literal: true + require 'faraday_middleware/response_middleware' module FaradayMiddleware # Public: Parse response bodies as YAML. # - # Warning: This is not backwards compatible with versions of this middleware prior to - # faraday_middleware v0.12 - prior to this version, we used YAML.load rather than - # YAMl.safe_load, which exposes serious remote code execution risks - see - # https://github.com/ruby/psych/issues/119 for details. If you're sure you can trust - # YAML you're passing, you can set up an unsafe version of this middleware as follows: + # Warning: This is not backwards compatible with versions of this middleware + # prior to faraday_middleware v0.12 - prior to this version, we used + # YAML.load rather than YAMl.safe_load, which exposes serious remote code + # execution risks - see https://github.com/ruby/psych/issues/119 for details. + # If you're sure you can trust YAML you're passing, you can set up an unsafe + # version of this middleware like this: # # class UnsafelyParseYaml < FaradayMiddleware::ResponseMiddleware # dependency do @@ -27,11 +30,7 @@ dependency 'safe_yaml/load' define_parser do |body, parser_options| - if SafeYAML::YAML_ENGINE == 'psych' - SafeYAML.load(body, nil, parser_options || {}) - else - SafeYAML.load(body, parser_options || {}) - end + SafeYAML.load(body, nil, parser_options || {}) end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/response/rashify.rb new/lib/faraday_middleware/response/rashify.rb --- old/lib/faraday_middleware/response/rashify.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/response/rashify.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday_middleware/response/mashify' module FaradayMiddleware diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/response_middleware.rb new/lib/faraday_middleware/response_middleware.rb --- old/lib/faraday_middleware/response_middleware.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/response_middleware.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,9 +1,12 @@ +# frozen_string_literal: true + require 'faraday' +# Main FaradayMiddleware module. module FaradayMiddleware # Internal: The base class for middleware that parses responses. class ResponseMiddleware < Faraday::Middleware - CONTENT_TYPE = 'Content-Type'.freeze + CONTENT_TYPE = 'Content-Type' class << self attr_accessor :parser @@ -11,13 +14,15 @@ # Store a Proc that receives the body and returns the parsed result. def self.define_parser(parser = nil, &block) - @parser = parser || block || raise(ArgumentError, 'Define parser with a block') + @parser = parser || + block || + raise(ArgumentError, 'Define parser with a block') end def self.inherited(subclass) super - subclass.load_error = self.load_error if subclass.respond_to? :load_error= - subclass.parser = self.parser + subclass.load_error = load_error if subclass.respond_to? :load_error= + subclass.parser = parser end def initialize(app = nil, options = {}) @@ -29,7 +34,7 @@ def call(environment) @app.call(environment).on_complete do |env| - if process_response_type?(response_type(env)) and parse_response?(env) + if process_response_type?(response_type(env)) && parse_response?(env) process_response(env) end end @@ -38,8 +43,8 @@ def process_response(env) env[:raw_body] = env[:body] if preserve_raw?(env) env[:body] = parse(env[:body]) - rescue Faraday::Error::ParsingError => err - raise Faraday::Error::ParsingError.new(err, env[:response]) + rescue Faraday::ParsingError => e + raise Faraday::ParsingError.new(e, env[:response]) end # Parse the response body. @@ -49,9 +54,11 @@ if self.class.parser begin self.class.parser.call(body, @parser_options) - rescue StandardError, SyntaxError => err - raise err if err.is_a? SyntaxError and err.class.name != 'Psych::SyntaxError' - raise Faraday::Error::ParsingError, err + rescue StandardError, SyntaxError => e + raise e if e.is_a?(SyntaxError) && + e.class.name != 'Psych::SyntaxError' + + raise Faraday::ParsingError, e end else body @@ -65,9 +72,9 @@ end def process_response_type?(type) - @content_types.empty? or @content_types.any? { |pattern| + @content_types.empty? || @content_types.any? do |pattern| pattern.is_a?(Regexp) ? type =~ pattern : type == pattern - } + end end def parse_response?(env) @@ -84,17 +91,18 @@ attr_accessor :preserve_raw def to_hash - super.update(:preserve_raw => preserve_raw) + super.update(preserve_raw: preserve_raw) end def each return to_enum(:each) unless block_given? + super yield :preserve_raw, preserve_raw end def fetch(key, *args) - if :preserve_raw == key + if key == :preserve_raw value = __send__(key) value.nil? ? args.fetch(0) : value else @@ -105,9 +113,9 @@ if defined?(Faraday::RequestOptions) begin - Faraday::RequestOptions.from(:preserve_raw => true) + Faraday::RequestOptions.from(preserve_raw: true) rescue NoMethodError - Faraday::RequestOptions.send(:include, OptionsExtension) + Faraday::RequestOptions.include OptionsExtension end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware/version.rb new/lib/faraday_middleware/version.rb --- old/lib/faraday_middleware/version.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware/version.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,3 +1,6 @@ +# frozen_string_literal: true + +# Main FaradayMiddleware module. module FaradayMiddleware - VERSION = '0.14.0' unless defined?(FaradayMiddleware::VERSION) + VERSION = '1.0.0' unless defined?(FaradayMiddleware::VERSION) end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/faraday_middleware.rb new/lib/faraday_middleware.rb --- old/lib/faraday_middleware.rb 2020-01-19 11:31:37.000000000 +0100 +++ new/lib/faraday_middleware.rb 2020-03-29 12:15:52.000000000 +0200 @@ -1,5 +1,8 @@ +# frozen_string_literal: true + require 'faraday' +# Main FaradayMiddleware module. module FaradayMiddleware autoload :OAuth, 'faraday_middleware/request/oauth' autoload :OAuth2, 'faraday_middleware/request/oauth2' @@ -15,33 +18,34 @@ autoload :Caching, 'faraday_middleware/response/caching' autoload :Chunked, 'faraday_middleware/response/chunked' autoload :RackCompatible, 'faraday_middleware/rack_compatible' + autoload :RedirectLimitReached, 'faraday_middleware/redirect_limit_reached' autoload :FollowRedirects, 'faraday_middleware/response/follow_redirects' autoload :Instrumentation, 'faraday_middleware/instrumentation' autoload :Gzip, 'faraday_middleware/gzip' if Faraday::Middleware.respond_to? :register_middleware Faraday::Request.register_middleware \ - :oauth => lambda { OAuth }, - :oauth2 => lambda { OAuth2 }, - :json => lambda { EncodeJson }, - :method_override => lambda { MethodOverride } + oauth: -> { OAuth }, + oauth2: -> { OAuth2 }, + json: -> { EncodeJson }, + method_override: -> { MethodOverride } Faraday::Response.register_middleware \ - :mashify => lambda { Mashify }, - :rashify => lambda { Rashify }, - :json => lambda { ParseJson }, - :json_fix => lambda { ParseJson::MimeTypeFix }, - :xml => lambda { ParseXml }, - :marshal => lambda { ParseMarshal }, - :yaml => lambda { ParseYaml }, - :dates => lambda { ParseDates }, - :caching => lambda { Caching }, - :follow_redirects => lambda { FollowRedirects }, - :chunked => lambda { Chunked } + mashify: -> { Mashify }, + rashify: -> { Rashify }, + json: -> { ParseJson }, + json_fix: -> { ParseJson::MimeTypeFix }, + xml: -> { ParseXml }, + marshal: -> { ParseMarshal }, + yaml: -> { ParseYaml }, + dates: -> { ParseDates }, + caching: -> { Caching }, + follow_redirects: -> { FollowRedirects }, + chunked: -> { Chunked } Faraday::Middleware.register_middleware \ - :instrumentation => lambda { Instrumentation }, - :gzip => lambda { Gzip } + instrumentation: -> { Instrumentation }, + gzip: -> { Gzip } end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 2020-01-19 11:31:37.000000000 +0100 +++ new/metadata 2020-03-29 12:15:52.000000000 +0200 @@ -1,7 +1,7 @@ --- !ruby/object:Gem::Specification name: faraday_middleware version: !ruby/object:Gem::Version - version: 0.14.0 + version: 1.0.0 platform: ruby authors: - Erik Michaels-Ober @@ -9,26 +9,20 @@ autorequire: bindir: bin cert_chain: [] -date: 2020-01-19 00:00:00.000000000 Z +date: 2020-03-29 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: faraday requirement: !ruby/object:Gem::Requirement requirements: - - - ">=" - - !ruby/object:Gem::Version - version: 0.7.4 - - - "<" + - - "~>" - !ruby/object:Gem::Version version: '1.0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - - ">=" - - !ruby/object:Gem::Version - version: 0.7.4 - - - "<" + - - "~>" - !ruby/object:Gem::Version version: '1.0' description: @@ -46,6 +40,7 @@ - lib/faraday_middleware/gzip.rb - lib/faraday_middleware/instrumentation.rb - lib/faraday_middleware/rack_compatible.rb +- lib/faraday_middleware/redirect_limit_reached.rb - lib/faraday_middleware/request/encode_json.rb - lib/faraday_middleware/request/method_override.rb - lib/faraday_middleware/request/oauth.rb @@ -74,7 +69,7 @@ requirements: - - ">=" - !ruby/object:Gem::Version - version: '0' + version: '2.3' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">="