splitclient-rb 7.3.5.pre.rc3 → 8.0.0.pre.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df863c319448efe787511c74dcf0943f7f0678a1307d2dd97c3da68bab54091b
4
- data.tar.gz: e36cb5e66fbc19cffb7343e8577436064713a79362bfc2f899f9f5d3cf9827fc
3
+ metadata.gz: 1959ef83640b436c648273ee5971c2a0d9b16af8a3344d9d4b3b544da2bbbe7c
4
+ data.tar.gz: d37340012997849e1ee3f886696347efd0e6f956051c299f9449b12630a5f193
5
5
  SHA512:
6
- metadata.gz: a7ac1c8ea998d34c709d71b3725fcac423056cc544a6d84eabdd4a86552d3dfa023b0b8bc253a0f9825a47f2082a165ba2887078225e9cc661f7b2d1204c943c
7
- data.tar.gz: 9b96aeb5547fe3debf7b53a05f64d7fbe4c5e83de4ea0a4a96cbd40d6e7cafe73cc5a9b45ad32246edbf73faa9f6f83526631b1ba2c7f691a4597601b90d4bb1
6
+ metadata.gz: 9a7f3ff299c0617afb4a35733a4e50e229ebc8c6036b084efca91bc1e390f7992738ab9ed6a64448dde4d2c4c0a91f11d50dea0eb71a0c785c78b39fc0bd4619
7
+ data.tar.gz: '08450153e746294a69e3b5e710172a084f1fec246d2b0843e7b16f6da330f1cd0073771deabe8297ec86eea0ae7746faa5d5007a875f29d05862cb6f1d166069'
@@ -1,10 +1,4 @@
1
- on:
2
- push:
3
- branches:
4
- - master
5
- pull_request:
6
- branches:
7
- - master
1
+ on: [push, pull_request]
8
2
 
9
3
  jobs:
10
4
  test:
@@ -21,7 +15,7 @@ jobs:
21
15
  fetch-depth: 0
22
16
 
23
17
  - name: Set up Ruby
24
- uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
18
+ uses: ruby/setup-ruby@v1
25
19
  with:
26
20
  ruby-version: 2.5
27
21
 
data/.rubocop.yml CHANGED
@@ -52,7 +52,7 @@ Naming/FileName:
52
52
  - splitclient-rb.gemspec
53
53
 
54
54
  AllCops:
55
- TargetRubyVersion: 2.3.6
55
+ TargetRubyVersion: 2.5
56
56
  Exclude:
57
57
  - gemfiles/* # excluded as appraisal generates them with errors
58
58
  - lib/*
data/Rakefile CHANGED
@@ -3,7 +3,6 @@
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
5
  require 'rubocop/rake_task'
6
- require 'appraisal'
7
6
 
8
7
  Dir['tasks/**/*.rake'].each { |rake| load rake }
9
8
 
@@ -26,10 +25,4 @@ else
26
25
  end
27
26
  end
28
27
 
29
- if !ENV['APPRAISAL_INITIALIZED']
30
- task :default do
31
- sh 'appraisal install && rake appraisal && rake rubocop'
32
- end
33
- else
34
- task default: %i[spec rubocop]
35
- end
28
+ task default: %i[spec rubocop]
@@ -31,9 +31,9 @@ module SplitIoClient
31
31
  def uniques_formatter(uniques)
32
32
  return if uniques.nil? || uniques.empty?
33
33
 
34
- to_return = { mtks: [] }
34
+ to_return = { keys: [] }
35
35
  uniques.each do |key, value|
36
- to_return[:mtks] << {
36
+ to_return[:keys] << {
37
37
  f: key,
38
38
  ks: value.to_a
39
39
  }
@@ -29,8 +29,6 @@ module SplitIoClient
29
29
  impressions_count.each do |key, value|
30
30
  pipeline.hincrby(impressions_count_key, key, value)
31
31
  end
32
-
33
- @future = pipeline.hlen(impressions_count_key)
34
32
  end
35
33
 
36
34
  expire_impressions_count_key(impressions_count, result)
@@ -24,7 +24,7 @@ module SplitIoClient
24
24
  sleep(@config.counter_refresh_rate)
25
25
  post_impressions_count
26
26
  end
27
- rescue SplitIoClient::SDKShutdownException
27
+ rescue SplitIoClient::SDKShutdownException
28
28
  post_impressions_count
29
29
 
30
30
  @config.logger.info('Posting impressions count due to shutdown')
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'net/http/persistent'
4
-
5
3
  module SplitIoClient
6
4
  module Api
7
5
  class Client
@@ -54,33 +52,12 @@ module SplitIoClient
54
52
  private
55
53
 
56
54
  def api_client
57
- if needs_patched_net_http_persistent_adapter?
58
- require 'splitclient-rb/engine/api/faraday_adapter/patched_net_http_persistent'
59
-
60
- Faraday::Adapter.register_middleware(
61
- net_http_persistent: SplitIoClient::FaradayAdapter::PatchedNetHttpPersistent
62
- )
63
- end
64
-
65
55
  @api_client ||= Faraday.new do |builder|
66
56
  builder.use SplitIoClient::FaradayMiddleware::Gzip
67
57
  builder.adapter :net_http_persistent
68
58
  end
69
59
  end
70
60
 
71
- def needs_patched_net_http_persistent_adapter?
72
- new_net_http_persistent? && incompatible_faraday_version?
73
- end
74
-
75
- def incompatible_faraday_version?
76
- version = Faraday::VERSION.split('.')[0..1]
77
- version[0].to_i == 0 && version[1].to_i < 13
78
- end
79
-
80
- def new_net_http_persistent?
81
- Net::HTTP::Persistent::VERSION.split('.').first.to_i >= 3
82
- end
83
-
84
61
  def common_headers(api_key)
85
62
  {
86
63
  'Authorization' => "Bearer #{api_key}",
@@ -18,9 +18,9 @@ module SplitIoClient
18
18
  end
19
19
 
20
20
  def record_unique_keys(uniques)
21
- return if uniques[:mtks].empty?
21
+ return if uniques[:keys].empty?
22
22
 
23
- post_telemetry("#{@config.telemetry_service_url}/mtks/ss", uniques, 'mtks')
23
+ post_telemetry("#{@config.telemetry_service_url}/keys/ss", uniques, 'unique_keys')
24
24
  rescue StandardError => e
25
25
  @config.log_found_exception(__method__.to_s, e)
26
26
  end
@@ -9,15 +9,13 @@ module SplitIoClient
9
9
  impression_counter,
10
10
  telemetry_runtime_producer,
11
11
  impression_observer,
12
- unique_keys_tracker,
13
- impression_router)
12
+ unique_keys_tracker)
14
13
  @config = config
15
14
  @impressions_repository = impressions_repository
16
15
  @impression_counter = impression_counter
17
16
  @impression_observer = impression_observer
18
17
  @telemetry_runtime_producer = telemetry_runtime_producer
19
18
  @unique_keys_tracker = unique_keys_tracker
20
- @impression_router = impression_router
21
19
  end
22
20
 
23
21
  def build_impression(matching_key, bucketing_key, split_name, treatment, params = {})
@@ -58,12 +56,18 @@ module SplitIoClient
58
56
  @config.log_found_exception(__method__.to_s, e)
59
57
  ensure
60
58
  record_stats(stats)
61
- @impression_router.add_bulk(impressions)
59
+ impression_router.add_bulk(impressions)
62
60
  end
63
61
  end
64
62
 
65
63
  private
66
64
 
65
+ def impression_router
66
+ @impression_router ||= SplitIoClient::ImpressionRouter.new(@config)
67
+ rescue StandardError => error
68
+ @config.log_found_exception(__method__.to_s, error)
69
+ end
70
+
67
71
  def record_stats(stats)
68
72
  return if redis?
69
73
 
@@ -41,17 +41,20 @@ module SplitIoClient
41
41
  private
42
42
 
43
43
  def schedule_next_token_refresh(time)
44
- @config.threads[:schedule_next_token_refresh] = Thread.new do
45
- begin
46
- @config.logger.debug("schedule_next_token_refresh refresh in #{time} seconds.") if @config.debug_enabled
47
- sleep(time)
48
- @config.logger.debug('schedule_next_token_refresh starting ...') if @config.debug_enabled
49
- @sse_handler.stop
50
- start_sse
51
- rescue StandardError => e
52
- @config.logger.debug("schedule_next_token_refresh error: #{e.inspect}") if @config.debug_enabled
53
- end
54
- end
44
+ @config.threads[:schedule_next_token_refresh] = Thread.new { refresh_token_task(time) }
45
+ end
46
+
47
+ def refresh_token_task(time)
48
+ @config.logger.debug("schedule_next_token_refresh refresh in #{time} seconds.") if @config.debug_enabled
49
+
50
+ sleep(time)
51
+
52
+ @config.logger.debug('schedule_next_token_refresh starting ...') if @config.debug_enabled
53
+ @sse_handler.stop
54
+
55
+ start_sse
56
+ rescue StandardError => e
57
+ @config.logger.debug("schedule_next_token_refresh error: #{e.inspect}") if @config.debug_enabled
55
58
  end
56
59
 
57
60
  def record_telemetry(time)
@@ -51,7 +51,7 @@ module SplitIoClient
51
51
 
52
52
  @segments_refresh_rate = opts[:segments_refresh_rate] || SplitConfig.default_segments_refresh_rate
53
53
 
54
- @impressions_mode = init_impressions_mode(opts[:impressions_mode])
54
+ @impressions_mode = init_impressions_mode(opts[:impressions_mode], opts[:cache_adapter])
55
55
 
56
56
  @impressions_refresh_rate = SplitConfig.init_impressions_refresh_rate(@impressions_mode, opts[:impressions_refresh_rate], SplitConfig.default_impressions_refresh_rate)
57
57
  @impressions_queue_size = opts[:impressions_queue_size] || SplitConfig.default_impressions_queue_size
@@ -314,14 +314,16 @@ module SplitIoClient
314
314
  :optimized
315
315
  end
316
316
 
317
- def init_impressions_mode(impressions_mode)
317
+ def init_impressions_mode(impressions_mode, adapter)
318
318
  impressions_mode ||= SplitConfig.default_impressions_mode
319
319
 
320
+ return :debug if adapter == :redis
321
+
320
322
  case impressions_mode
321
323
  when :debug
322
324
  return :debug
323
- when :none
324
- return :none
325
+ # when :none // we not support :none impression mode yet. Defaulting to :optimized mode
326
+ # return :none
325
327
  else
326
328
  @logger.error('You passed an invalid impressions_mode, impressions_mode should be one of the following values: :debug or :optimized. Defaulting to :optimized mode') unless impressions_mode == :optimized
327
329
  return :optimized
@@ -65,7 +65,7 @@ module SplitIoClient
65
65
  build_streaming_components
66
66
  build_sync_manager
67
67
 
68
- @sync_manager.start if @config.valid_mode
68
+ @sync_manager.start
69
69
  end
70
70
 
71
71
  def stop!
@@ -127,10 +127,10 @@ module SplitIoClient
127
127
  def validate_api_key
128
128
  if(@api_key.nil?)
129
129
  @config.logger.error('Factory Instantiation: you passed a nil api_key, api_key must be a non-empty String')
130
- @config.valid_mode = false
130
+ @config.valid_mode = false
131
131
  elsif (@api_key.empty?)
132
132
  @config.logger.error('Factory Instantiation: you passed and empty api_key, api_key must be a non-empty String')
133
- @config.valid_mode = false
133
+ @config.valid_mode = false
134
134
  end
135
135
  end
136
136
 
@@ -249,8 +249,7 @@ module SplitIoClient
249
249
  build_impressions_observer
250
250
  build_impression_counter
251
251
 
252
- impression_router = ImpressionRouter.new(@config)
253
- @impressions_manager = Engine::Common::ImpressionManager.new(@config, @impressions_repository, @impression_counter, @runtime_producer, @impression_observer, @unique_keys_tracker, impression_router)
252
+ @impressions_manager = Engine::Common::ImpressionManager.new(@config, @impressions_repository, @impression_counter, @runtime_producer, @impression_observer, @unique_keys_tracker)
254
253
  end
255
254
  end
256
255
  end
@@ -11,12 +11,12 @@ module SplitIoClient
11
11
  def record_config(config_data)
12
12
  return if config_data.nil?
13
13
 
14
- data = { m: { i: @config.machine_ip, n: @config.machine_name, s: "#{@config.language}-#{@config.version}" },
15
- t: { oM: config_data.om, st: config_data.st, aF: config_data.af, rF: config_data.rf, t: config_data.t } }
14
+ data = { t: { oM: config_data.om, st: config_data.st, aF: config_data.af, rF: config_data.rf, t: config_data.t } }
15
+ field = "#{@config.language}-#{@config.version}/#{@config.machine_name}/#{@config.machine_ip}"
16
16
 
17
- @adapter.add_to_queue(config_key, data.to_json)
18
- rescue StandardError => error
19
- @config.log_found_exception(__method__.to_s, error)
17
+ @adapter.add_to_map(config_key, field, data.to_json)
18
+ rescue StandardError => e
19
+ @config.log_found_exception(__method__.to_s, e)
20
20
  end
21
21
 
22
22
  def record_bur_timeout
@@ -30,7 +30,7 @@ module SplitIoClient
30
30
  private
31
31
 
32
32
  def config_key
33
- "#{@config.redis_namespace}.telemetry.config"
33
+ "#{@config.redis_namespace}.telemetry.init"
34
34
  end
35
35
  end
36
36
  end
@@ -15,21 +15,21 @@ module SplitIoClient
15
15
  private
16
16
 
17
17
  def stats_thread
18
- @config.threads[:telemetry_stats_sender] = Thread.new do
19
- begin
20
- @config.logger.info('Starting Telemetry Sync Task')
18
+ @config.threads[:telemetry_stats_sender] = Thread.new { telemetry_sync_task }
19
+ end
21
20
 
22
- loop do
23
- sleep(@config.telemetry_refresh_rate)
21
+ def telemetry_sync_task
22
+ @config.logger.info('Starting Telemetry Sync Task')
24
23
 
25
- @telemetry_synchronizer.synchronize_stats
26
- end
27
- rescue SplitIoClient::SDKShutdownException
28
- @telemetry_synchronizer.synchronize_stats
24
+ loop do
25
+ sleep(@config.telemetry_refresh_rate)
29
26
 
30
- @config.logger.info('Posting Telemetry due to shutdown')
31
- end
27
+ @telemetry_synchronizer.synchronize_stats
32
28
  end
29
+ rescue SplitIoClient::SDKShutdownException
30
+ @telemetry_synchronizer.synchronize_stats
31
+
32
+ @config.logger.info('Posting Telemetry due to shutdown')
33
33
  end
34
34
  end
35
35
  end
@@ -1,3 +1,3 @@
1
1
  module SplitIoClient
2
- VERSION = '7.3.5.pre.rc3'
2
+ VERSION = '8.0.0.pre.rc1'
3
3
  end
@@ -49,7 +49,6 @@ require 'splitclient-rb/validators'
49
49
  require 'splitclient-rb/split_factory_registry'
50
50
 
51
51
  require 'splitclient-rb/engine/api/faraday_middleware/gzip'
52
- require 'splitclient-rb/engine/api/faraday_adapter/patched_net_http_persistent'
53
52
  require 'splitclient-rb/engine/api/client'
54
53
  require 'splitclient-rb/engine/api/impressions'
55
54
  require 'splitclient-rb/engine/api/segments'
@@ -8,16 +8,15 @@ Gem::Specification.new do |spec|
8
8
  spec.name = 'splitclient-rb'
9
9
  spec.version = SplitIoClient::VERSION
10
10
  spec.authors = ['Split Software']
11
- spec.email = ['pato@split.io']
12
-
11
+ spec.email = ['mauro.sanz@split.io']
13
12
  spec.summary = 'Ruby client for split SDK.'
14
13
  spec.description = 'Ruby client for using split SDK.'
15
14
  spec.homepage = 'https://github.com/splitio/ruby-client'
16
15
  spec.license = 'Apache-2.0'
17
16
 
18
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|features|ext)/}) }
19
-
20
18
  spec.require_paths = ['lib']
19
+ spec.required_ruby_version = '>= 2.5.0'
21
20
 
22
21
  if defined?(JRUBY_VERSION)
23
22
  spec.platform = 'java'
@@ -37,11 +36,10 @@ Gem::Specification.new do |spec|
37
36
  end
38
37
 
39
38
  spec.add_development_dependency 'allocation_stats', '~> 0.1'
40
- spec.add_development_dependency 'appraisal', '~> 2.4'
41
39
  spec.add_development_dependency 'bundler', '~> 2.2'
42
40
  spec.add_development_dependency 'pry', '~> 0.14'
43
41
  spec.add_development_dependency 'pry-nav', '~> 1.0'
44
- spec.add_development_dependency 'rake', '~> 12.3'
42
+ spec.add_development_dependency 'rake', '~> 13.0'
45
43
  spec.add_development_dependency 'rake-compiler', '~> 1.1'
46
44
  spec.add_development_dependency 'rspec', '~> 3.10'
47
45
  spec.add_development_dependency 'rubocop', '0.59.0'
@@ -49,10 +47,11 @@ Gem::Specification.new do |spec|
49
47
  spec.add_development_dependency 'simplecov-json', '~> 0.2'
50
48
  spec.add_development_dependency 'timecop', '~> 0.9'
51
49
  spec.add_development_dependency 'webmock', '~> 3.14'
50
+ spec.add_development_dependency 'webrick', '~> 1.7'
52
51
 
53
52
  spec.add_runtime_dependency 'bitarray', '~> 1.3'
54
53
  spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
55
- spec.add_runtime_dependency 'faraday', '>= 0.8', '< 2.0'
54
+ spec.add_runtime_dependency 'faraday', '>= 1.1', '< 2.0'
56
55
  spec.add_runtime_dependency 'json', '>= 1.8', '< 3.0'
57
56
  spec.add_runtime_dependency 'jwt', '>= 1.0.0', '< 3.0'
58
57
  spec.add_runtime_dependency 'lru_redux', '~> 1.1'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: splitclient-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.3.5.pre.rc3
4
+ version: 8.0.0.pre.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Split Software
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-12 00:00:00.000000000 Z
11
+ date: 2022-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: allocation_stats
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.1'
27
- - !ruby/object:Gem::Dependency
28
- name: appraisal
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '2.4'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '2.4'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +72,14 @@ dependencies:
86
72
  requirements:
87
73
  - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: '12.3'
75
+ version: '13.0'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
- version: '12.3'
82
+ version: '13.0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: rake-compiler
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -192,6 +178,20 @@ dependencies:
192
178
  - - "~>"
193
179
  - !ruby/object:Gem::Version
194
180
  version: '3.14'
181
+ - !ruby/object:Gem::Dependency
182
+ name: webrick
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '1.7'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '1.7'
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: bitarray
197
197
  requirement: !ruby/object:Gem::Requirement
@@ -226,7 +226,7 @@ dependencies:
226
226
  requirements:
227
227
  - - ">="
228
228
  - !ruby/object:Gem::Version
229
- version: '0.8'
229
+ version: '1.1'
230
230
  - - "<"
231
231
  - !ruby/object:Gem::Version
232
232
  version: '2.0'
@@ -236,7 +236,7 @@ dependencies:
236
236
  requirements:
237
237
  - - ">="
238
238
  - !ruby/object:Gem::Version
239
- version: '0.8'
239
+ version: '1.1'
240
240
  - - "<"
241
241
  - !ruby/object:Gem::Version
242
242
  version: '2.0'
@@ -370,7 +370,7 @@ dependencies:
370
370
  version: '0.3'
371
371
  description: Ruby client for using split SDK.
372
372
  email:
373
- - pato@split.io
373
+ - mauro.sanz@split.io
374
374
  executables: []
375
375
  extensions:
376
376
  - ext/murmurhash/extconf.rb
@@ -382,7 +382,6 @@ files:
382
382
  - ".gitignore"
383
383
  - ".rubocop.yml"
384
384
  - ".simplecov"
385
- - Appraisals
386
385
  - CHANGES.txt
387
386
  - CONTRIBUTORS-GUIDE.md
388
387
  - Gemfile
@@ -437,7 +436,6 @@ files:
437
436
  - lib/splitclient-rb/constants.rb
438
437
  - lib/splitclient-rb/engine/api/client.rb
439
438
  - lib/splitclient-rb/engine/api/events.rb
440
- - lib/splitclient-rb/engine/api/faraday_adapter/patched_net_http_persistent.rb
441
439
  - lib/splitclient-rb/engine/api/faraday_middleware/gzip.rb
442
440
  - lib/splitclient-rb/engine/api/impressions.rb
443
441
  - lib/splitclient-rb/engine/api/segments.rb
@@ -540,14 +538,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
540
538
  requirements:
541
539
  - - ">="
542
540
  - !ruby/object:Gem::Version
543
- version: '0'
541
+ version: 2.5.0
544
542
  required_rubygems_version: !ruby/object:Gem::Requirement
545
543
  requirements:
546
544
  - - ">"
547
545
  - !ruby/object:Gem::Version
548
546
  version: 1.3.1
549
547
  requirements: []
550
- rubygems_version: 3.2.32
548
+ rubygems_version: 3.3.5
551
549
  signing_key:
552
550
  specification_version: 4
553
551
  summary: Ruby client for split SDK.
data/Appraisals DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- appraise 'faraday-before-0.13' do
4
- gem 'faraday', '>= 0.9', '< 0.13'
5
- gem 'net-http-persistent', '~> 3.0'
6
- end
7
-
8
- appraise 'faraday-after-0.13' do
9
- gem 'faraday', '> 0.13'
10
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SplitIoClient
4
- module FaradayAdapter
5
- class PatchedNetHttpPersistent < Faraday::Adapter::NetHttpPersistent
6
- ##
7
- # Borrowed directly from the latest `NetHttpPersistent` adapter implementation.
8
- #
9
- # https://github.com/lostisland/faraday/blob/master/lib/faraday/adapter/net_http_persistent.rb
10
- #
11
- def net_http_connection(env)
12
- @cached_connection ||=
13
- if Net::HTTP::Persistent.instance_method(:initialize).parameters.first == [:key, :name]
14
- Net::HTTP::Persistent.new(name: 'Faraday')
15
- else
16
- Net::HTTP::Persistent.new('Faraday')
17
- end
18
-
19
- proxy_uri = proxy_uri(env)
20
- @cached_connection.proxy = proxy_uri if @cached_connection.proxy_uri != proxy_uri
21
- @cached_connection
22
- end
23
-
24
- def proxy_uri(env)
25
- proxy_uri = nil
26
- if (proxy = env[:request][:proxy])
27
- proxy_uri = ::URI::HTTP === proxy[:uri] ? proxy[:uri].dup : ::URI.parse(proxy[:uri].to_s)
28
- proxy_uri.user = proxy_uri.password = nil
29
- # awful patch for net-http-persistent 2.8 not unescaping user/password
30
- (
31
- class << proxy_uri;
32
- self;
33
- end).class_eval do
34
- define_method(:user) { proxy[:user] }
35
- define_method(:password) { proxy[:password] }
36
- end if proxy[:user]
37
- end
38
- proxy_uri
39
- end
40
-
41
- def with_net_http_connection(env)
42
- yield net_http_connection(env)
43
- end
44
- end
45
- end
46
- end