faraday 0.10.1 → 0.11.0
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/README.md +8 -0
- data/lib/faraday.rb +1 -1
- data/lib/faraday/adapter.rb +6 -0
- data/lib/faraday/adapter/em_http.rb +5 -1
- data/lib/faraday/adapter/em_synchrony.rb +5 -1
- data/lib/faraday/adapter/excon.rb +5 -6
- data/lib/faraday/adapter/httpclient.rb +6 -0
- data/lib/faraday/adapter/net_http.rb +8 -4
- data/lib/faraday/adapter/net_http_persistent.rb +4 -3
- data/lib/faraday/adapter/patron.rb +1 -6
- data/lib/faraday/connection.rb +3 -3
- data/lib/faraday/options.rb +7 -0
- data/lib/faraday/request/authorization.rb +1 -2
- data/lib/faraday/request/retry.rb +1 -1
- data/lib/faraday/response/logger.rb +19 -5
- 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: 88d17f843f96e641d4cb8b87b360b99adfee6c53
|
4
|
+
data.tar.gz: 3c0031b2fa042939cc5e7f27aefa00f8ebe6a97f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03fa51e8008930909fb2e5f40afe8f3d59d176574a084e364569d256b0c073bd06796bb0fe96f79c42cfacda2ee8417fecb1b3fc13e5b46bbb76f960136d116c
|
7
|
+
data.tar.gz: 16432e693c7c666ac40de8a03ca890f08ee1cba705477afd31d64346282f018abf9ee617e1996330bbe2b2c3352021683e386522d700c49d08246b77d36fb65a
|
data/README.md
CHANGED
@@ -30,6 +30,14 @@ conn = Faraday.new(:url => 'http://sushi.com') do |faraday|
|
|
30
30
|
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
31
31
|
end
|
32
32
|
|
33
|
+
# Filter sensitive information from logs with a regex matcher
|
34
|
+
|
35
|
+
conn = Faraday.new(:url => 'http://sushi.com/api_key=s3cr3t') do |faraday|
|
36
|
+
faraday.response :logger do | logger |
|
37
|
+
logger.filter(/(api_key=)(\w+)/,'\1[REMOVED]')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
33
41
|
## GET ##
|
34
42
|
|
35
43
|
response = conn.get '/nigiri/sake.json' # GET http://sushi.com/nigiri/sake.json
|
data/lib/faraday.rb
CHANGED
data/lib/faraday/adapter.rb
CHANGED
@@ -30,6 +30,12 @@ module Faraday
|
|
30
30
|
extend Parallelism
|
31
31
|
self.supports_parallel = false
|
32
32
|
|
33
|
+
def initialize(app = nil, opts = {}, &block)
|
34
|
+
super(app)
|
35
|
+
@connection_options = opts
|
36
|
+
@config_block = block
|
37
|
+
end
|
38
|
+
|
33
39
|
def call(env)
|
34
40
|
env.clear_body if env.needs_body?
|
35
41
|
end
|
@@ -138,7 +138,7 @@ module Faraday
|
|
138
138
|
|
139
139
|
# TODO: reuse the connection to support pipelining
|
140
140
|
def perform_single_request(env)
|
141
|
-
req =
|
141
|
+
req = create_request(env)
|
142
142
|
req.setup_request(env[:method], request_config(env)).callback { |client|
|
143
143
|
status = client.response_header.status
|
144
144
|
reason = client.response_header.http_reason
|
@@ -150,6 +150,10 @@ module Faraday
|
|
150
150
|
}
|
151
151
|
end
|
152
152
|
|
153
|
+
def create_request(env)
|
154
|
+
EventMachine::HttpRequest.new(env[:url], connection_config(env).merge(@connection_options))
|
155
|
+
end
|
156
|
+
|
153
157
|
def error_message(client)
|
154
158
|
client.error or "request failed"
|
155
159
|
end
|
@@ -19,7 +19,7 @@ module Faraday
|
|
19
19
|
|
20
20
|
def call(env)
|
21
21
|
super
|
22
|
-
request =
|
22
|
+
request = create_request(env)
|
23
23
|
|
24
24
|
http_method = env[:method].to_s.downcase.to_sym
|
25
25
|
|
@@ -87,6 +87,10 @@ module Faraday
|
|
87
87
|
raise
|
88
88
|
end
|
89
89
|
end
|
90
|
+
|
91
|
+
def create_request(env)
|
92
|
+
EventMachine::HttpRequest.new(Utils::URI(env[:url].to_s), connection_config(env).merge(@connection_options))
|
93
|
+
end
|
90
94
|
end
|
91
95
|
end
|
92
96
|
end
|
@@ -3,11 +3,6 @@ module Faraday
|
|
3
3
|
class Excon < Faraday::Adapter
|
4
4
|
dependency 'excon'
|
5
5
|
|
6
|
-
def initialize(app, connection_options = {})
|
7
|
-
@connection_options = connection_options
|
8
|
-
super(app)
|
9
|
-
end
|
10
|
-
|
11
6
|
def call(env)
|
12
7
|
super
|
13
8
|
|
@@ -50,7 +45,7 @@ module Faraday
|
|
50
45
|
end
|
51
46
|
end
|
52
47
|
|
53
|
-
conn =
|
48
|
+
conn = create_connection(env, opts)
|
54
49
|
|
55
50
|
resp = conn.request \
|
56
51
|
:method => env[:method].to_s.upcase,
|
@@ -72,6 +67,10 @@ module Faraday
|
|
72
67
|
raise Error::TimeoutError, err
|
73
68
|
end
|
74
69
|
|
70
|
+
def create_connection(env, opts)
|
71
|
+
::Excon.new(env[:url].to_s, opts.merge(@connection_options))
|
72
|
+
end
|
73
|
+
|
75
74
|
# TODO: support streaming requests
|
76
75
|
def read_body(env)
|
77
76
|
env[:body].respond_to?(:read) ? env[:body].read : env[:body]
|
@@ -29,6 +29,8 @@ module Faraday
|
|
29
29
|
configure_ssl ssl
|
30
30
|
end
|
31
31
|
|
32
|
+
configure_client
|
33
|
+
|
32
34
|
# TODO Don't stream yet.
|
33
35
|
# https://github.com/nahi/httpclient/pull/90
|
34
36
|
env[:body] = env[:body].read if env[:body].respond_to? :read
|
@@ -95,6 +97,10 @@ module Faraday
|
|
95
97
|
end
|
96
98
|
end
|
97
99
|
|
100
|
+
def configure_client
|
101
|
+
@config_block.call(client) if @config_block
|
102
|
+
end
|
103
|
+
|
98
104
|
def ssl_cert_store(ssl)
|
99
105
|
return ssl[:cert_store] if ssl[:cert_store]
|
100
106
|
# Memoize the cert store so that the same one is passed to
|
@@ -32,10 +32,7 @@ module Faraday
|
|
32
32
|
super
|
33
33
|
with_net_http_connection(env) do |http|
|
34
34
|
configure_ssl(http, env[:ssl]) if env[:url].scheme == 'https' and env[:ssl]
|
35
|
-
|
36
|
-
req = env[:request]
|
37
|
-
http.read_timeout = http.open_timeout = req[:timeout] if req[:timeout]
|
38
|
-
http.open_timeout = req[:open_timeout] if req[:open_timeout]
|
35
|
+
configure_request(http, env[:request])
|
39
36
|
|
40
37
|
begin
|
41
38
|
http_response = perform_request(http, env)
|
@@ -109,6 +106,13 @@ module Faraday
|
|
109
106
|
http.ssl_version = ssl[:version] if ssl[:version]
|
110
107
|
end
|
111
108
|
|
109
|
+
def configure_request(http, req)
|
110
|
+
http.read_timeout = http.open_timeout = req[:timeout] if req[:timeout]
|
111
|
+
http.open_timeout = req[:open_timeout] if req[:open_timeout]
|
112
|
+
|
113
|
+
@config_block.call(http) if @config_block
|
114
|
+
end
|
115
|
+
|
112
116
|
def ssl_cert_store(ssl)
|
113
117
|
return ssl[:cert_store] if ssl[:cert_store]
|
114
118
|
# Use the default cert store by default, i.e. system ca certs
|
@@ -7,8 +7,8 @@ module Faraday
|
|
7
7
|
class NetHttpPersistent < NetHttp
|
8
8
|
dependency 'net/http/persistent'
|
9
9
|
|
10
|
-
def
|
11
|
-
if proxy = env[:request][:proxy]
|
10
|
+
def net_http_connection(env)
|
11
|
+
if (proxy = env[:request][:proxy])
|
12
12
|
proxy_uri = ::URI::HTTP === proxy[:uri] ? proxy[:uri].dup : ::URI.parse(proxy[:uri].to_s)
|
13
13
|
proxy_uri.user = proxy_uri.password = nil
|
14
14
|
# awful patch for net-http-persistent 2.8 not unescaping user/password
|
@@ -16,9 +16,10 @@ module Faraday
|
|
16
16
|
define_method(:user) { proxy[:user] }
|
17
17
|
define_method(:password) { proxy[:password] }
|
18
18
|
end if proxy[:user]
|
19
|
+
return Net::HTTP::Persistent.new 'Faraday', proxy_uri
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
|
+
Net::HTTP::Persistent.new 'Faraday'
|
22
23
|
end
|
23
24
|
|
24
25
|
def perform_request(http, env)
|
@@ -3,11 +3,6 @@ module Faraday
|
|
3
3
|
class Patron < Faraday::Adapter
|
4
4
|
dependency 'patron'
|
5
5
|
|
6
|
-
def initialize(app, &block)
|
7
|
-
super(app)
|
8
|
-
@block = block
|
9
|
-
end
|
10
|
-
|
11
6
|
def call(env)
|
12
7
|
super
|
13
8
|
|
@@ -73,7 +68,7 @@ module Faraday
|
|
73
68
|
def create_session
|
74
69
|
session = ::Patron::Session.new
|
75
70
|
session.insecure = true
|
76
|
-
@
|
71
|
+
@config_block.call(session) if @config_block
|
77
72
|
session
|
78
73
|
end
|
79
74
|
end
|
data/lib/faraday/connection.rb
CHANGED
@@ -55,11 +55,11 @@ module Faraday
|
|
55
55
|
# :user - String (optional)
|
56
56
|
# :password - String (optional)
|
57
57
|
def initialize(url = nil, options = nil)
|
58
|
+
options = ConnectionOptions.from(options) unless options and options.is_a?(ConnectionOptions)
|
59
|
+
|
58
60
|
if url.is_a?(Hash)
|
59
|
-
options = options
|
61
|
+
options = options.merge(url)
|
60
62
|
url = options.url
|
61
|
-
else
|
62
|
-
options = ConnectionOptions.from(options)
|
63
63
|
end
|
64
64
|
|
65
65
|
@parallel_manager = nil
|
data/lib/faraday/options.rb
CHANGED
@@ -12,22 +12,28 @@ module Faraday
|
|
12
12
|
require 'logger'
|
13
13
|
::Logger.new(STDOUT)
|
14
14
|
end
|
15
|
+
@filter = []
|
15
16
|
@options = DEFAULT_OPTIONS.merge(options)
|
17
|
+
yield self if block_given?
|
16
18
|
end
|
17
19
|
|
18
20
|
def_delegators :@logger, :debug, :info, :warn, :error, :fatal
|
19
21
|
|
20
22
|
def call(env)
|
21
|
-
info "#{env.method} #{env.url.to_s}"
|
22
|
-
debug('request') { dump_headers env.request_headers } if log_headers?(:request)
|
23
|
-
debug('request') { dump_body(env[:body]) } if env[:body] && log_body?(:request)
|
23
|
+
info "#{env.method} #{apply_filters(env.url.to_s)}"
|
24
|
+
debug('request') { apply_filters( dump_headers env.request_headers ) } if log_headers?(:request)
|
25
|
+
debug('request') { apply_filters( dump_body(env[:body]) ) } if env[:body] && log_body?(:request)
|
24
26
|
super
|
25
27
|
end
|
26
28
|
|
27
29
|
def on_complete(env)
|
28
30
|
info('Status') { env.status.to_s }
|
29
|
-
debug('response') { dump_headers env.response_headers } if log_headers?(:response)
|
30
|
-
debug('response') { dump_body env[:body] } if env[:body] && log_body?(:response)
|
31
|
+
debug('response') { apply_filters( dump_headers env.response_headers ) } if log_headers?(:response)
|
32
|
+
debug('response') { apply_filters( dump_body env[:body] ) } if env[:body] && log_body?(:response)
|
33
|
+
end
|
34
|
+
|
35
|
+
def filter(filter_word, filter_replacement)
|
36
|
+
@filter.push([ filter_word, filter_replacement ])
|
31
37
|
end
|
32
38
|
|
33
39
|
private
|
@@ -62,5 +68,13 @@ module Faraday
|
|
62
68
|
else @options[:bodies]
|
63
69
|
end
|
64
70
|
end
|
71
|
+
|
72
|
+
def apply_filters(output)
|
73
|
+
@filter.each do |pattern, replacement|
|
74
|
+
output = output.to_s.gsub(pattern, replacement)
|
75
|
+
end
|
76
|
+
output
|
77
|
+
end
|
78
|
+
|
65
79
|
end
|
66
80
|
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.11.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: 2017-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multipart-post
|