faraday 0.12.1 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/faraday.rb +3 -2
- data/lib/faraday/adapter/httpclient.rb +1 -1
- data/lib/faraday/adapter/patron.rb +9 -2
- data/lib/faraday/connection.rb +1 -1
- data/lib/faraday/options.rb +1 -1
- data/lib/faraday/rack_builder.rb +22 -0
- data/lib/faraday/utils.rb +18 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 515b1bc445a69d6ccdbb95b042750cd08962053a
|
4
|
+
data.tar.gz: 504c63a2fb5c1bb6eec8b8cf9d930bd966984be2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5da384774bb02aae523a55d2f383ae4f0804757eabd1a398eca2998f6c6279391cb48c39e99d7948d63b4a71953ef98e31eb7e5dad57af5b615c9af007e8e870
|
7
|
+
data.tar.gz: 63f74afdb08b2232af31ceb76309466f30a3fc4e4d9edbb2e67d4ecac94e432591edc0932fb32ad3945af261b49c7fc6663e06bc8fbfef1f24a9ce60418cc76a
|
data/README.md
CHANGED
@@ -42,7 +42,8 @@ conn = Faraday.new(:url => 'http://www.example.com')
|
|
42
42
|
response = conn.get '/users' # GET http://www.example.com/users'
|
43
43
|
```
|
44
44
|
|
45
|
-
Connections can also take an options hash as a parameter or be configured by using a block. Checkout the section called [Advanced middleware usage](#advanced-middleware-usage) for more details about how to use this block for configurations.
|
45
|
+
Connections can also take an options hash as a parameter or be configured by using a block. Checkout the section called [Advanced middleware usage](#advanced-middleware-usage) for more details about how to use this block for configurations.
|
46
|
+
Since the default middleware stack uses url\_encoded middleware and default adapter, use them on building your own middleware stack.
|
46
47
|
|
47
48
|
```ruby
|
48
49
|
conn = Faraday.new(:url => 'http://sushi.com') do |faraday|
|
@@ -54,6 +55,7 @@ end
|
|
54
55
|
# Filter sensitive information from logs with a regex matcher
|
55
56
|
|
56
57
|
conn = Faraday.new(:url => 'http://sushi.com/api_key=s3cr3t') do |faraday|
|
58
|
+
faraday.request :url_encoded # form-encode POST params
|
57
59
|
faraday.response :logger do | logger |
|
58
60
|
logger.filter(/(api_key=)(\w+)/,'\1[REMOVED]')
|
59
61
|
end
|
@@ -166,6 +168,7 @@ Faraday.new(...) do |conn|
|
|
166
168
|
conn.request :multipart
|
167
169
|
conn.request :url_encoded
|
168
170
|
|
171
|
+
# Last middleware must be the adapter:
|
169
172
|
conn.adapter :net_http
|
170
173
|
end
|
171
174
|
```
|
data/lib/faraday.rb
CHANGED
@@ -14,7 +14,7 @@ require 'forwardable'
|
|
14
14
|
# conn.get '/'
|
15
15
|
#
|
16
16
|
module Faraday
|
17
|
-
VERSION = "0.12.
|
17
|
+
VERSION = "0.12.2"
|
18
18
|
|
19
19
|
class << self
|
20
20
|
# Public: Gets or sets the root path that Faraday is being loaded from.
|
@@ -109,7 +109,7 @@ module Faraday
|
|
109
109
|
#
|
110
110
|
# Returns a Faraday::Connection, configured with the #default_adapter.
|
111
111
|
def self.default_connection
|
112
|
-
@default_connection ||= Connection.new
|
112
|
+
@default_connection ||= Connection.new(default_connection_options)
|
113
113
|
end
|
114
114
|
|
115
115
|
# Gets the default connection options used when calling Faraday#new.
|
@@ -121,6 +121,7 @@ module Faraday
|
|
121
121
|
|
122
122
|
# Public: Sets the default options used when calling Faraday#new.
|
123
123
|
def self.default_connection_options=(options)
|
124
|
+
@default_connection = nil
|
124
125
|
@default_connection_options = ConnectionOptions.from(options)
|
125
126
|
end
|
126
127
|
|
@@ -50,7 +50,7 @@ module Faraday
|
|
50
50
|
else
|
51
51
|
raise Faraday::Error::ClientError, $!
|
52
52
|
end
|
53
|
-
rescue Errno::ECONNREFUSED, IOError
|
53
|
+
rescue Errno::ECONNREFUSED, IOError, SocketError
|
54
54
|
raise Faraday::Error::ConnectionFailed, $!
|
55
55
|
rescue => err
|
56
56
|
if defined?(OpenSSL) && OpenSSL::SSL::SSLError === err
|
@@ -5,11 +5,11 @@ module Faraday
|
|
5
5
|
|
6
6
|
def call(env)
|
7
7
|
super
|
8
|
-
|
9
8
|
# TODO: support streaming requests
|
10
9
|
env[:body] = env[:body].read if env[:body].respond_to? :read
|
11
10
|
|
12
11
|
session = @session ||= create_session
|
12
|
+
configure_ssl(session, env[:ssl]) if env[:url].scheme == 'https' and env[:ssl]
|
13
13
|
|
14
14
|
if req = env[:request]
|
15
15
|
session.timeout = session.connect_timeout = req[:timeout] if req[:timeout]
|
@@ -67,10 +67,17 @@ module Faraday
|
|
67
67
|
|
68
68
|
def create_session
|
69
69
|
session = ::Patron::Session.new
|
70
|
-
session.insecure = true
|
71
70
|
@config_block.call(session) if @config_block
|
72
71
|
session
|
73
72
|
end
|
73
|
+
|
74
|
+
def configure_ssl(session, ssl)
|
75
|
+
if ssl.fetch(:verify, true)
|
76
|
+
session.cacert = ssl[:ca_file]
|
77
|
+
else
|
78
|
+
session.insecure = true
|
79
|
+
end
|
80
|
+
end
|
74
81
|
end
|
75
82
|
end
|
76
83
|
end
|
data/lib/faraday/connection.rb
CHANGED
data/lib/faraday/options.rb
CHANGED
@@ -49,7 +49,7 @@ module Faraday
|
|
49
49
|
other.each do |key, other_value|
|
50
50
|
self_value = self.send(key)
|
51
51
|
sub_options = self.class.options_for(key)
|
52
|
-
new_value = sub_options ? self_value.merge(other_value) : other_value
|
52
|
+
new_value = (self_value && sub_options && other_value) ? self_value.merge(other_value) : other_value
|
53
53
|
self.send("#{key}=", new_value) unless new_value.nil?
|
54
54
|
end
|
55
55
|
self
|
data/lib/faraday/rack_builder.rb
CHANGED
@@ -84,6 +84,7 @@ module Faraday
|
|
84
84
|
use_symbol(Faraday::Middleware, klass, *args, &block)
|
85
85
|
else
|
86
86
|
raise_if_locked
|
87
|
+
warn_middleware_after_adapter if adapter_set?
|
87
88
|
@handlers << self.class::Handler.new(klass, *args, &block)
|
88
89
|
end
|
89
90
|
end
|
@@ -105,6 +106,7 @@ module Faraday
|
|
105
106
|
def insert(index, *args, &block)
|
106
107
|
raise_if_locked
|
107
108
|
index = assert_index(index)
|
109
|
+
warn_middleware_after_adapter if inserting_after_adapter?(index)
|
108
110
|
handler = self.class::Handler.new(*args, &block)
|
109
111
|
@handlers.insert(index, handler)
|
110
112
|
end
|
@@ -200,6 +202,26 @@ module Faraday
|
|
200
202
|
raise StackLocked, "can't modify middleware stack after making a request" if locked?
|
201
203
|
end
|
202
204
|
|
205
|
+
def warn_middleware_after_adapter
|
206
|
+
warn "WARNING: Unexpected middleware set after the adapter. " \
|
207
|
+
"This won't be supported from Faraday 1.0."
|
208
|
+
end
|
209
|
+
|
210
|
+
def adapter_set?
|
211
|
+
@handlers.any? { |handler| is_adapter?(handler) }
|
212
|
+
end
|
213
|
+
|
214
|
+
def inserting_after_adapter?(index)
|
215
|
+
adapter_index = @handlers.find_index { |handler| is_adapter?(handler) }
|
216
|
+
return false if adapter_index.nil?
|
217
|
+
|
218
|
+
index > adapter_index
|
219
|
+
end
|
220
|
+
|
221
|
+
def is_adapter?(handler)
|
222
|
+
handler.klass.ancestors.include? Faraday::Adapter
|
223
|
+
end
|
224
|
+
|
203
225
|
def use_symbol(mod, key, *args, &block)
|
204
226
|
use(mod.lookup_middleware(key), *args, &block)
|
205
227
|
end
|
data/lib/faraday/utils.rb
CHANGED
@@ -10,12 +10,22 @@ module Faraday
|
|
10
10
|
new(value)
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.allocate
|
14
|
+
new_self = super
|
15
|
+
new_self.initialize_names
|
16
|
+
new_self
|
17
|
+
end
|
18
|
+
|
13
19
|
def initialize(hash = nil)
|
14
20
|
super()
|
15
21
|
@names = {}
|
16
22
|
self.update(hash || {})
|
17
23
|
end
|
18
24
|
|
25
|
+
def initialize_names
|
26
|
+
@names = {}
|
27
|
+
end
|
28
|
+
|
19
29
|
# on dup/clone, we need to duplicate @names hash
|
20
30
|
def initialize_copy(other)
|
21
31
|
super
|
@@ -95,7 +105,14 @@ module Faraday
|
|
95
105
|
|
96
106
|
def parse(header_string)
|
97
107
|
return unless header_string && !header_string.empty?
|
98
|
-
|
108
|
+
|
109
|
+
headers = header_string.split(/\r\n/)
|
110
|
+
|
111
|
+
# Find the last set of response headers.
|
112
|
+
start_index = headers.rindex { |x| x.match(/^HTTP\//) }
|
113
|
+
last_response = headers.slice(start_index, headers.size)
|
114
|
+
|
115
|
+
last_response.
|
99
116
|
tap { |a| a.shift if a.first.index('HTTP/') == 0 }. # drop the HTTP status line
|
100
117
|
map { |h| h.split(/:\s*/, 2) }.reject { |p| p[0].nil? }. # split key and value, ignore blank lines
|
101
118
|
each { |key, value|
|
@@ -108,14 +125,6 @@ module Faraday
|
|
108
125
|
}
|
109
126
|
end
|
110
127
|
|
111
|
-
def init_with(coder)
|
112
|
-
@names = coder['names']
|
113
|
-
end
|
114
|
-
|
115
|
-
def encode_with(coder)
|
116
|
-
coder['names'] = @names
|
117
|
-
end
|
118
|
-
|
119
128
|
protected
|
120
129
|
|
121
130
|
def names
|
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.12.
|
4
|
+
version: 0.12.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Olson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multipart-post
|