faraday 0.15.0 → 0.15.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3737507d92b48e4b98e891c5026210048ab70b2b1ee17ea20993b8ffc65eafb5
4
- data.tar.gz: caaaa7f7ad1bdda848ac7bc70d4d1b9ba9d06bc85912a61b1ee4082086629a26
3
+ metadata.gz: db0b54b940edbbba0e72c6a5d393b101f6852c4d4c9d4b31106382a983c31045
4
+ data.tar.gz: 594b4833954d6049878ccc1e1006d4b4295da70b01809f2abbd977368215812e
5
5
  SHA512:
6
- metadata.gz: 231b96efdd5b0399f204edaeba22d01661b9d301aff6cad7d097c27c1e95f0a0a8adc9184e88f089862fa9db9a833e50a3eb7bfb96034a2df7f1bdd93661f3fb
7
- data.tar.gz: f19fca5f59454b7b620160c3e58339e0dff8049be29bda8e8f1a494455dac6c62a1c6cbe4b4e141e999ea3df25cbcdf3ef09d65e93d71a882c318c75c3070dec
6
+ metadata.gz: 347f4c8f7e15467652370480e1131ec28ee9eeb964bc5eb8982781da79718a74bd3fe2421d57107e2245fc218b1cb0351c0df569f18b2f2fe0d1625408b8fa82
7
+ data.tar.gz: 5014a90947f8987b70facb531f9dd83f4df923ee9d14cb3b8d5250cce0fe51e0eaba6b4a1ca9b5a35db15d5b181a964b9aaeaddcfc0f4f3feec9b669a48817c5
data/README.md CHANGED
@@ -54,7 +54,7 @@ Since the default middleware stack uses url\_encoded middleware and default adap
54
54
  ```ruby
55
55
  conn = Faraday.new(:url => 'http://sushi.com') do |faraday|
56
56
  faraday.request :url_encoded # form-encode POST params
57
- faraday.response :logger # log requests to STDOUT
57
+ faraday.response :logger # log requests to $stdout
58
58
  faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
59
59
  end
60
60
 
@@ -79,7 +79,7 @@ response.body
79
79
 
80
80
  conn.get '/nigiri', { :name => 'Maguro' } # GET http://sushi.com/nigiri?name=Maguro
81
81
 
82
- conn.get do |req| # GET http://sushi.com/search?page=2&limit=100
82
+ conn.get do |req| # GET http://sushi.com/search?page=2&limit=100
83
83
  req.url '/search', :page => 2
84
84
  req.params['limit'] = 100
85
85
  end
@@ -118,7 +118,7 @@ conn.get do |req|
118
118
  req.options.context = {
119
119
  foo: 'foo',
120
120
  bar: 'bar'
121
- }
121
+ }
122
122
  end
123
123
  ```
124
124
 
@@ -14,7 +14,7 @@ require 'forwardable'
14
14
  # conn.get '/'
15
15
  #
16
16
  module Faraday
17
- VERSION = "0.15.0"
17
+ VERSION = "0.15.1"
18
18
 
19
19
  class << self
20
20
  # Public: Gets or sets the root path that Faraday is being loaded from.
@@ -15,6 +15,9 @@ module Faraday
15
15
  opts[:client_key] = ssl[:client_key] if ssl[:client_key]
16
16
  opts[:certificate] = ssl[:certificate] if ssl[:certificate]
17
17
  opts[:private_key] = ssl[:private_key] if ssl[:private_key]
18
+ opts[:ssl_version] = ssl[:version] if ssl[:version]
19
+ opts[:ssl_min_version] = ssl[:min_version] if ssl[:min_version]
20
+ opts[:ssl_max_version] = ssl[:max_version] if ssl[:max_version]
18
21
 
19
22
  # https://github.com/geemus/excon/issues/106
20
23
  # https://github.com/jruby/jruby-ossl/issues/19
@@ -28,6 +28,11 @@ module Faraday
28
28
  NET_HTTP_EXCEPTIONS << OpenSSL::SSL::SSLError if defined?(OpenSSL)
29
29
  NET_HTTP_EXCEPTIONS << Net::OpenTimeout if defined?(Net::OpenTimeout)
30
30
 
31
+ def initialize(app = nil, opts = {}, &block)
32
+ @cert_store = nil
33
+ super(app, opts, &block)
34
+ end
35
+
31
36
  def call(env)
32
37
  super
33
38
  with_net_http_connection(env) do |http|
@@ -106,6 +111,8 @@ module Faraday
106
111
  http.ca_path = ssl[:ca_path] if ssl[:ca_path]
107
112
  http.verify_depth = ssl[:verify_depth] if ssl[:verify_depth]
108
113
  http.ssl_version = ssl[:version] if ssl[:version]
114
+ http.min_version = ssl[:min_version] if ssl[:min_version]
115
+ http.max_version = ssl[:max_version] if ssl[:max_version]
109
116
  end
110
117
 
111
118
  def configure_request(http, req)
@@ -117,10 +124,11 @@ module Faraday
117
124
 
118
125
  def ssl_cert_store(ssl)
119
126
  return ssl[:cert_store] if ssl[:cert_store]
127
+ return @cert_store if @cert_store
120
128
  # Use the default cert store by default, i.e. system ca certs
121
- cert_store = OpenSSL::X509::Store.new
122
- cert_store.set_default_paths
123
- cert_store
129
+ @cert_store = OpenSSL::X509::Store.new
130
+ @cert_store.set_default_paths
131
+ @cert_store
124
132
  end
125
133
 
126
134
  def ssl_verify_mode(ssl)
@@ -6,15 +6,16 @@ module Faraday
6
6
  private
7
7
 
8
8
  def net_http_connection(env)
9
- proxy_uri = proxy_uri(env)
10
-
11
- cached_connection env[:url], proxy_uri do
9
+ @cached_connection ||=
12
10
  if Net::HTTP::Persistent.instance_method(:initialize).parameters.first == [:key, :name]
13
- Net::HTTP::Persistent.new(name: 'Faraday', proxy: proxy_uri)
11
+ Net::HTTP::Persistent.new(name: 'Faraday')
14
12
  else
15
- Net::HTTP::Persistent.new('Faraday', proxy_uri)
13
+ Net::HTTP::Persistent.new('Faraday')
16
14
  end
17
- end
15
+
16
+ proxy_uri = proxy_uri(env)
17
+ @cached_connection.proxy = proxy_uri if @cached_connection.proxy_uri != proxy_uri
18
+ @cached_connection
18
19
  end
19
20
 
20
21
  def proxy_uri(env)
@@ -46,17 +47,19 @@ module Faraday
46
47
  end
47
48
 
48
49
  def configure_ssl(http, ssl)
49
- http.verify_mode = ssl_verify_mode(ssl)
50
- http.cert_store = ssl_cert_store(ssl)
50
+ http_set(http, :verify_mode, ssl_verify_mode(ssl))
51
+ http_set(http, :cert_store, ssl_cert_store(ssl))
51
52
 
52
- http.certificate = ssl[:client_cert] if ssl[:client_cert]
53
- http.private_key = ssl[:client_key] if ssl[:client_key]
54
- http.ca_file = ssl[:ca_file] if ssl[:ca_file]
55
- http.ssl_version = ssl[:version] if ssl[:version]
53
+ http_set(http, :certificate, ssl[:client_cert]) if ssl[:client_cert]
54
+ http_set(http, :private_key, ssl[:client_key]) if ssl[:client_key]
55
+ http_set(http, :ca_file, ssl[:ca_file]) if ssl[:ca_file]
56
+ http_set(http, :ssl_version, ssl[:version]) if ssl[:version]
56
57
  end
57
58
 
58
- def cached_connection(url, proxy_uri)
59
- (@cached_connection ||= {})[[url.scheme, url.host, url.port, proxy_uri]] ||= yield
59
+ def http_set(http, attr, value)
60
+ if http.send(attr) != value
61
+ http.send("#{attr}=", value)
62
+ end
60
63
  end
61
64
  end
62
65
  end
@@ -8,7 +8,8 @@ module Faraday
8
8
  # TODO: support streaming requests
9
9
  env[:body] = env[:body].read if env[:body].respond_to? :read
10
10
 
11
- session = @session ||= create_session
11
+ session = ::Patron::Session.new
12
+ @config_block.call(session) if @config_block
12
13
  configure_ssl(session, env[:ssl]) if env[:url].scheme == 'https' and env[:ssl]
13
14
 
14
15
  if req = env[:request]
@@ -65,12 +66,6 @@ module Faraday
65
66
  end
66
67
  end
67
68
 
68
- def create_session
69
- session = ::Patron::Session.new
70
- @config_block.call(session) if @config_block
71
- session
72
- end
73
-
74
69
  def configure_ssl(session, ssl)
75
70
  if ssl.fetch(:verify, true)
76
71
  session.cacert = ssl[:ca_file]
@@ -214,7 +214,8 @@ module Faraday
214
214
  end
215
215
 
216
216
  class SSLOptions < Options.new(:verify, :ca_file, :ca_path, :verify_mode,
217
- :cert_store, :client_cert, :client_key, :certificate, :private_key, :verify_depth, :version)
217
+ :cert_store, :client_cert, :client_key, :certificate, :private_key, :verify_depth,
218
+ :version, :min_version, :max_version)
218
219
 
219
220
  def verify?
220
221
  verify != false
@@ -10,7 +10,7 @@ module Faraday
10
10
  super(app)
11
11
  @logger = logger || begin
12
12
  require 'logger'
13
- ::Logger.new(STDOUT)
13
+ ::Logger.new($stdout)
14
14
  end
15
15
  @filter = []
16
16
  @options = DEFAULT_OPTIONS.merge(options)
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.15.0
4
+ version: 0.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Olson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-19 00:00:00.000000000 Z
11
+ date: 2018-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post