restify 1.15.1 → 1.15.2

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: 95d9cf12fd58e2f17bd1d3c046dfda23eaa38ec2fb99fe0c9b7e1034e014cd1f
4
- data.tar.gz: b995cf5d935ba1c83b403fedf18d4c35154ea0ad60d4be0437fa98c89281d687
3
+ metadata.gz: c29c95a9b1c0b18f2a73b51c99da7cdddf163e1cee33c43272810f5557b1375b
4
+ data.tar.gz: 95f956684154058cc6f25b7d4ffebde6706864b00c1369e91c8f8b5fcc50f0d9
5
5
  SHA512:
6
- metadata.gz: 96b5f22cc74ca967876f2ecc86bf30c70fa21ceee6f8726117862ad0e94a6319a9384673cd83a4222bd40b49f4b6eeb48cdec7bd5d1e94ac70fcdab787a8ed5b
7
- data.tar.gz: 98199df1ecf1b9467b609ae57f58f2ae459f42f7121c1947763a9d49acb7224d6b8dc50088e74cd7f563719fb81f507d88fca2252a823856e57bbf995db5cbbe
6
+ metadata.gz: f420cc4d0c4ebbdade1bc1a780c24218b5eea707bd8e420c113d155d58067936464dc3d4807717de8f515ed586784c9f13476b46c66f68c8d1181501937db3a2
7
+ data.tar.gz: 71da11cdf50d25abc968af02c6157c63f1aa5703c88f7ae28c3394aa028d9f038013d220283510532f7b540dffc69d0abad5fe4952c4e27df4910a4009475ae5
data/CHANGELOG.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Changelog
2
+
2
3
  All notable changes to this project will be documented in this file.
3
4
 
4
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
6
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
7
 
7
8
 
8
-
9
9
  ## Unreleased
10
10
  ---
11
11
 
@@ -18,163 +18,227 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
18
18
  ### Breaks
19
19
 
20
20
 
21
+ ## 1.15.2 - (2021-12-23)
22
+
23
+ ---
24
+
25
+ ### Fixes
26
+
27
+ - ActiveSupport v7.0 issues with cache module
28
+
29
+
21
30
  ## 1.15.1 - (2021-07-15)
31
+
22
32
  ---
23
33
 
24
34
  ### Fixes
25
- * Typhoeus internal exception when request timed out
26
35
 
36
+ - Typhoeus internal exception when request timed out
27
37
 
28
38
  ## 1.15.0 - (2021-07-09)
39
+
29
40
  ---
30
41
 
31
42
  ### New
32
- * Improve memory usage when running lots of requests with typhoeus adapter
33
- * Use hydra for synchronous requests
34
- * Increased thread stability of typhoeus adapter (new internal queuing mechanism)
43
+
44
+ - Improve memory usage when running lots of requests with typhoeus adapter
45
+ - Use hydra for synchronous requests
46
+ - Increased thread stability of typhoeus adapter (new internal queuing mechanism)
35
47
 
36
48
  ### Changes
37
- * Use Ruby 2.5 as baseline for testing and linting
38
- * Add Ruby 3.0 to automated testing
39
- * Changed timing behavior for multiple requests due to new internal queuing mechanism for the typhoeus adapter
40
49
 
50
+ - Use Ruby 2.5 as baseline for testing and linting
51
+ - Add Ruby 3.0 to automated testing
52
+ - Changed timing behavior for multiple requests due to new internal queuing mechanism for the typhoeus adapter
41
53
 
42
54
  ## 1.14.0 - (2020-12-15)
55
+
43
56
  ---
44
57
 
45
58
  ### New
46
- * Allow making requests with non-JSON bodies and custom content types (#42)
47
59
 
60
+ - Allow making requests with non-JSON bodies and custom content types (#42)
48
61
 
49
62
  ## 1.13.0 - (2020-06-12)
63
+
50
64
  ---
51
65
 
52
66
  ### New
53
- * typhoeus: Support setting per-request libcurl options on adapter
54
- * typhoeus: Enable short TCP keepalive probes by default (5s/5s)
55
67
 
68
+ - typhoeus: Support setting per-request libcurl options on adapter
69
+ - typhoeus: Enable short TCP keepalive probes by default (5s/5s)
56
70
 
57
71
  ## 1.12.0 - (2020-04-01)
72
+
58
73
  ---
59
74
 
60
75
  ### Added
61
- * Explicit exception class for HTTP status code 410 (Gone)
76
+
77
+ - Explicit exception class for HTTP status code 410 (Gone)
62
78
 
63
79
  ### Changed
64
80
 
65
81
  ### Fixed
66
- * `GatewayError` exception classes introduced in v1.11.0 now properly inherit from `ServerError` (#30)
67
82
 
83
+ - `GatewayError` exception classes introduced in v1.11.0 now properly inherit from `ServerError` (#30)
68
84
 
69
85
  ## 1.11.0 - (2019-07-11)
86
+
70
87
  ### Added
71
- * Explicit exception classes for HTTP status codes 500, 502, 503, 504
88
+
89
+ - Explicit exception classes for HTTP status codes 500, 502, 503, 504
72
90
 
73
91
  ## 1.10.0 - 2018-12-11
92
+
74
93
  ### Changed
94
+
75
95
  - Raise more specific error on a few status codes (#17)
76
96
  - Complete promises with an empty list (but a list) of dependencies (#18)
77
97
 
78
98
  ## 1.9.0 - 2018-11-13
99
+
79
100
  ### Changed
101
+
80
102
  - Do not raise error on 3XX responses but return responses
81
103
 
82
104
  ## 1.8.0 - 2018-08-22
105
+
83
106
  ### Added
107
+
84
108
  - Add HEAD request method (#16)
85
109
 
86
110
  ## 1.7.0 - 2018-08-15
111
+
87
112
  ### Added
113
+
88
114
  - Introduce promise dependency timeouts (#15)
89
115
 
90
116
  ## 1.6.0 - 2018-08-09
117
+
91
118
  ### Changed
119
+
92
120
  - Specify headers on restify clients and individual requests (#14)
93
121
 
94
122
  ## 1.5.0 - 2018-07-31
123
+
95
124
  ### Added
125
+
96
126
  - Add MessagePack processor enabled by default
97
127
 
98
128
  ### Changed
129
+
99
130
  - Tune typhoeus adapter to be more race-condition resilent
100
131
 
101
132
  ## 1.4.4 - 2018-07-13
133
+
102
134
  ### Added
135
+
103
136
  - Add `#request` to `NetworkError` to ease debugging
104
137
 
105
138
  ### Changed
139
+
106
140
  - Fix race condition in typhoeus adapter
107
141
 
108
142
  ## 1.4.3 - 2017-11-15
143
+
109
144
  ### Added
145
+
110
146
  - Add advanced logging capabilities using logging gem
111
147
 
112
148
  ### Changed
149
+
113
150
  - Improve compatibility with webmocks returning `nil` as headers
114
151
 
115
152
  ## 1.4.1 - 2017-11-15
153
+
116
154
  ### Changed
155
+
117
156
  - Fix possible deadlock issues
118
157
 
119
158
  ## 1.4.0 - 2017-11-10
159
+
120
160
  ### Added
161
+
121
162
  - Add timeout option to requests (only supported by typhoeus adapter)
122
163
 
123
164
  ### Changed
165
+
124
166
  - Fix possible concurrency issue with typhoeus adapter
125
167
 
126
168
  ## 1.3.1 - 2017-11-10
169
+
127
170
  ### Changed
171
+
128
172
  - Improve typhoeus adapters initial request queuing
129
173
  - Disable default pipelining
130
174
 
131
175
  ## 1.3.0 - 2017-11-08
176
+
132
177
  ### Changed
178
+
133
179
  - Improve typhoeus adapter to better utilize concurrency
134
180
  - Default to new typhoeus adapter
135
181
 
136
182
  ## 1.2.1 - 2017-10-30
183
+
137
184
  ### Changed
185
+
138
186
  - Fix issue with Ruby 2.2 compatibility
139
187
 
140
188
  ## 1.2.0 - 2017-10-30
189
+
141
190
  ### Added
191
+
142
192
  - Add experimental PooledEM adapter (#10)
143
193
 
144
194
  ### Changed
195
+
145
196
  - Improve marshaling of resources
146
197
 
147
198
  ## 1.1.0 - 2017-05-12
199
+
148
200
  ### Added
201
+
149
202
  - Add shortcuts for creating fulfilled / rejected promises (#6)
150
203
 
151
204
  ### Changed
205
+
152
206
  - Return response body if no processor matches (#7)
153
207
 
154
208
  ## 1.0.0 - 2016-08-22
209
+
155
210
  ### Added
211
+
156
212
  - Experimental cache API doing nothing for now
157
213
 
158
214
  ### Changed
215
+
159
216
  - Use `~> 1.0` of `concurrent-ruby`
160
217
 
161
218
  ## 0.5.0 - 2016-04-04
219
+
162
220
  ### Added
221
+
163
222
  - Add `sync` option to typhoeus adapter
164
223
  - Add registry for storing entry points
165
224
 
166
225
  ### Changed
226
+
167
227
  - Make eventmachine based adapter default
168
228
 
169
229
  ## 0.4.0 - 2016-02-24
230
+
170
231
  ### Added
232
+
171
233
  - Add method to explicit access resource data
172
234
 
173
235
  ### Changed
236
+
174
237
  - Use typhoeus as default adapter
175
238
  - `Restify.new` returns relation now instead of resource
176
239
 
177
240
  ### Removed
241
+
178
242
  - Drop obligation in favor of simple Concurrent::IVar based promise class.
179
243
  Notable changes:
180
244
  - Returned object us of type `Restify::Promise` now.
@@ -29,7 +29,7 @@ module Restify
29
29
  end
30
30
 
31
31
  # rubocop:disable Style/IdenticalConditionalBranches
32
- def call(request, writer, retried = false)
32
+ def call(request, writer, retried: false)
33
33
  if requests.empty?
34
34
  requests << [request, writer, retried]
35
35
  process_next
@@ -47,10 +47,6 @@ module Restify
47
47
  @pipeline
48
48
  end
49
49
 
50
- # rubocop:disable Metrics/AbcSize
51
- # rubocop:disable Metrics/CyclomaticComplexity
52
- # rubocop:disable Metrics/MethodLength
53
- # rubocop:disable Metrics/PerceivedComplexity
54
50
  def process_next
55
51
  return if requests.empty?
56
52
 
@@ -77,7 +73,7 @@ module Restify
77
73
  req.last_effective_url,
78
74
  req.response_header.status,
79
75
  req.response_header,
80
- req.response
76
+ req.response,
81
77
  )
82
78
 
83
79
  if req.response_header['CONNECTION'] == 'close'
@@ -108,7 +104,6 @@ module Restify
108
104
  end
109
105
  end
110
106
  end
111
- # rubocop:enable all
112
107
  end
113
108
 
114
109
  def call_native(request, writer)
@@ -128,7 +123,7 @@ module Restify
128
123
  return if EventMachine.reactor_running?
129
124
 
130
125
  Thread.new do
131
- EventMachine.run {}
126
+ EventMachine.run
132
127
  rescue StandardError => e
133
128
  puts "#{self.class} -> #{e}\n#{e.backtrace.join("\n")}"
134
129
  raise e
@@ -164,7 +164,7 @@ module Restify
164
164
  def new(origin)
165
165
  logger.debug do
166
166
  "Connect to '#{origin}' " \
167
- "(#{@connect_timeout}/#{@inactivity_timeout})..."
167
+ "(#{@connect_timeout}/#{@inactivity_timeout})..."
168
168
  end
169
169
 
170
170
  @host[origin] += 1
@@ -197,11 +197,10 @@ module Restify
197
197
  end
198
198
 
199
199
  def initialize(**kwargs)
200
+ super()
200
201
  @pool = Pool.new(**kwargs)
201
202
  end
202
203
 
203
- # rubocop:disable Metrics/MethodLength
204
- # rubocop:disable Metrics/AbcSize
205
204
  # rubocop:disable Metrics/BlockLength
206
205
  def call_native(request, writer)
207
206
  next_tick do
@@ -226,7 +225,7 @@ module Restify
226
225
  req.last_effective_url,
227
226
  req.response_header.status,
228
227
  req.response_header,
229
- req.response
228
+ req.response,
230
229
  )
231
230
 
232
231
  if req.response_header['CONNECTION'] == 'close'
@@ -259,7 +258,7 @@ module Restify
259
258
  return if EventMachine.reactor_running?
260
259
 
261
260
  Thread.new do
262
- EventMachine.run {}
261
+ EventMachine.run
263
262
  rescue StandardError => e
264
263
  logger.error(e)
265
264
  raise e
@@ -13,14 +13,14 @@ module Restify
13
13
 
14
14
  DEFAULT_HEADERS = {
15
15
  'Expect' => '',
16
- 'Transfer-Encoding' => ''
16
+ 'Transfer-Encoding' => '',
17
17
  }.freeze
18
18
 
19
19
  DEFAULT_OPTIONS = {
20
20
  followlocation: true,
21
21
  tcp_keepalive: true,
22
22
  tcp_keepidle: 5,
23
- tcp_keepintvl: 5
23
+ tcp_keepintvl: 5,
24
24
  }.freeze
25
25
 
26
26
  def initialize(sync: false, options: {}, **kwargs)
@@ -38,7 +38,6 @@ module Restify
38
38
  @sync
39
39
  end
40
40
 
41
- # rubocop:disable Metrics/MethodLength
42
41
  def call_native(request, writer)
43
42
  req = convert(request, writer)
44
43
 
@@ -57,12 +56,9 @@ module Restify
57
56
  thread.run unless thread.status
58
57
  end
59
58
  end
60
- # rubocop:enable Metrics/MethodLength
61
59
 
62
60
  private
63
61
 
64
- # rubocop:disable Metrics/AbcSize
65
- # rubocop:disable Metrics/MethodLength
66
62
  def convert(request, writer)
67
63
  ::Typhoeus::Request.new(
68
64
  request.uri,
@@ -71,7 +67,7 @@ module Restify
71
67
  headers: DEFAULT_HEADERS.merge(request.headers),
72
68
  body: request.body,
73
69
  timeout: request.timeout,
74
- connecttimeout: request.timeout
70
+ connecttimeout: request.timeout,
75
71
  ).tap do |req|
76
72
  req.on_complete do |response|
77
73
  debug 'request:complete',
@@ -93,8 +89,6 @@ module Restify
93
89
  end
94
90
  end
95
91
  end
96
- # rubocop:enable Metrics/MethodLength
97
- # rubocop:enable Metrics/AbcSize
98
92
 
99
93
  def convert_back(response, request)
100
94
  uri = request.uri
@@ -127,7 +121,6 @@ module Restify
127
121
  @thread
128
122
  end
129
123
 
130
- # rubocop:disable Metrics/MethodLength
131
124
  def run
132
125
  runs = 0
133
126
 
@@ -154,7 +147,6 @@ module Restify
154
147
  ensure
155
148
  debug 'hydra:exit'
156
149
  end
157
- # rubocop:enable Metrics/MethodLength
158
150
 
159
151
  def dequeue_all
160
152
  loop do
@@ -47,26 +47,22 @@ module Restify
47
47
  processor.new(context, response).resource
48
48
  end
49
49
 
50
- # rubocop:disable Metrics/MethodLength
51
50
  def request(method, uri, data: nil, headers: {}, **kwargs)
52
51
  request = Request.new(
53
52
  headers: default_headers.merge(headers),
54
53
  **kwargs,
55
54
  method: method,
56
55
  uri: join(uri),
57
- data: data
56
+ data: data,
58
57
  )
59
58
 
60
59
  ret = cache.call(request) {|req| adapter.call(req) }
61
60
  ret.then do |response|
62
- if response.errored?
63
- raise ResponseError.from_code(response)
64
- else
65
- process response
66
- end
61
+ raise ResponseError.from_code(response) if response.errored?
62
+
63
+ process(response)
67
64
  end
68
65
  end
69
- # rubocop:enable all
70
66
 
71
67
  def encode_with(coder)
72
68
  coder.map = marshal_dump
@@ -79,7 +75,7 @@ module Restify
79
75
  def marshal_dump
80
76
  {
81
77
  uri: uri.to_s,
82
- headers: default_headers
78
+ headers: default_headers,
83
79
  }
84
80
  end
85
81
 
@@ -20,6 +20,7 @@ module Restify
20
20
 
21
21
  def cache
22
22
  @cache ||= begin
23
+ require 'active_support'
23
24
  require 'active_support/cache'
24
25
  Restify::Cache.new store: ActiveSupport::Cache::MemoryStore.new
25
26
  end
@@ -14,7 +14,7 @@ module Restify
14
14
  _log_prefix,
15
15
  *Array(tag),
16
16
  message,
17
- _fmt(**kwargs)
17
+ _fmt(**kwargs),
18
18
  ].map(&:to_s).reject(&:empty?).join(' ')
19
19
  end
20
20
  end
@@ -21,8 +21,8 @@ module Restify
21
21
  def parse(object, root: false)
22
22
  case object
23
23
  when Hash
24
- data = object.each_with_object({}, &method(:parse_data))
25
- relations = object.each_with_object({}, &method(:parse_rels))
24
+ data = object.each_with_object({}) {|each, obj| parse_data(each, obj) }
25
+ relations = object.each_with_object({}) {|each, obj| parse_rels(each, obj) }
26
26
 
27
27
  data = with_indifferent_access(data) if self.class.indifferent_access?
28
28
 
@@ -32,7 +32,7 @@ module Restify
32
32
  relations: relations
33
33
 
34
34
  when Array
35
- object.map(&method(:parse))
35
+ object.map {|each| parse(each) }
36
36
  else
37
37
  object
38
38
  end
@@ -96,7 +96,7 @@ module Restify
96
96
  def inspect
97
97
  text = {
98
98
  '@data' => data,
99
- '@relations' => @relations
99
+ '@relations' => @relations,
100
100
  }.map {|k, v| "#{k}=#{v.inspect}" }.join(' ')
101
101
 
102
102
  "#<#{self.class} #{text}>"
@@ -89,7 +89,6 @@ module Restify
89
89
  #
90
90
  # @return [Array<Link>] Links.
91
91
  #
92
- # rubocop:disable Metrics/MethodLength
93
92
  def links
94
93
  @links ||= begin
95
94
  if headers['LINK']
@@ -104,7 +103,6 @@ module Restify
104
103
  end
105
104
  end
106
105
  end
107
- # rubocop:enable all
108
106
 
109
107
  # Return content type header from response headers.
110
108
  #
@@ -4,9 +4,9 @@ module Restify
4
4
  module VERSION
5
5
  MAJOR = 1
6
6
  MINOR = 15
7
- PATCH = 1
7
+ PATCH = 2
8
8
  STAGE = nil
9
- STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.').freeze
9
+ STRING = [MAJOR, MINOR, PATCH, STAGE].compact.join('.').freeze
10
10
 
11
11
  def self.to_s
12
12
  STRING
@@ -3,11 +3,11 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Restify::Cache do
6
+ subject { cache }
7
+
6
8
  let(:store) { double 'store' }
7
9
  let(:cache) { described_class.new store }
8
10
 
9
- subject { cache }
10
-
11
11
  describe '#call' do
12
12
  let(:request) { double 'request' }
13
13
  let(:promise0) { double 'promise0' }
@@ -18,27 +18,30 @@ describe Restify::Context do
18
18
  end
19
19
 
20
20
  describe '#adapter' do
21
- let(:kwargs) { {adapter: double('adapter')} }
22
21
  subject { super().options[:adapter] }
23
22
 
23
+ let(:kwargs) { {adapter: double('adapter')} }
24
+
24
25
  it 'adapter is not serialized' do
25
26
  expect(subject).to equal nil
26
27
  end
27
28
  end
28
29
 
29
30
  describe '#cache' do
30
- let(:kwargs) { {adapter: double('cache')} }
31
31
  subject { super().options[:cache] }
32
32
 
33
+ let(:kwargs) { {adapter: double('cache')} }
34
+
33
35
  it 'cache is not serialized' do
34
36
  expect(subject).to equal nil
35
37
  end
36
38
  end
37
39
 
38
40
  describe '#headers' do
39
- let(:kwargs) { {headers: {'Accept' => 'application/json'}} }
40
41
  subject { super().options[:headers] }
41
42
 
43
+ let(:kwargs) { {headers: {'Accept' => 'application/json'}} }
44
+
42
45
  it 'all headers are serialized' do
43
46
  expect(subject).to eq('Accept' => 'application/json')
44
47
  end
@@ -46,20 +49,20 @@ describe Restify::Context do
46
49
  end
47
50
 
48
51
  context 'YAML' do
52
+ subject { load }
53
+
49
54
  let(:dump) { YAML.dump(context) }
50
55
  let(:load) { YAML.load(dump) } # rubocop:disable Security/YAMLLoad
51
56
 
52
- subject { load }
53
-
54
57
  include_examples 'serialization'
55
58
  end
56
59
 
57
60
  context 'Marshall' do
61
+ subject { load }
62
+
58
63
  let(:dump) { Marshal.dump(context) }
59
64
  let(:load) { Marshal.load(dump) } # rubocop:disable Security/MarshalLoad
60
65
 
61
- subject { load }
62
-
63
66
  include_examples 'serialization'
64
67
  end
65
68
  end
@@ -19,51 +19,61 @@ describe Restify::ResponseError do
19
19
 
20
20
  context 'with 400 Bad Request' do
21
21
  let(:code) { 400 }
22
+
22
23
  it { is_expected.to be_a ::Restify::BadRequest }
23
24
  end
24
25
 
25
26
  context 'with 401 Unauthorized' do
26
27
  let(:code) { 401 }
28
+
27
29
  it { is_expected.to be_a ::Restify::Unauthorized }
28
30
  end
29
31
 
30
32
  context 'with 404 Unauthorized' do
31
33
  let(:code) { 404 }
34
+
32
35
  it { is_expected.to be_a ::Restify::NotFound }
33
36
  end
34
37
 
35
38
  context 'with 406 Not Acceptable' do
36
39
  let(:code) { 406 }
40
+
37
41
  it { is_expected.to be_a ::Restify::NotAcceptable }
38
42
  end
39
43
 
40
44
  context 'with 410 Gone' do
41
45
  let(:code) { 410 }
46
+
42
47
  it { is_expected.to be_a ::Restify::Gone }
43
48
  end
44
49
 
45
50
  context 'with 422 Unprocessable Entity' do
46
51
  let(:code) { 422 }
52
+
47
53
  it { is_expected.to be_a ::Restify::UnprocessableEntity }
48
54
  end
49
55
 
50
56
  context 'with 500 Internal Server Error' do
51
57
  let(:code) { 500 }
58
+
52
59
  it { is_expected.to be_a ::Restify::InternalServerError }
53
60
  end
54
61
 
55
62
  context 'with 502 Bad Gateway' do
56
63
  let(:code) { 502 }
64
+
57
65
  it { is_expected.to be_a ::Restify::BadGateway }
58
66
  end
59
67
 
60
68
  context 'with 503 Service Unavailable' do
61
69
  let(:code) { 503 }
70
+
62
71
  it { is_expected.to be_a ::Restify::ServiceUnavailable }
63
72
  end
64
73
 
65
74
  context 'with 504 Gateway Timeout' do
66
75
  let(:code) { 504 }
76
+
67
77
  it { is_expected.to be_a ::Restify::GatewayTimeout }
68
78
  end
69
79
  end
@@ -17,6 +17,7 @@ describe Restify do
17
17
 
18
18
  describe 'HEAD requests' do
19
19
  subject { Restify.new('http://localhost:9292/base').head(params).value! }
20
+
20
21
  let(:params) { {} }
21
22
 
22
23
  it 'returns a resource with access to headers' do
@@ -33,7 +34,7 @@ describe Restify do
33
34
  it 'adds them to the query string' do
34
35
  subject
35
36
  expect(
36
- request_stub.with(query: {foo: 'bar'})
37
+ request_stub.with(query: {foo: 'bar'}),
37
38
  ).to have_been_requested
38
39
  end
39
40
  end