dagger 2.2.0 → 2.3.0

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: b5435e1639eeb130ce413215a7406e3db0c431dc3d4291cfcedc6373eae61d67
4
- data.tar.gz: 0e8d27e62e1d14a704599f913ca634a324edc118c7433e644d6538fdefa715fe
3
+ metadata.gz: 10733130d8f24aa8ba7fb7e27837fdc34ab854348aed2e82a09347c039689b2d
4
+ data.tar.gz: 9e3c600a111cdd1cf7090b8b48aa1103fa48e1f763588623902a9bb9daa704b6
5
5
  SHA512:
6
- metadata.gz: 478af3e55a32f1abe612c2724d70a0d9df80acf6adef53ef7fe31e402d19db1d13416e5ffbf465240b3afa1644a3603b48b1fb9a63f3b02013178327ab4f6390
7
- data.tar.gz: d463ab826e62bb5a282ea696ac780b56d69de58a0bdb200c00d645a27516c477c03ee08324b93716ec185cad7c9683caf2885b558c32069247fb2d602db6eb4e
6
+ metadata.gz: c1d486fd374676a0f1892dfc98e89048729941a4ba10c0f207ebc87fefc100fe3ed172b31a3ba9d238124c1d8d8dfd01d3deda79b06eb93e7a60c04d67fbf7c6
7
+ data.tar.gz: fefd2e08f939a0dcfe8ba1c52c8e07c20eda4cdf921d120393cd4e52ade3002180ef29329ce2f9f1085ad27e2785cf76dc00a90cc499ba3724ac057a487c46b4
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
1
  pkg
2
+ .ruby-version
3
+ Gemfile.lock
data/dagger.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_development_dependency "rspec-mocks"
20
20
  s.add_development_dependency "rspec-expectations"
21
21
 
22
+ s.add_runtime_dependency "net-http-persistent", ">= 3.0"
22
23
  s.add_runtime_dependency "oj", ">= 2.1"
23
24
  s.add_runtime_dependency "ox", ">= 2.4"
24
25
 
@@ -1,3 +1,5 @@
1
+ # unused (we're using Net::HTTP::Persistent again)
2
+
1
3
  module Dagger
2
4
 
3
5
  class ConnectionManager
@@ -41,7 +43,7 @@ module Dagger
41
43
 
42
44
  # Executes an HTTP request to the given URI with the given method. Also
43
45
  # allows a request body, headers, and query string to be specified.
44
- def send_request(uri, request)
46
+ def request(uri, request)
45
47
  connection = connection_for(uri)
46
48
  @mutex.synchronize do
47
49
  begin
@@ -1,6 +1,6 @@
1
1
  module Dagger
2
2
  MAJOR = 2
3
- MINOR = 2
3
+ MINOR = 3
4
4
  PATCH = 0
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].join('.')
data/lib/dagger.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'dagger/version'
2
2
  require 'dagger/response'
3
3
  require 'dagger/parsers'
4
- require 'dagger/connection_manager'
4
+ require 'net/http/persistent'
5
+ # require 'dagger/connection_manager' # unused
5
6
  require 'net/https'
6
7
  require 'base64'
7
8
  require 'erb'
@@ -79,25 +80,20 @@ module Dagger
79
80
 
80
81
  class Client
81
82
 
82
- def self.init_persistent(opts = {})
83
- # this line below forces one connection manager between multiple threads
84
- # @persistent ||= Dagger::ConnectionManager.new(opts)
85
-
86
- # here we initialize a connection manager for each thread
87
- Thread.current[:dagger_persistent] ||= begin
88
- Dagger::ConnectionManager.new(opts)
89
- end
90
- end
91
-
92
83
  def self.init_connection(uri, opts = {})
93
- http = Net::HTTP.new(opts[:ip] || uri.host, uri.port)
84
+ http = if opts.delete(:persistent)
85
+ pool_size = opts[:pool_size] || Net::HTTP::Persistent::DEFAULT_POOL_SIZE
86
+ Net::HTTP::Persistent.new(name: DAGGER_NAME, pool_size: pool_size)
87
+ else
88
+ Net::HTTP.new(opts[:ip] || uri.host, uri.port)
89
+ end
94
90
 
95
91
  if uri.port == 443 || uri.scheme == 'https'
96
92
  http.use_ssl = true if http.respond_to?(:use_ssl=) # persistent does it automatically
97
93
  http.verify_mode = opts[:verify_ssl] === false ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
98
94
  end
99
95
 
100
- [:keep_alive_timeout, :open_timeout, :read_timeout, :ssl_version, :ciphers].each do |key|
96
+ [:open_timeout, :read_timeout, :ssl_version, :ciphers].each do |key|
101
97
  http.send("#{key}=", opts[key] || DEFAULTS[key]) if (opts.has_key?(key) || DEFAULTS.has_key?(key))
102
98
  end
103
99
 
@@ -106,12 +102,7 @@ module Dagger
106
102
 
107
103
  def self.init(uri, opts)
108
104
  uri = Utils.parse_uri(uri)
109
-
110
- http = if opts.delete(:persistent)
111
- init_persistent(opts)
112
- else
113
- init_connection(uri, opts)
114
- end
105
+ http = init_connection(uri, opts)
115
106
 
116
107
  new(http, uri.scheme_and_host)
117
108
  end
@@ -137,6 +128,8 @@ module Dagger
137
128
  uri = opts[:ip]
138
129
  end
139
130
 
131
+ debug { "Sending GET request to #{uri.request_uri} with headers #{headers.inspect} -- #{opts[:body]}" }
132
+
140
133
  request = Net::HTTP::Get.new(uri, DEFAULT_HEADERS.merge(headers))
141
134
  request.basic_auth(opts.delete(:username), opts.delete(:password)) if opts[:username]
142
135
  request.body = Utils.encode_body(opts[:body], opts) if opts[:body] && opts[:body].size > 0
@@ -145,7 +138,7 @@ module Dagger
145
138
  @http.start unless @http.started?
146
139
  resp, data = @http.request(request)
147
140
  else # persistent
148
- resp, data = @http.send_request(uri, request)
141
+ resp, data = @http.request(uri, request)
149
142
  end
150
143
 
151
144
  if REDIRECT_CODES.include?(resp.code.to_i) && resp['Location'] && (opts[:follow] && opts[:follow] > 0)
@@ -210,7 +203,7 @@ module Dagger
210
203
  end
211
204
 
212
205
  start = Time.now
213
- debug { "Sending #{method} request to #{uri.request_uri} with headers #{headers.inspect} -- #{query}" }
206
+ debug { "Sending #{method} request to #{uri.request_uri} with headers #{headers.inspect} -- #{data}" }
214
207
 
215
208
  if @http.respond_to?(:started?) # regular Net::HTTP
216
209
  args = [method.to_s.downcase, uri.request_uri, body, headers]
@@ -221,7 +214,7 @@ module Dagger
221
214
  else # Net::HTTP::Persistent
222
215
  req = Kernel.const_get("Net::HTTP::#{method.capitalize}").new(uri.request_uri, headers)
223
216
  req.body = body
224
- resp, data = @http.send_request(uri, req)
217
+ resp, data = @http.request(uri, req)
225
218
  end
226
219
 
227
220
  debug { "Got response #{resp.code} in #{(Time.now - start).round(2)}s: #{data || resp.body}" }
@@ -245,7 +238,7 @@ module Dagger
245
238
  end
246
239
 
247
240
  def open(&block)
248
- if @http.is_a?(Dagger::ConnectionManager)
241
+ if @http.is_a?(Net::HTTP::Persistent)
249
242
  instance_eval(&block)
250
243
  else
251
244
  @http.start do
@@ -255,7 +248,7 @@ module Dagger
255
248
  end
256
249
 
257
250
  def close
258
- if @http.is_a?(Dagger::ConnectionManager)
251
+ if @http.is_a?(Net::HTTP::Persistent)
259
252
  @http.shutdown # calls finish on pool connections
260
253
  else
261
254
  @http.finish if @http.started?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-23 00:00:00.000000000 Z
11
+ date: 2023-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: net-http-persistent
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: oj
71
85
  requirement: !ruby/object:Gem::Requirement