faraday 1.1.0 → 1.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +104 -0
- data/README.md +1 -2
- data/examples/client_spec.rb +34 -2
- data/examples/client_test.rb +41 -2
- data/lib/faraday/adapter/test.rb +59 -43
- data/lib/faraday/adapter.rb +1 -12
- data/lib/faraday/autoload.rb +1 -9
- data/lib/faraday/connection.rb +34 -6
- data/lib/faraday/deprecate.rb +110 -0
- data/lib/faraday/error.rb +12 -6
- data/lib/faraday/methods.rb +6 -0
- data/lib/faraday/middleware.rb +14 -4
- data/lib/faraday/options/proxy_options.rb +4 -0
- data/lib/faraday/request/authorization.rb +14 -7
- data/lib/faraday/request/json.rb +55 -0
- data/lib/faraday/request.rb +10 -12
- data/lib/faraday/response/json.rb +54 -0
- data/lib/faraday/response/logger.rb +2 -4
- data/lib/faraday/response.rb +3 -7
- data/lib/faraday/version.rb +5 -0
- data/lib/faraday.rb +67 -40
- data/spec/faraday/adapter/em_http_spec.rb +39 -37
- data/spec/faraday/adapter/em_synchrony_spec.rb +11 -9
- data/spec/faraday/adapter/test_spec.rb +117 -0
- data/spec/faraday/connection_spec.rb +45 -0
- data/spec/faraday/deprecate_spec.rb +147 -0
- data/spec/faraday/error_spec.rb +15 -0
- data/spec/faraday/middleware_spec.rb +32 -6
- data/spec/faraday/options/proxy_options_spec.rb +7 -0
- data/spec/faraday/request/authorization_spec.rb +8 -0
- data/spec/faraday/request/json_spec.rb +111 -0
- data/spec/faraday/request_spec.rb +1 -1
- data/spec/faraday/response/json_spec.rb +119 -0
- data/spec/faraday/response/raise_error_spec.rb +30 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/shared_examples/adapter.rb +2 -1
- data/spec/support/shared_examples/request_method.rb +36 -8
- metadata +143 -32
- data/lib/faraday/adapter/em_http.rb +0 -286
- data/lib/faraday/adapter/em_http_ssl_patch.rb +0 -62
- data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +0 -69
- data/lib/faraday/adapter/em_synchrony.rb +0 -150
- data/lib/faraday/adapter/excon.rb +0 -124
- data/lib/faraday/adapter/httpclient.rb +0 -152
- data/lib/faraday/adapter/net_http.rb +0 -219
- data/lib/faraday/adapter/net_http_persistent.rb +0 -91
- data/lib/faraday/adapter/patron.rb +0 -132
- data/lib/faraday/adapter/rack.rb +0 -75
- data/lib/faraday/file_part.rb +0 -128
- data/lib/faraday/param_part.rb +0 -53
- data/lib/faraday/request/multipart.rb +0 -106
- data/lib/faraday/request/retry.rb +0 -239
- data/spec/faraday/adapter/net_http_persistent_spec.rb +0 -57
- data/spec/faraday/request/multipart_spec.rb +0 -302
- data/spec/faraday/request/retry_spec.rb +0 -242
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
# @param new_klass [Class] new Klass to use
|
5
|
+
#
|
6
|
+
# @return [Class] A modified version of new_klass that warns on
|
7
|
+
# usage about deprecation.
|
8
|
+
# @see Faraday::Deprecate
|
9
|
+
module DeprecatedClass
|
10
|
+
def self.proxy_class(origclass, ver = '1.0')
|
11
|
+
proxy = Class.new(origclass) do
|
12
|
+
const_set('ORIG_CLASS', origclass)
|
13
|
+
|
14
|
+
class << self
|
15
|
+
extend Faraday::Deprecate
|
16
|
+
|
17
|
+
def ===(other)
|
18
|
+
(superclass == const_get('ORIG_CLASS') && other.is_a?(superclass)) || super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
proxy.singleton_class.send(:deprecate, :new, "#{origclass}.new", ver)
|
23
|
+
proxy.singleton_class.send(:deprecate, :inherited, origclass.name, ver)
|
24
|
+
proxy
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Deprecation using semver instead of date, based on Gem::Deprecate
|
29
|
+
# Provides a single method +deprecate+ to be used to declare when
|
30
|
+
# something is going away.
|
31
|
+
#
|
32
|
+
# class Legacy
|
33
|
+
# def self.klass_method
|
34
|
+
# # ...
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# def instance_method
|
38
|
+
# # ...
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# extend Faraday::Deprecate
|
42
|
+
# deprecate :instance_method, "X.z", '1.0'
|
43
|
+
#
|
44
|
+
# class << self
|
45
|
+
# extend Faraday::Deprecate
|
46
|
+
# deprecate :klass_method, :none, '1.0'
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
module Deprecate
|
50
|
+
def self.skip # :nodoc:
|
51
|
+
@skip ||= begin
|
52
|
+
case ENV['FARADAY_DEPRECATE'].to_s.downcase
|
53
|
+
when '1', 'warn' then :warn
|
54
|
+
else :skip
|
55
|
+
end
|
56
|
+
end
|
57
|
+
@skip == :skip
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.skip=(value) # :nodoc:
|
61
|
+
@skip = value ? :skip : :warn
|
62
|
+
end
|
63
|
+
|
64
|
+
# Temporarily turn off warnings. Intended for tests only.
|
65
|
+
def skip_during
|
66
|
+
original = Faraday::Deprecate.skip
|
67
|
+
Faraday::Deprecate.skip = true
|
68
|
+
yield
|
69
|
+
ensure
|
70
|
+
Faraday::Deprecate.skip = original
|
71
|
+
end
|
72
|
+
|
73
|
+
# Simple deprecation method that deprecates +name+ by wrapping it up
|
74
|
+
# in a dummy method. It warns on each call to the dummy method
|
75
|
+
# telling the user of +repl+ (unless +repl+ is :none) and the
|
76
|
+
# semver that it is planned to go away.
|
77
|
+
# @param name [Symbol] the method symbol to deprecate
|
78
|
+
# @param repl [#to_s, :none] the replacement to use, when `:none` it will
|
79
|
+
# alert the user that no replacement is present.
|
80
|
+
# @param ver [String] the semver the method will be removed.
|
81
|
+
def deprecate(name, repl, ver, custom_message = nil)
|
82
|
+
class_eval do
|
83
|
+
gem_ver = Gem::Version.new(ver)
|
84
|
+
old = "_deprecated_#{name}"
|
85
|
+
alias_method old, name
|
86
|
+
define_method name do |*args, &block|
|
87
|
+
mod = is_a? Module
|
88
|
+
target = mod ? "#{self}." : "#{self.class}#"
|
89
|
+
target_message = if name == :inherited
|
90
|
+
"Inheriting #{self}"
|
91
|
+
else
|
92
|
+
"#{target}#{name}"
|
93
|
+
end
|
94
|
+
|
95
|
+
msg = [
|
96
|
+
"NOTE: #{target_message} is deprecated",
|
97
|
+
repl == :none ? ' with no replacement' : "; use #{repl} instead. ",
|
98
|
+
"It will be removed in or after version #{gem_ver} ",
|
99
|
+
custom_message,
|
100
|
+
"\n#{target}#{name} called from #{Gem.location_of_caller.join(':')}"
|
101
|
+
]
|
102
|
+
warn "#{msg.join}." unless Faraday::Deprecate.skip
|
103
|
+
send old, *args, &block
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
module_function :deprecate, :skip_during
|
109
|
+
end
|
110
|
+
end
|
data/lib/faraday/error.rb
CHANGED
@@ -28,6 +28,18 @@ module Faraday
|
|
28
28
|
%(#<#{self.class}#{inner}>)
|
29
29
|
end
|
30
30
|
|
31
|
+
def response_status
|
32
|
+
@response[:status] if @response
|
33
|
+
end
|
34
|
+
|
35
|
+
def response_headers
|
36
|
+
@response[:headers] if @response
|
37
|
+
end
|
38
|
+
|
39
|
+
def response_body
|
40
|
+
@response[:body] if @response
|
41
|
+
end
|
42
|
+
|
31
43
|
protected
|
32
44
|
|
33
45
|
# Pulls out potential parent exception and response hash, storing them in
|
@@ -131,10 +143,4 @@ module Faraday
|
|
131
143
|
# Raised by FaradayMiddleware::ResponseMiddleware
|
132
144
|
class ParsingError < Error
|
133
145
|
end
|
134
|
-
|
135
|
-
# Exception used to control the Retry middleware.
|
136
|
-
#
|
137
|
-
# @see Faraday::Request::Retry
|
138
|
-
class RetriableResponse < Error
|
139
|
-
end
|
140
146
|
end
|
data/lib/faraday/middleware.rb
CHANGED
@@ -6,15 +6,25 @@ module Faraday
|
|
6
6
|
extend MiddlewareRegistry
|
7
7
|
extend DependencyLoader
|
8
8
|
|
9
|
-
|
9
|
+
attr_reader :app, :options
|
10
|
+
|
11
|
+
def initialize(app = nil, options = {})
|
10
12
|
@app = app
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
on_request(env) if respond_to?(:on_request)
|
18
|
+
app.call(env).on_complete do |environment|
|
19
|
+
on_complete(environment) if respond_to?(:on_complete)
|
20
|
+
end
|
11
21
|
end
|
12
22
|
|
13
23
|
def close
|
14
|
-
if
|
15
|
-
|
24
|
+
if app.respond_to?(:close)
|
25
|
+
app.close
|
16
26
|
else
|
17
|
-
warn "#{
|
27
|
+
warn "#{app} does not implement \#close!"
|
18
28
|
end
|
19
29
|
end
|
20
30
|
end
|
@@ -11,6 +11,9 @@ module Faraday
|
|
11
11
|
def self.from(value)
|
12
12
|
case value
|
13
13
|
when String
|
14
|
+
# URIs without a scheme should default to http (like 'example:123').
|
15
|
+
# This fixes #1282 and prevents a silent failure in some adapters.
|
16
|
+
value = "http://#{value}" unless value.include?('://')
|
14
17
|
value = { uri: Utils.URI(value) }
|
15
18
|
when URI
|
16
19
|
value = { uri: value }
|
@@ -19,6 +22,7 @@ module Faraday
|
|
19
22
|
value[:uri] = Utils.URI(uri)
|
20
23
|
end
|
21
24
|
end
|
25
|
+
|
22
26
|
super(value)
|
23
27
|
end
|
24
28
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'base64'
|
4
|
+
|
3
5
|
module Faraday
|
4
6
|
class Request
|
5
7
|
# Request middleware for the Authorization HTTP header
|
@@ -13,7 +15,8 @@ module Faraday
|
|
13
15
|
# @return [String] a header value
|
14
16
|
def self.header(type, token)
|
15
17
|
case token
|
16
|
-
when String, Symbol
|
18
|
+
when String, Symbol, Proc
|
19
|
+
token = token.call if token.is_a?(Proc)
|
17
20
|
"#{type} #{token}"
|
18
21
|
when Hash
|
19
22
|
build_hash(type.to_s, token)
|
@@ -32,6 +35,7 @@ module Faraday
|
|
32
35
|
comma = ', '
|
33
36
|
values = []
|
34
37
|
hash.each do |key, value|
|
38
|
+
value = value.call if value.is_a?(Proc)
|
35
39
|
values << "#{key}=#{value.to_s.inspect}"
|
36
40
|
end
|
37
41
|
"#{type} #{values * comma}"
|
@@ -39,16 +43,19 @@ module Faraday
|
|
39
43
|
|
40
44
|
# @param app [#call]
|
41
45
|
# @param type [String, Symbol] Type of Authorization
|
42
|
-
# @param
|
43
|
-
|
44
|
-
|
46
|
+
# @param param [String, Symbol, Hash, Proc] parameter to build the Authorization header.
|
47
|
+
# This value can be a proc, in which case it will be invoked on each request.
|
48
|
+
def initialize(app, type, param)
|
49
|
+
@type = type
|
50
|
+
@param = param
|
45
51
|
super(app)
|
46
52
|
end
|
47
53
|
|
48
54
|
# @param env [Faraday::Env]
|
49
|
-
def
|
50
|
-
|
51
|
-
|
55
|
+
def on_request(env)
|
56
|
+
return if env.request_headers[KEY]
|
57
|
+
|
58
|
+
env.request_headers[KEY] = self.class.header(@type, @param)
|
52
59
|
end
|
53
60
|
end
|
54
61
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Faraday
|
6
|
+
class Request
|
7
|
+
# Request middleware that encodes the body as JSON.
|
8
|
+
#
|
9
|
+
# Processes only requests with matching Content-type or those without a type.
|
10
|
+
# If a request doesn't have a type but has a body, it sets the Content-type
|
11
|
+
# to JSON MIME-type.
|
12
|
+
#
|
13
|
+
# Doesn't try to encode bodies that already are in string form.
|
14
|
+
class Json < Middleware
|
15
|
+
MIME_TYPE = 'application/json'
|
16
|
+
MIME_TYPE_REGEX = %r{^application/(vnd\..+\+)?json$}.freeze
|
17
|
+
|
18
|
+
def on_request(env)
|
19
|
+
match_content_type(env) do |data|
|
20
|
+
env[:body] = encode(data)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def encode(data)
|
27
|
+
::JSON.generate(data)
|
28
|
+
end
|
29
|
+
|
30
|
+
def match_content_type(env)
|
31
|
+
return unless process_request?(env)
|
32
|
+
|
33
|
+
env[:request_headers][CONTENT_TYPE] ||= MIME_TYPE
|
34
|
+
yield env[:body] unless env[:body].respond_to?(:to_str)
|
35
|
+
end
|
36
|
+
|
37
|
+
def process_request?(env)
|
38
|
+
type = request_type(env)
|
39
|
+
body?(env) && (type.empty? || type.match?(MIME_TYPE_REGEX))
|
40
|
+
end
|
41
|
+
|
42
|
+
def body?(env)
|
43
|
+
(body = env[:body]) && !(body.respond_to?(:to_str) && body.empty?)
|
44
|
+
end
|
45
|
+
|
46
|
+
def request_type(env)
|
47
|
+
type = env[:request_headers][CONTENT_TYPE].to_s
|
48
|
+
type = type.split(';', 2).first if type.index(';')
|
49
|
+
type
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
Faraday::Request.register_middleware(json: Faraday::Request::Json)
|
data/lib/faraday/request.rb
CHANGED
@@ -35,8 +35,6 @@ module Faraday
|
|
35
35
|
|
36
36
|
register_middleware File.expand_path('request', __dir__),
|
37
37
|
url_encoded: [:UrlEncoded, 'url_encoded'],
|
38
|
-
multipart: [:Multipart, 'multipart'],
|
39
|
-
retry: [:Retry, 'retry'],
|
40
38
|
authorization: [:Authorization, 'authorization'],
|
41
39
|
basic_auth: [
|
42
40
|
:BasicAuthentication,
|
@@ -46,7 +44,8 @@ module Faraday
|
|
46
44
|
:TokenAuthentication,
|
47
45
|
'token_authentication'
|
48
46
|
],
|
49
|
-
instrumentation: [:Instrumentation, 'instrumentation']
|
47
|
+
instrumentation: [:Instrumentation, 'instrumentation'],
|
48
|
+
json: [:Json, 'json']
|
50
49
|
|
51
50
|
# @param request_method [String]
|
52
51
|
# @yield [request] for block customization, if block given
|
@@ -59,13 +58,12 @@ module Faraday
|
|
59
58
|
end
|
60
59
|
|
61
60
|
def method
|
62
|
-
warn <<~TEXT
|
63
|
-
WARNING: `Faraday::Request##{__method__}` is deprecated; use `#http_method` instead. It will be removed in or after version 2.0.
|
64
|
-
`Faraday::Request##{__method__}` called from #{caller_locations(1..1).first}
|
65
|
-
TEXT
|
66
61
|
http_method
|
67
62
|
end
|
68
63
|
|
64
|
+
extend Faraday::Deprecate
|
65
|
+
deprecate :method, :http_method, '2.0'
|
66
|
+
|
69
67
|
# Replace params, preserving the existing hash type.
|
70
68
|
#
|
71
69
|
# @param hash [Hash] new params
|
@@ -140,11 +138,11 @@ module Faraday
|
|
140
138
|
# @param serialised [Hash] the serialised object.
|
141
139
|
def marshal_load(serialised)
|
142
140
|
self.http_method = serialised[:http_method]
|
143
|
-
self.body
|
144
|
-
self.headers
|
145
|
-
self.path
|
146
|
-
self.params
|
147
|
-
self.options
|
141
|
+
self.body = serialised[:body]
|
142
|
+
self.headers = serialised[:headers]
|
143
|
+
self.path = serialised[:path]
|
144
|
+
self.params = serialised[:params]
|
145
|
+
self.options = serialised[:options]
|
148
146
|
end
|
149
147
|
|
150
148
|
# @return [Env] the Env for this Request
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Faraday
|
6
|
+
class Response
|
7
|
+
# Parse response bodies as JSON.
|
8
|
+
class Json < Middleware
|
9
|
+
def initialize(app = nil, options = {})
|
10
|
+
super(app)
|
11
|
+
@parser_options = options[:parser_options]
|
12
|
+
@content_types = Array(options[:content_type] || /\bjson$/)
|
13
|
+
@preserve_raw = options[:preserve_raw]
|
14
|
+
end
|
15
|
+
|
16
|
+
def on_complete(env)
|
17
|
+
process_response(env) if parse_response?(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def process_response(env)
|
23
|
+
env[:raw_body] = env[:body] if @preserve_raw
|
24
|
+
env[:body] = parse(env[:body])
|
25
|
+
rescue StandardError, SyntaxError => e
|
26
|
+
raise Faraday::ParsingError.new(e, env[:response])
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse(body)
|
30
|
+
::JSON.parse(body, @parser_options || {}) unless body.strip.empty?
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse_response?(env)
|
34
|
+
process_response_type?(env) &&
|
35
|
+
env[:body].respond_to?(:to_str)
|
36
|
+
end
|
37
|
+
|
38
|
+
def process_response_type?(env)
|
39
|
+
type = response_type(env)
|
40
|
+
@content_types.empty? || @content_types.any? do |pattern|
|
41
|
+
pattern.is_a?(Regexp) ? type.match?(pattern) : type == pattern
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def response_type(env)
|
46
|
+
type = env[:response_headers][CONTENT_TYPE].to_s
|
47
|
+
type = type.split(';', 2).first if type.index(';')
|
48
|
+
type
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
Faraday::Response.register_middleware(json: Faraday::Response::Json)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'forwardable'
|
4
|
+
require 'logger'
|
4
5
|
require 'faraday/logging/formatter'
|
5
6
|
|
6
7
|
module Faraday
|
@@ -11,10 +12,7 @@ module Faraday
|
|
11
12
|
class Logger < Middleware
|
12
13
|
def initialize(app, logger = nil, options = {})
|
13
14
|
super(app)
|
14
|
-
logger ||=
|
15
|
-
require 'logger'
|
16
|
-
::Logger.new($stdout)
|
17
|
-
end
|
15
|
+
logger ||= ::Logger.new($stdout)
|
18
16
|
formatter_class = options.delete(:formatter) || Logging::Formatter
|
19
17
|
@formatter = formatter_class.new(logger: logger, options: options)
|
20
18
|
yield @formatter if block_given?
|
data/lib/faraday/response.rb
CHANGED
@@ -7,12 +7,6 @@ module Faraday
|
|
7
7
|
class Response
|
8
8
|
# Used for simple response middleware.
|
9
9
|
class Middleware < Faraday::Middleware
|
10
|
-
def call(env)
|
11
|
-
@app.call(env).on_complete do |environment|
|
12
|
-
on_complete(environment)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
10
|
# Override this to modify the environment after the response has finished.
|
17
11
|
# Calls the `parse` method if defined
|
18
12
|
# `parse` method can be defined as private, public and protected
|
@@ -28,7 +22,8 @@ module Faraday
|
|
28
22
|
|
29
23
|
register_middleware File.expand_path('response', __dir__),
|
30
24
|
raise_error: [:RaiseError, 'raise_error'],
|
31
|
-
logger: [:Logger, 'logger']
|
25
|
+
logger: [:Logger, 'logger'],
|
26
|
+
json: [:Json, 'json']
|
32
27
|
|
33
28
|
def initialize(env = nil)
|
34
29
|
@env = Env.from(env) if env
|
@@ -48,6 +43,7 @@ module Faraday
|
|
48
43
|
def headers
|
49
44
|
finished? ? env.response_headers : {}
|
50
45
|
end
|
46
|
+
|
51
47
|
def_delegator :headers, :[]
|
52
48
|
|
53
49
|
def body
|
data/lib/faraday.rb
CHANGED
@@ -1,11 +1,49 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'cgi'
|
4
|
+
require 'date'
|
4
5
|
require 'set'
|
5
6
|
require 'forwardable'
|
6
7
|
require 'faraday/middleware_registry'
|
7
8
|
require 'faraday/dependency_loader'
|
8
9
|
|
10
|
+
unless defined?(::Faraday::Timer)
|
11
|
+
require 'timeout'
|
12
|
+
::Faraday::Timer = Timeout
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'faraday/version'
|
16
|
+
require 'faraday/methods'
|
17
|
+
require 'faraday/utils'
|
18
|
+
require 'faraday/options'
|
19
|
+
require 'faraday/connection'
|
20
|
+
require 'faraday/rack_builder'
|
21
|
+
require 'faraday/parameters'
|
22
|
+
require 'faraday/middleware'
|
23
|
+
require 'faraday/adapter'
|
24
|
+
require 'faraday/request'
|
25
|
+
require 'faraday/response'
|
26
|
+
require 'faraday/error'
|
27
|
+
require 'faraday/request/url_encoded' # needed by multipart
|
28
|
+
|
29
|
+
# External Middleware gems and their aliases
|
30
|
+
require 'faraday/multipart'
|
31
|
+
require 'faraday/retry'
|
32
|
+
Faraday::Request::Multipart = Faraday::Multipart::Middleware
|
33
|
+
Faraday::Request::Retry = Faraday::Retry::Middleware
|
34
|
+
|
35
|
+
# External Adapters gems
|
36
|
+
unless defined?(JRUBY_VERSION)
|
37
|
+
require 'faraday/em_http'
|
38
|
+
require 'faraday/em_synchrony'
|
39
|
+
end
|
40
|
+
require 'faraday/excon'
|
41
|
+
require 'faraday/httpclient'
|
42
|
+
require 'faraday/net_http'
|
43
|
+
require 'faraday/net_http_persistent'
|
44
|
+
require 'faraday/patron'
|
45
|
+
require 'faraday/rack'
|
46
|
+
|
9
47
|
# This is the main namespace for Faraday.
|
10
48
|
#
|
11
49
|
# It provides methods to create {Connection} objects, and HTTP-related
|
@@ -19,9 +57,7 @@ require 'faraday/dependency_loader'
|
|
19
57
|
# conn.get '/'
|
20
58
|
#
|
21
59
|
module Faraday
|
22
|
-
|
23
|
-
METHODS_WITH_QUERY = %w[get head delete trace].freeze
|
24
|
-
METHODS_WITH_BODY = %w[post put patch].freeze
|
60
|
+
CONTENT_TYPE = 'Content-Type'
|
25
61
|
|
26
62
|
class << self
|
27
63
|
# The root path that Faraday is being loaded from.
|
@@ -107,6 +143,34 @@ module Faraday
|
|
107
143
|
default_connection.respond_to?(symbol, include_private) || super
|
108
144
|
end
|
109
145
|
|
146
|
+
# @overload default_connection
|
147
|
+
# Gets the default connection used for simple scripts.
|
148
|
+
# @return [Faraday::Connection] a connection configured with
|
149
|
+
# the default_adapter.
|
150
|
+
# @overload default_connection=(connection)
|
151
|
+
# @param connection [Faraday::Connection]
|
152
|
+
# Sets the default {Faraday::Connection} for simple scripts that
|
153
|
+
# access the Faraday constant directly, such as
|
154
|
+
# <code>Faraday.get "https://faraday.com"</code>.
|
155
|
+
def default_connection
|
156
|
+
@default_connection ||= Connection.new(default_connection_options)
|
157
|
+
end
|
158
|
+
|
159
|
+
# Gets the default connection options used when calling {Faraday#new}.
|
160
|
+
#
|
161
|
+
# @return [Faraday::ConnectionOptions]
|
162
|
+
def default_connection_options
|
163
|
+
@default_connection_options ||= ConnectionOptions.new
|
164
|
+
end
|
165
|
+
|
166
|
+
# Sets the default options used when calling {Faraday#new}.
|
167
|
+
#
|
168
|
+
# @param options [Hash, Faraday::ConnectionOptions]
|
169
|
+
def default_connection_options=(options)
|
170
|
+
@default_connection = nil
|
171
|
+
@default_connection_options = ConnectionOptions.from(options)
|
172
|
+
end
|
173
|
+
|
110
174
|
private
|
111
175
|
|
112
176
|
# Internal: Proxies method calls on the Faraday constant to
|
@@ -125,42 +189,5 @@ module Faraday
|
|
125
189
|
self.lib_path = File.expand_path 'faraday', __dir__
|
126
190
|
self.default_adapter = :net_http
|
127
191
|
|
128
|
-
# @overload default_connection
|
129
|
-
# Gets the default connection used for simple scripts.
|
130
|
-
# @return [Faraday::Connection] a connection configured with
|
131
|
-
# the default_adapter.
|
132
|
-
# @overload default_connection=(connection)
|
133
|
-
# @param connection [Faraday::Connection]
|
134
|
-
# Sets the default {Faraday::Connection} for simple scripts that
|
135
|
-
# access the Faraday constant directly, such as
|
136
|
-
# <code>Faraday.get "https://faraday.com"</code>.
|
137
|
-
def self.default_connection
|
138
|
-
@default_connection ||= Connection.new(default_connection_options)
|
139
|
-
end
|
140
|
-
|
141
|
-
# Gets the default connection options used when calling {Faraday#new}.
|
142
|
-
#
|
143
|
-
# @return [Faraday::ConnectionOptions]
|
144
|
-
def self.default_connection_options
|
145
|
-
@default_connection_options ||= ConnectionOptions.new
|
146
|
-
end
|
147
|
-
|
148
|
-
# Sets the default options used when calling {Faraday#new}.
|
149
|
-
#
|
150
|
-
# @param options [Hash, Faraday::ConnectionOptions]
|
151
|
-
def self.default_connection_options=(options)
|
152
|
-
@default_connection = nil
|
153
|
-
@default_connection_options = ConnectionOptions.from(options)
|
154
|
-
end
|
155
|
-
|
156
|
-
unless defined?(::Faraday::Timer)
|
157
|
-
require 'timeout'
|
158
|
-
Timer = Timeout
|
159
|
-
end
|
160
|
-
|
161
|
-
require_libs 'utils', 'options', 'connection', 'rack_builder', 'parameters',
|
162
|
-
'middleware', 'adapter', 'request', 'response', 'error',
|
163
|
-
'file_part', 'param_part'
|
164
|
-
|
165
192
|
require_lib 'autoload' unless ENV['FARADAY_NO_AUTOLOAD']
|
166
193
|
end
|