dagger 2.1.1 → 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: 5942c147bb4bcf52ad8d1aa04cb5a44010eb15a6c85877a71b68872d745710c2
4
- data.tar.gz: 14654c7a309a5719f0b23d136f62f67a6e995b9ac0d6dff0e697b628acf57f35
3
+ metadata.gz: 10733130d8f24aa8ba7fb7e27837fdc34ab854348aed2e82a09347c039689b2d
4
+ data.tar.gz: 9e3c600a111cdd1cf7090b8b48aa1103fa48e1f763588623902a9bb9daa704b6
5
5
  SHA512:
6
- metadata.gz: 4f71ee8900cc198365cb0ec64176b0861ebe9e8c295a407b048d6c712806f80453770f336e0b518a3f87338b34be4a110963bfb978fdaafec80b54a885d79466
7
- data.tar.gz: ec8bc6f7f374466b4d73fdb5cca061b2cab17918818d72e28c7b03b728cdfe5328e04a79584c483a223dbec2ec767dc10a9e0e562152d561f55c24db3b08bd0e
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,7 +1,7 @@
1
1
  module Dagger
2
2
  MAJOR = 2
3
- MINOR = 1
4
- PATCH = 1
3
+ MINOR = 3
4
+ PATCH = 0
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].join('.')
7
7
  end
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'
@@ -47,6 +48,7 @@ module Dagger
47
48
  end
48
49
 
49
50
  def self.encode_body(obj, opts = {})
51
+ return if obj.nil? || obj.empty?
50
52
  if obj.is_a?(String)
51
53
  obj
52
54
  elsif opts[:json]
@@ -78,25 +80,20 @@ module Dagger
78
80
 
79
81
  class Client
80
82
 
81
- def self.init_persistent(opts = {})
82
- # this line below forces one connection manager between multiple threads
83
- # @persistent ||= Dagger::ConnectionManager.new(opts)
84
-
85
- # here we initialize a connection manager for each thread
86
- Thread.current[:dagger_persistent] ||= begin
87
- Dagger::ConnectionManager.new(opts)
88
- end
89
- end
90
-
91
83
  def self.init_connection(uri, opts = {})
92
- 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
93
90
 
94
91
  if uri.port == 443 || uri.scheme == 'https'
95
92
  http.use_ssl = true if http.respond_to?(:use_ssl=) # persistent does it automatically
96
93
  http.verify_mode = opts[:verify_ssl] === false ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
97
94
  end
98
95
 
99
- [:keep_alive_timeout, :open_timeout, :read_timeout, :ssl_version, :ciphers].each do |key|
96
+ [:open_timeout, :read_timeout, :ssl_version, :ciphers].each do |key|
100
97
  http.send("#{key}=", opts[key] || DEFAULTS[key]) if (opts.has_key?(key) || DEFAULTS.has_key?(key))
101
98
  end
102
99
 
@@ -105,12 +102,7 @@ module Dagger
105
102
 
106
103
  def self.init(uri, opts)
107
104
  uri = Utils.parse_uri(uri)
108
-
109
- http = if opts.delete(:persistent)
110
- init_persistent(opts)
111
- else
112
- init_connection(uri, opts)
113
- end
105
+ http = init_connection(uri, opts)
114
106
 
115
107
  new(http, uri.scheme_and_host)
116
108
  end
@@ -129,22 +121,24 @@ module Dagger
129
121
  opts[:follow] = 10 if opts[:follow] == true
130
122
  headers = opts[:headers] || {}
131
123
  headers['Accept'] = 'application/json' if opts[:json] && headers['Accept'].nil?
132
- headers['Content-Type'] = 'application/json' if opts[:json] && opts[:body]
124
+ headers['Content-Type'] = 'application/json' if opts[:json] && opts[:body] && opts[:body].size > 0
133
125
 
134
126
  if opts[:ip]
135
127
  headers['Host'] = uri.host
136
128
  uri = opts[:ip]
137
129
  end
138
130
 
131
+ debug { "Sending GET request to #{uri.request_uri} with headers #{headers.inspect} -- #{opts[:body]}" }
132
+
139
133
  request = Net::HTTP::Get.new(uri, DEFAULT_HEADERS.merge(headers))
140
134
  request.basic_auth(opts.delete(:username), opts.delete(:password)) if opts[:username]
141
- request.body = Utils.encode_body(opts[:body], opts) if opts[:body]
135
+ request.body = Utils.encode_body(opts[:body], opts) if opts[:body] && opts[:body].size > 0
142
136
 
143
137
  if @http.respond_to?(:started?) # regular Net::HTTP
144
138
  @http.start unless @http.started?
145
139
  resp, data = @http.request(request)
146
140
  else # persistent
147
- resp, data = @http.send_request(uri, request)
141
+ resp, data = @http.request(uri, request)
148
142
  end
149
143
 
150
144
  if REDIRECT_CODES.include?(resp.code.to_i) && resp['Location'] && (opts[:follow] && opts[:follow] > 0)
@@ -209,7 +203,7 @@ module Dagger
209
203
  end
210
204
 
211
205
  start = Time.now
212
- 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}" }
213
207
 
214
208
  if @http.respond_to?(:started?) # regular Net::HTTP
215
209
  args = [method.to_s.downcase, uri.request_uri, body, headers]
@@ -220,7 +214,7 @@ module Dagger
220
214
  else # Net::HTTP::Persistent
221
215
  req = Kernel.const_get("Net::HTTP::#{method.capitalize}").new(uri.request_uri, headers)
222
216
  req.body = body
223
- resp, data = @http.send_request(uri, req)
217
+ resp, data = @http.request(uri, req)
224
218
  end
225
219
 
226
220
  debug { "Got response #{resp.code} in #{(Time.now - start).round(2)}s: #{data || resp.body}" }
@@ -244,7 +238,7 @@ module Dagger
244
238
  end
245
239
 
246
240
  def open(&block)
247
- if @http.is_a?(Dagger::ConnectionManager)
241
+ if @http.is_a?(Net::HTTP::Persistent)
248
242
  instance_eval(&block)
249
243
  else
250
244
  @http.start do
@@ -254,7 +248,7 @@ module Dagger
254
248
  end
255
249
 
256
250
  def close
257
- if @http.is_a?(Dagger::ConnectionManager)
251
+ if @http.is_a?(Net::HTTP::Persistent)
258
252
  @http.shutdown # calls finish on pool connections
259
253
  else
260
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.1.1
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-04-19 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