faraday 0.15.4 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +1 -1
- data/README.md +18 -344
- data/lib/faraday.rb +93 -175
- data/lib/faraday/adapter.rb +36 -22
- data/lib/faraday/adapter/em_http.rb +142 -99
- data/lib/faraday/adapter/em_http_ssl_patch.rb +23 -17
- data/lib/faraday/adapter/em_synchrony.rb +104 -60
- data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +18 -15
- data/lib/faraday/adapter/excon.rb +100 -55
- data/lib/faraday/adapter/httpclient.rb +61 -39
- data/lib/faraday/adapter/net_http.rb +104 -51
- data/lib/faraday/adapter/net_http_persistent.rb +48 -27
- data/lib/faraday/adapter/patron.rb +54 -35
- data/lib/faraday/adapter/rack.rb +28 -12
- data/lib/faraday/adapter/test.rb +86 -53
- data/lib/faraday/adapter/typhoeus.rb +4 -1
- data/lib/faraday/adapter_registry.rb +28 -0
- data/lib/faraday/autoload.rb +47 -36
- data/lib/faraday/connection.rb +321 -179
- data/lib/faraday/dependency_loader.rb +37 -0
- data/lib/faraday/encoders/flat_params_encoder.rb +94 -0
- data/lib/faraday/encoders/nested_params_encoder.rb +171 -0
- data/lib/faraday/error.rb +67 -33
- data/lib/faraday/file_part.rb +128 -0
- data/lib/faraday/logging/formatter.rb +92 -0
- data/lib/faraday/middleware.rb +4 -28
- data/lib/faraday/middleware_registry.rb +129 -0
- data/lib/faraday/options.rb +35 -186
- data/lib/faraday/options/connection_options.rb +22 -0
- data/lib/faraday/options/env.rb +181 -0
- data/lib/faraday/options/proxy_options.rb +28 -0
- data/lib/faraday/options/request_options.rb +21 -0
- data/lib/faraday/options/ssl_options.rb +59 -0
- data/lib/faraday/param_part.rb +53 -0
- data/lib/faraday/parameters.rb +4 -197
- data/lib/faraday/rack_builder.rb +67 -56
- data/lib/faraday/request.rb +68 -36
- data/lib/faraday/request/authorization.rb +42 -30
- data/lib/faraday/request/basic_authentication.rb +14 -7
- data/lib/faraday/request/instrumentation.rb +45 -27
- data/lib/faraday/request/multipart.rb +79 -48
- data/lib/faraday/request/retry.rb +198 -169
- data/lib/faraday/request/token_authentication.rb +15 -10
- data/lib/faraday/request/url_encoded.rb +41 -23
- data/lib/faraday/response.rb +23 -16
- data/lib/faraday/response/logger.rb +22 -69
- data/lib/faraday/response/raise_error.rb +36 -14
- data/lib/faraday/utils.rb +28 -245
- data/lib/faraday/utils/headers.rb +139 -0
- data/lib/faraday/utils/params_hash.rb +61 -0
- data/spec/external_adapters/faraday_specs_setup.rb +14 -0
- metadata +21 -5
- data/lib/faraday/upload_io.rb +0 -67
@@ -0,0 +1,139 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
module Utils
|
5
|
+
# A case-insensitive Hash that preserves the original case of a header
|
6
|
+
# when set.
|
7
|
+
#
|
8
|
+
# Adapted from Rack::Utils::HeaderHash
|
9
|
+
class Headers < ::Hash
|
10
|
+
def self.from(value)
|
11
|
+
new(value)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.allocate
|
15
|
+
new_self = super
|
16
|
+
new_self.initialize_names
|
17
|
+
new_self
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(hash = nil)
|
21
|
+
super()
|
22
|
+
@names = {}
|
23
|
+
update(hash || {})
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize_names
|
27
|
+
@names = {}
|
28
|
+
end
|
29
|
+
|
30
|
+
# on dup/clone, we need to duplicate @names hash
|
31
|
+
def initialize_copy(other)
|
32
|
+
super
|
33
|
+
@names = other.names.dup
|
34
|
+
end
|
35
|
+
|
36
|
+
# need to synchronize concurrent writes to the shared KeyMap
|
37
|
+
keymap_mutex = Mutex.new
|
38
|
+
|
39
|
+
# symbol -> string mapper + cache
|
40
|
+
KeyMap = Hash.new do |map, key|
|
41
|
+
value = if key.respond_to?(:to_str)
|
42
|
+
key
|
43
|
+
else
|
44
|
+
key.to_s.split('_') # user_agent: %w(user agent)
|
45
|
+
.each(&:capitalize!) # => %w(User Agent)
|
46
|
+
.join('-') # => "User-Agent"
|
47
|
+
end
|
48
|
+
keymap_mutex.synchronize { map[key] = value }
|
49
|
+
end
|
50
|
+
KeyMap[:etag] = 'ETag'
|
51
|
+
|
52
|
+
def [](key)
|
53
|
+
key = KeyMap[key]
|
54
|
+
super(key) || super(@names[key.downcase])
|
55
|
+
end
|
56
|
+
|
57
|
+
def []=(key, val)
|
58
|
+
key = KeyMap[key]
|
59
|
+
key = (@names[key.downcase] ||= key)
|
60
|
+
# join multiple values with a comma
|
61
|
+
val = val.to_ary.join(', ') if val.respond_to?(:to_ary)
|
62
|
+
super(key, val)
|
63
|
+
end
|
64
|
+
|
65
|
+
def fetch(key, *args, &block)
|
66
|
+
key = KeyMap[key]
|
67
|
+
key = @names.fetch(key.downcase, key)
|
68
|
+
super(key, *args, &block)
|
69
|
+
end
|
70
|
+
|
71
|
+
def delete(key)
|
72
|
+
key = KeyMap[key]
|
73
|
+
key = @names[key.downcase]
|
74
|
+
return unless key
|
75
|
+
|
76
|
+
@names.delete key.downcase
|
77
|
+
super(key)
|
78
|
+
end
|
79
|
+
|
80
|
+
def include?(key)
|
81
|
+
@names.include? key.downcase
|
82
|
+
end
|
83
|
+
|
84
|
+
alias has_key? include?
|
85
|
+
alias member? include?
|
86
|
+
alias key? include?
|
87
|
+
|
88
|
+
def merge!(other)
|
89
|
+
other.each { |k, v| self[k] = v }
|
90
|
+
self
|
91
|
+
end
|
92
|
+
|
93
|
+
alias update merge!
|
94
|
+
|
95
|
+
def merge(other)
|
96
|
+
hash = dup
|
97
|
+
hash.merge! other
|
98
|
+
end
|
99
|
+
|
100
|
+
def replace(other)
|
101
|
+
clear
|
102
|
+
@names.clear
|
103
|
+
update other
|
104
|
+
self
|
105
|
+
end
|
106
|
+
|
107
|
+
def to_hash
|
108
|
+
::Hash.new.update(self)
|
109
|
+
end
|
110
|
+
|
111
|
+
def parse(header_string)
|
112
|
+
return unless header_string && !header_string.empty?
|
113
|
+
|
114
|
+
headers = header_string.split(/\r\n/)
|
115
|
+
|
116
|
+
# Find the last set of response headers.
|
117
|
+
start_index = headers.rindex { |x| x.match(%r{^HTTP/}) } || 0
|
118
|
+
last_response = headers.slice(start_index, headers.size)
|
119
|
+
|
120
|
+
last_response
|
121
|
+
.tap { |a| a.shift if a.first.start_with?('HTTP/') }
|
122
|
+
.map { |h| h.split(/:\s*/, 2) } # split key and value
|
123
|
+
.reject { |p| p[0].nil? } # ignore blank lines
|
124
|
+
.each { |key, value| add_parsed(key, value) }
|
125
|
+
end
|
126
|
+
|
127
|
+
protected
|
128
|
+
|
129
|
+
attr_reader :names
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
# Join multiple values with a comma.
|
134
|
+
def add_parsed(key, value)
|
135
|
+
self[key] ? self[key] << ', ' << value : self[key] = value
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
module Utils
|
5
|
+
# A hash with stringified keys.
|
6
|
+
class ParamsHash < Hash
|
7
|
+
def [](key)
|
8
|
+
super(convert_key(key))
|
9
|
+
end
|
10
|
+
|
11
|
+
def []=(key, value)
|
12
|
+
super(convert_key(key), value)
|
13
|
+
end
|
14
|
+
|
15
|
+
def delete(key)
|
16
|
+
super(convert_key(key))
|
17
|
+
end
|
18
|
+
|
19
|
+
def include?(key)
|
20
|
+
super(convert_key(key))
|
21
|
+
end
|
22
|
+
|
23
|
+
alias has_key? include?
|
24
|
+
alias member? include?
|
25
|
+
alias key? include?
|
26
|
+
|
27
|
+
def update(params)
|
28
|
+
params.each do |key, value|
|
29
|
+
self[key] = value
|
30
|
+
end
|
31
|
+
self
|
32
|
+
end
|
33
|
+
alias merge! update
|
34
|
+
|
35
|
+
def merge(params)
|
36
|
+
dup.update(params)
|
37
|
+
end
|
38
|
+
|
39
|
+
def replace(other)
|
40
|
+
clear
|
41
|
+
update(other)
|
42
|
+
end
|
43
|
+
|
44
|
+
def merge_query(query, encoder = nil)
|
45
|
+
return self unless query && !query.empty?
|
46
|
+
|
47
|
+
update((encoder || Utils.default_params_encoder).decode(query))
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_query(encoder = nil)
|
51
|
+
(encoder || Utils.default_params_encoder).encode(self)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def convert_key(key)
|
57
|
+
key.to_s
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'webmock/rspec'
|
4
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
5
|
+
|
6
|
+
require_relative '../support/helper_methods'
|
7
|
+
require_relative '../support/disabling_stub'
|
8
|
+
require_relative '../support/streaming_response_checker'
|
9
|
+
require_relative '../support/shared_examples/adapter'
|
10
|
+
require_relative '../support/shared_examples/request_method'
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.include Faraday::HelperMethods
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Olson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multipart-post
|
@@ -52,11 +52,24 @@ files:
|
|
52
52
|
- lib/faraday/adapter/rack.rb
|
53
53
|
- lib/faraday/adapter/test.rb
|
54
54
|
- lib/faraday/adapter/typhoeus.rb
|
55
|
+
- lib/faraday/adapter_registry.rb
|
55
56
|
- lib/faraday/autoload.rb
|
56
57
|
- lib/faraday/connection.rb
|
58
|
+
- lib/faraday/dependency_loader.rb
|
59
|
+
- lib/faraday/encoders/flat_params_encoder.rb
|
60
|
+
- lib/faraday/encoders/nested_params_encoder.rb
|
57
61
|
- lib/faraday/error.rb
|
62
|
+
- lib/faraday/file_part.rb
|
63
|
+
- lib/faraday/logging/formatter.rb
|
58
64
|
- lib/faraday/middleware.rb
|
65
|
+
- lib/faraday/middleware_registry.rb
|
59
66
|
- lib/faraday/options.rb
|
67
|
+
- lib/faraday/options/connection_options.rb
|
68
|
+
- lib/faraday/options/env.rb
|
69
|
+
- lib/faraday/options/proxy_options.rb
|
70
|
+
- lib/faraday/options/request_options.rb
|
71
|
+
- lib/faraday/options/ssl_options.rb
|
72
|
+
- lib/faraday/param_part.rb
|
60
73
|
- lib/faraday/parameters.rb
|
61
74
|
- lib/faraday/rack_builder.rb
|
62
75
|
- lib/faraday/request.rb
|
@@ -70,8 +83,10 @@ files:
|
|
70
83
|
- lib/faraday/response.rb
|
71
84
|
- lib/faraday/response/logger.rb
|
72
85
|
- lib/faraday/response/raise_error.rb
|
73
|
-
- lib/faraday/upload_io.rb
|
74
86
|
- lib/faraday/utils.rb
|
87
|
+
- lib/faraday/utils/headers.rb
|
88
|
+
- lib/faraday/utils/params_hash.rb
|
89
|
+
- spec/external_adapters/faraday_specs_setup.rb
|
75
90
|
homepage: https://github.com/lostisland/faraday
|
76
91
|
licenses:
|
77
92
|
- MIT
|
@@ -80,11 +95,12 @@ post_install_message:
|
|
80
95
|
rdoc_options: []
|
81
96
|
require_paths:
|
82
97
|
- lib
|
98
|
+
- spec/external_adapters
|
83
99
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
100
|
requirements:
|
85
101
|
- - ">="
|
86
102
|
- !ruby/object:Gem::Version
|
87
|
-
version: '
|
103
|
+
version: '2.3'
|
88
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
105
|
requirements:
|
90
106
|
- - ">="
|
@@ -92,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
108
|
version: '0'
|
93
109
|
requirements: []
|
94
110
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.7.
|
111
|
+
rubygems_version: 2.7.6.2
|
96
112
|
signing_key:
|
97
113
|
specification_version: 4
|
98
114
|
summary: HTTP/REST API client library.
|
data/lib/faraday/upload_io.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'composite_io'
|
3
|
-
require 'parts'
|
4
|
-
require 'stringio'
|
5
|
-
rescue LoadError
|
6
|
-
$stderr.puts "Install the multipart-post gem."
|
7
|
-
raise
|
8
|
-
end
|
9
|
-
|
10
|
-
module Faraday
|
11
|
-
# Similar but not compatible with ::CompositeReadIO provided by multipart-post.
|
12
|
-
class CompositeReadIO
|
13
|
-
def initialize(*parts)
|
14
|
-
@parts = parts.flatten
|
15
|
-
@ios = @parts.map { |part| part.to_io }
|
16
|
-
@index = 0
|
17
|
-
end
|
18
|
-
|
19
|
-
def length
|
20
|
-
@parts.inject(0) { |sum, part| sum + part.length }
|
21
|
-
end
|
22
|
-
|
23
|
-
def rewind
|
24
|
-
@ios.each { |io| io.rewind }
|
25
|
-
@index = 0
|
26
|
-
end
|
27
|
-
|
28
|
-
# Read from IOs in order until `length` bytes have been received.
|
29
|
-
def read(length = nil, outbuf = nil)
|
30
|
-
got_result = false
|
31
|
-
outbuf = outbuf ? outbuf.replace("") : ""
|
32
|
-
|
33
|
-
while io = current_io
|
34
|
-
if result = io.read(length)
|
35
|
-
got_result ||= !result.nil?
|
36
|
-
result.force_encoding("BINARY") if result.respond_to?(:force_encoding)
|
37
|
-
outbuf << result
|
38
|
-
length -= result.length if length
|
39
|
-
break if length == 0
|
40
|
-
end
|
41
|
-
advance_io
|
42
|
-
end
|
43
|
-
(!got_result && length) ? nil : outbuf
|
44
|
-
end
|
45
|
-
|
46
|
-
def close
|
47
|
-
@ios.each { |io| io.close }
|
48
|
-
end
|
49
|
-
|
50
|
-
def ensure_open_and_readable
|
51
|
-
# Rubinius compatibility
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def current_io
|
57
|
-
@ios[@index]
|
58
|
-
end
|
59
|
-
|
60
|
-
def advance_io
|
61
|
-
@index += 1
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
UploadIO = ::UploadIO
|
66
|
-
Parts = ::Parts
|
67
|
-
end
|