restify 1.15.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +102 -15
- data/README.md +23 -31
- data/lib/restify/adapter/base.rb +4 -0
- data/lib/restify/adapter/telemetry.rb +54 -0
- data/lib/restify/adapter/typhoeus.rb +24 -14
- data/lib/restify/context.rb +7 -11
- data/lib/restify/error.rb +2 -2
- data/lib/restify/global.rb +1 -0
- data/lib/restify/link.rb +4 -4
- data/lib/restify/logging.rb +1 -1
- data/lib/restify/processors/base/parsing.rb +5 -24
- data/lib/restify/processors/base.rb +1 -1
- data/lib/restify/promise.rb +2 -2
- data/lib/restify/registry.rb +1 -1
- data/lib/restify/relation.rb +45 -17
- data/lib/restify/request.rb +6 -6
- data/lib/restify/resource.rb +1 -1
- data/lib/restify/response.rb +0 -2
- data/lib/restify/timeout.rb +2 -2
- data/lib/restify/version.rb +4 -4
- data/lib/restify.rb +0 -1
- data/spec/restify/cache_spec.rb +16 -12
- data/spec/restify/context_spec.rb +15 -7
- data/spec/restify/error_spec.rb +23 -16
- data/spec/restify/features/head_requests_spec.rb +7 -5
- data/spec/restify/features/request_bodies_spec.rb +14 -13
- data/spec/restify/features/request_errors_spec.rb +2 -2
- data/spec/restify/features/request_headers_spec.rb +11 -14
- data/spec/restify/features/response_errors_spec.rb +2 -2
- data/spec/restify/global_spec.rb +13 -13
- data/spec/restify/link_spec.rb +9 -9
- data/spec/restify/processors/base_spec.rb +7 -7
- data/spec/restify/processors/json_spec.rb +22 -62
- data/spec/restify/processors/msgpack_spec.rb +40 -76
- data/spec/restify/promise_spec.rb +38 -34
- data/spec/restify/registry_spec.rb +6 -8
- data/spec/restify/relation_spec.rb +196 -17
- data/spec/restify/resource_spec.rb +55 -60
- data/spec/restify/timeout_spec.rb +7 -7
- data/spec/restify_spec.rb +13 -74
- data/spec/spec_helper.rb +13 -17
- data/spec/support/stub_server.rb +3 -3
- metadata +35 -65
- data/lib/restify/adapter/em.rb +0 -139
- data/lib/restify/adapter/pooled_em.rb +0 -270
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85964ce70270ead0fcc3271b733611bcb97f8415e03a91b46cb402032a4c68f5
|
4
|
+
data.tar.gz: 0c99e59283131de272b9a2a1ad23589395bb89e5b8753e330f305e7ec1483685
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58bf934808c55172f28ec0673f543531c935b68e8e1f8fcf62435b49dfd7ab2e13522ef6c8b675fbfaf234be7ebfac4fdbfe05d57da4e97288b3876000a2487f
|
7
|
+
data.tar.gz: 4617aa58aa9ba400e1f28a0e5a854c5b56a560abb818432211958295e695feab6fe4bfeb0b5bd6418b231260db778804f4cf5309a34f8d1db9cb501d5f48fe6b
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,12 @@
|
|
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
|
-
|
9
8
|
## Unreleased
|
9
|
+
|
10
10
|
---
|
11
11
|
|
12
12
|
### New
|
@@ -17,164 +17,251 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
17
17
|
|
18
18
|
### Breaks
|
19
19
|
|
20
|
+
## 2.0.0 - (2025-02-14)
|
21
|
+
|
22
|
+
---
|
23
|
+
|
24
|
+
### New
|
25
|
+
|
26
|
+
- Support for Ruby 3.4
|
27
|
+
- Experimental support for OpenTelemetry tracing
|
28
|
+
|
29
|
+
### Changes
|
30
|
+
|
31
|
+
- Strict keyword handling for request methods
|
32
|
+
|
33
|
+
All request methods take parameters and headers as explicit keyword arguments, not as secondary arguments anymore. Change e.g. `get({}, {headers: ...})` into `get(headers: ...)`, and `head(params)` to `head(params:)`.
|
34
|
+
|
35
|
+
`#post`, `#put`, and `#patch` still take an optional first positional data/body argument. Change `post(body, {}, {headers: ...})` to `post(body, headers: ...)`.
|
36
|
+
|
37
|
+
`#get`, `#head`, and `#delete` accept a hash as the first positional argument, which is merged with `params:`. Therefore, passing parameters as data works too: `get({id: 1})`.
|
38
|
+
|
39
|
+
### Breaks
|
40
|
+
|
41
|
+
- Remove indifferent access methods (Hashie) from responses
|
42
|
+
- Removed `em` and `em-pooled` adapters
|
43
|
+
- Require Ruby 3.1+
|
44
|
+
|
45
|
+
## 1.15.2 - (2021-12-23)
|
46
|
+
|
47
|
+
---
|
48
|
+
|
49
|
+
### Fixes
|
50
|
+
|
51
|
+
- ActiveSupport v7.0 issues with cache module
|
20
52
|
|
21
53
|
## 1.15.1 - (2021-07-15)
|
54
|
+
|
22
55
|
---
|
23
56
|
|
24
57
|
### Fixes
|
25
|
-
* Typhoeus internal exception when request timed out
|
26
58
|
|
59
|
+
- Typhoeus internal exception when request timed out
|
27
60
|
|
28
61
|
## 1.15.0 - (2021-07-09)
|
62
|
+
|
29
63
|
---
|
30
64
|
|
31
65
|
### New
|
32
|
-
|
33
|
-
|
34
|
-
|
66
|
+
|
67
|
+
- Improve memory usage when running lots of requests with typhoeus adapter
|
68
|
+
- Use hydra for synchronous requests
|
69
|
+
- Increased thread stability of typhoeus adapter (new internal queuing mechanism)
|
35
70
|
|
36
71
|
### 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
72
|
|
73
|
+
- Use Ruby 2.5 as baseline for testing and linting
|
74
|
+
- Add Ruby 3.0 to automated testing
|
75
|
+
- Changed timing behavior for multiple requests due to new internal queuing mechanism for the typhoeus adapter
|
41
76
|
|
42
77
|
## 1.14.0 - (2020-12-15)
|
78
|
+
|
43
79
|
---
|
44
80
|
|
45
81
|
### New
|
46
|
-
* Allow making requests with non-JSON bodies and custom content types (#42)
|
47
82
|
|
83
|
+
- Allow making requests with non-JSON bodies and custom content types (#42)
|
48
84
|
|
49
85
|
## 1.13.0 - (2020-06-12)
|
86
|
+
|
50
87
|
---
|
51
88
|
|
52
89
|
### New
|
53
|
-
* typhoeus: Support setting per-request libcurl options on adapter
|
54
|
-
* typhoeus: Enable short TCP keepalive probes by default (5s/5s)
|
55
90
|
|
91
|
+
- typhoeus: Support setting per-request libcurl options on adapter
|
92
|
+
- typhoeus: Enable short TCP keepalive probes by default (5s/5s)
|
56
93
|
|
57
94
|
## 1.12.0 - (2020-04-01)
|
95
|
+
|
58
96
|
---
|
59
97
|
|
60
98
|
### Added
|
61
|
-
|
99
|
+
|
100
|
+
- Explicit exception class for HTTP status code 410 (Gone)
|
62
101
|
|
63
102
|
### Changed
|
64
103
|
|
65
104
|
### Fixed
|
66
|
-
* `GatewayError` exception classes introduced in v1.11.0 now properly inherit from `ServerError` (#30)
|
67
105
|
|
106
|
+
- `GatewayError` exception classes introduced in v1.11.0 now properly inherit from `ServerError` (#30)
|
68
107
|
|
69
108
|
## 1.11.0 - (2019-07-11)
|
109
|
+
|
70
110
|
### Added
|
71
|
-
|
111
|
+
|
112
|
+
- Explicit exception classes for HTTP status codes 500, 502, 503, 504
|
72
113
|
|
73
114
|
## 1.10.0 - 2018-12-11
|
115
|
+
|
74
116
|
### Changed
|
117
|
+
|
75
118
|
- Raise more specific error on a few status codes (#17)
|
76
119
|
- Complete promises with an empty list (but a list) of dependencies (#18)
|
77
120
|
|
78
121
|
## 1.9.0 - 2018-11-13
|
122
|
+
|
79
123
|
### Changed
|
124
|
+
|
80
125
|
- Do not raise error on 3XX responses but return responses
|
81
126
|
|
82
127
|
## 1.8.0 - 2018-08-22
|
128
|
+
|
83
129
|
### Added
|
130
|
+
|
84
131
|
- Add HEAD request method (#16)
|
85
132
|
|
86
133
|
## 1.7.0 - 2018-08-15
|
134
|
+
|
87
135
|
### Added
|
136
|
+
|
88
137
|
- Introduce promise dependency timeouts (#15)
|
89
138
|
|
90
139
|
## 1.6.0 - 2018-08-09
|
140
|
+
|
91
141
|
### Changed
|
142
|
+
|
92
143
|
- Specify headers on restify clients and individual requests (#14)
|
93
144
|
|
94
145
|
## 1.5.0 - 2018-07-31
|
146
|
+
|
95
147
|
### Added
|
148
|
+
|
96
149
|
- Add MessagePack processor enabled by default
|
97
150
|
|
98
151
|
### Changed
|
152
|
+
|
99
153
|
- Tune typhoeus adapter to be more race-condition resilent
|
100
154
|
|
101
155
|
## 1.4.4 - 2018-07-13
|
156
|
+
|
102
157
|
### Added
|
158
|
+
|
103
159
|
- Add `#request` to `NetworkError` to ease debugging
|
104
160
|
|
105
161
|
### Changed
|
162
|
+
|
106
163
|
- Fix race condition in typhoeus adapter
|
107
164
|
|
108
165
|
## 1.4.3 - 2017-11-15
|
166
|
+
|
109
167
|
### Added
|
168
|
+
|
110
169
|
- Add advanced logging capabilities using logging gem
|
111
170
|
|
112
171
|
### Changed
|
172
|
+
|
113
173
|
- Improve compatibility with webmocks returning `nil` as headers
|
114
174
|
|
115
175
|
## 1.4.1 - 2017-11-15
|
176
|
+
|
116
177
|
### Changed
|
178
|
+
|
117
179
|
- Fix possible deadlock issues
|
118
180
|
|
119
181
|
## 1.4.0 - 2017-11-10
|
182
|
+
|
120
183
|
### Added
|
184
|
+
|
121
185
|
- Add timeout option to requests (only supported by typhoeus adapter)
|
122
186
|
|
123
187
|
### Changed
|
188
|
+
|
124
189
|
- Fix possible concurrency issue with typhoeus adapter
|
125
190
|
|
126
191
|
## 1.3.1 - 2017-11-10
|
192
|
+
|
127
193
|
### Changed
|
194
|
+
|
128
195
|
- Improve typhoeus adapters initial request queuing
|
129
196
|
- Disable default pipelining
|
130
197
|
|
131
198
|
## 1.3.0 - 2017-11-08
|
199
|
+
|
132
200
|
### Changed
|
201
|
+
|
133
202
|
- Improve typhoeus adapter to better utilize concurrency
|
134
203
|
- Default to new typhoeus adapter
|
135
204
|
|
136
205
|
## 1.2.1 - 2017-10-30
|
206
|
+
|
137
207
|
### Changed
|
208
|
+
|
138
209
|
- Fix issue with Ruby 2.2 compatibility
|
139
210
|
|
140
211
|
## 1.2.0 - 2017-10-30
|
212
|
+
|
141
213
|
### Added
|
214
|
+
|
142
215
|
- Add experimental PooledEM adapter (#10)
|
143
216
|
|
144
217
|
### Changed
|
218
|
+
|
145
219
|
- Improve marshaling of resources
|
146
220
|
|
147
221
|
## 1.1.0 - 2017-05-12
|
222
|
+
|
148
223
|
### Added
|
224
|
+
|
149
225
|
- Add shortcuts for creating fulfilled / rejected promises (#6)
|
150
226
|
|
151
227
|
### Changed
|
228
|
+
|
152
229
|
- Return response body if no processor matches (#7)
|
153
230
|
|
154
231
|
## 1.0.0 - 2016-08-22
|
232
|
+
|
155
233
|
### Added
|
234
|
+
|
156
235
|
- Experimental cache API doing nothing for now
|
157
236
|
|
158
237
|
### Changed
|
238
|
+
|
159
239
|
- Use `~> 1.0` of `concurrent-ruby`
|
160
240
|
|
161
241
|
## 0.5.0 - 2016-04-04
|
242
|
+
|
162
243
|
### Added
|
244
|
+
|
163
245
|
- Add `sync` option to typhoeus adapter
|
164
246
|
- Add registry for storing entry points
|
165
247
|
|
166
248
|
### Changed
|
249
|
+
|
167
250
|
- Make eventmachine based adapter default
|
168
251
|
|
169
252
|
## 0.4.0 - 2016-02-24
|
253
|
+
|
170
254
|
### Added
|
255
|
+
|
171
256
|
- Add method to explicit access resource data
|
172
257
|
|
173
258
|
### Changed
|
259
|
+
|
174
260
|
- Use typhoeus as default adapter
|
175
261
|
- `Restify.new` returns relation now instead of resource
|
176
262
|
|
177
263
|
### Removed
|
264
|
+
|
178
265
|
- Drop obligation in favor of simple Concurrent::IVar based promise class.
|
179
266
|
Notable changes:
|
180
267
|
- Returned object us of type `Restify::Promise` now.
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Restify
|
2
2
|
|
3
|
-
[](https://rubygems.org/gems/restify)
|
4
|
+
[](https://github.com/jgraichen/restify/actions)
|
5
|
+
[](https://codebeat.co/projects/github-com-jgraichen-restify-main)
|
5
6
|
|
6
7
|
Restify is an hypermedia REST client that does parallel, concurrent and keep-alive requests by default.
|
7
8
|
|
@@ -27,16 +28,19 @@ Links are extracted from
|
|
27
28
|
* HTTP Link header
|
28
29
|
* Github-style relations in payloads
|
29
30
|
|
30
|
-
|
31
|
+
## Installation
|
31
32
|
|
32
|
-
|
33
|
-
* API versions via header
|
34
|
-
* Content-Type and Language negotiation
|
35
|
-
* Processors for JSON-HAL, etc.
|
33
|
+
Add it to your Gemfile:
|
36
34
|
|
37
|
-
|
35
|
+
```ruby
|
36
|
+
gem 'restify', '~> 2.0'
|
37
|
+
```
|
38
38
|
|
39
|
-
|
39
|
+
Or install it manually:
|
40
|
+
|
41
|
+
```console
|
42
|
+
gem install restify
|
43
|
+
```
|
40
44
|
|
41
45
|
## Usage
|
42
46
|
|
@@ -51,7 +55,7 @@ client = Restify.new('https://api.github.com').get.value
|
|
51
55
|
# ...
|
52
56
|
```
|
53
57
|
|
54
|
-
We are essentially requesting `'http://api.github.com'` via HTTP `get`. `get` is returning
|
58
|
+
We are essentially requesting `'http://api.github.com'` via HTTP `get`. `get` is returning a `Promise`, similar to Java's `Future`. The `value` call resolves the returned `Promise` by blocking the thread until the resource is actually there. `value!` will additionally raise errors instead of returning `nil`. You can chain handlers using the `then` method. This allows you to be build a dependency chain that will be executed when the last promise is needed.
|
55
59
|
|
56
60
|
As we can see GitHub returns us a field `repository_url` with a URI template. Restify automatically scans for `*_url` fields in the JSON response and exposes these as relations. It additionally scans the HTTP Header field `Link` for relations like pagination.
|
57
61
|
|
@@ -65,33 +69,21 @@ repositories = client.rel(:repository)
|
|
65
69
|
This gets us the relation named `repository` that we can request now. The usual HTTP methods are available on a relation:
|
66
70
|
|
67
71
|
```ruby
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
def delete(params = {})
|
73
|
-
request :delete, nil, params
|
74
|
-
end
|
75
|
-
|
76
|
-
def post(data = {}, params = {})
|
77
|
-
request :post, data, params
|
78
|
-
end
|
79
|
-
|
80
|
-
def put(data = {}, params = {})
|
81
|
-
request :put, data, params
|
82
|
-
end
|
72
|
+
def get(params, params:, headers:, **)
|
73
|
+
def head(params, params:, headers:, **)
|
74
|
+
def delete(params, params:, headers:, **)
|
83
75
|
|
84
|
-
|
85
|
-
|
86
|
-
|
76
|
+
def put(data = nil, params:, headers:, **)
|
77
|
+
def post(data = nil, params:, headers:, **)
|
78
|
+
def patch(data = nil, params:, headers:, **)
|
87
79
|
```
|
88
80
|
|
89
|
-
URL templates can define some parameters such as `{owner}` or `{repo}`. They will be expanded from the `params` given to the HTTP method
|
81
|
+
URL templates can define some parameters such as `{owner}` or `{repo}`. They will be expanded from the `params` given to the HTTP method.
|
90
82
|
|
91
83
|
Now send a GET request with some parameters to request a specific repository:
|
92
84
|
|
93
85
|
```ruby
|
94
|
-
repo = repositories.get(owner: 'jgraichen', repo: 'restify').value
|
86
|
+
repo = repositories.get({owner: 'jgraichen', repo: 'restify'}).value
|
95
87
|
```
|
96
88
|
|
97
89
|
Now fetch a list of commits for this repo and get this first one:
|
@@ -121,7 +113,7 @@ See commented example in main spec [`spec/restify_spec.rb`](https://github.com/j
|
|
121
113
|
|
122
114
|
## License
|
123
115
|
|
124
|
-
Copyright (C) 2014-
|
116
|
+
Copyright (C) 2014-2025 Jan Graichen
|
125
117
|
|
126
118
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
127
119
|
|
data/lib/restify/adapter/base.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'opentelemetry'
|
4
|
+
require 'opentelemetry/common'
|
5
|
+
|
6
|
+
module Restify
|
7
|
+
module Adapter
|
8
|
+
module Telemetry
|
9
|
+
def call(request)
|
10
|
+
method = request.method.to_s.upcase
|
11
|
+
uri = URI.parse(request.uri)
|
12
|
+
name = "#{method} #{uri.scheme}://#{uri.host}:#{uri.port}"
|
13
|
+
|
14
|
+
attributes = {
|
15
|
+
'http.request.method' => method,
|
16
|
+
'server.address' => uri.host,
|
17
|
+
'server.port' => uri.port,
|
18
|
+
'url.full' => uri.to_s,
|
19
|
+
'url.scheme' => uri.scheme,
|
20
|
+
}
|
21
|
+
|
22
|
+
span = tracer.start_span(name, attributes:, kind: :client)
|
23
|
+
OpenTelemetry::Trace.with_span(span) do
|
24
|
+
OpenTelemetry.propagation.inject(request.headers)
|
25
|
+
|
26
|
+
super.tap do |x|
|
27
|
+
x.add_observer do |_, response, err|
|
28
|
+
if response
|
29
|
+
span.set_attribute('http.response.status_code', response&.code)
|
30
|
+
span.status = OpenTelemetry::Trace::Status.error unless (100..399).cover?(response&.code)
|
31
|
+
end
|
32
|
+
|
33
|
+
span.status = OpenTelemetry::Trace::Status.error(err) if err
|
34
|
+
|
35
|
+
span.finish
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def tracer
|
44
|
+
Telemetry.tracer
|
45
|
+
end
|
46
|
+
|
47
|
+
class << self
|
48
|
+
def tracer
|
49
|
+
@tracer ||= OpenTelemetry.tracer_provider.tracer('restify', Restify::VERSION.to_s)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'typhoeus'
|
4
4
|
|
5
|
-
|
5
|
+
Ethon.logger = Logging.logger[Ethon]
|
6
6
|
|
7
7
|
module Restify
|
8
8
|
module Adapter
|
@@ -13,18 +13,36 @@ 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
|
+
# Patch to store easy handles in the queue, instead of requests.
|
27
|
+
# This improves compatibility with OpenTelemetry instrumentation
|
28
|
+
# for Ethon, that needs the request handle to be constructed in
|
29
|
+
# the current threading context, not the background thread were
|
30
|
+
# Typhoeus is running.
|
31
|
+
module EasyOverride
|
32
|
+
def queue(request)
|
33
|
+
request.hydra = self
|
34
|
+
queued_requests << ::Typhoeus::EasyFactory.new(request, self).get
|
35
|
+
end
|
36
|
+
|
37
|
+
def add(handle)
|
38
|
+
multi.add(handle)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
26
42
|
def initialize(sync: false, options: {}, **kwargs)
|
27
|
-
@hydra
|
43
|
+
@hydra = ::Typhoeus::Hydra.new(**kwargs)
|
44
|
+
@hydra.extend(EasyOverride)
|
45
|
+
|
28
46
|
@mutex = Mutex.new
|
29
47
|
@options = DEFAULT_OPTIONS.merge(options)
|
30
48
|
@queue = Queue.new
|
@@ -38,7 +56,6 @@ module Restify
|
|
38
56
|
@sync
|
39
57
|
end
|
40
58
|
|
41
|
-
# rubocop:disable Metrics/MethodLength
|
42
59
|
def call_native(request, writer)
|
43
60
|
req = convert(request, writer)
|
44
61
|
|
@@ -57,12 +74,9 @@ module Restify
|
|
57
74
|
thread.run unless thread.status
|
58
75
|
end
|
59
76
|
end
|
60
|
-
# rubocop:enable Metrics/MethodLength
|
61
77
|
|
62
78
|
private
|
63
79
|
|
64
|
-
# rubocop:disable Metrics/AbcSize
|
65
|
-
# rubocop:disable Metrics/MethodLength
|
66
80
|
def convert(request, writer)
|
67
81
|
::Typhoeus::Request.new(
|
68
82
|
request.uri,
|
@@ -71,7 +85,7 @@ module Restify
|
|
71
85
|
headers: DEFAULT_HEADERS.merge(request.headers),
|
72
86
|
body: request.body,
|
73
87
|
timeout: request.timeout,
|
74
|
-
connecttimeout: request.timeout
|
88
|
+
connecttimeout: request.timeout,
|
75
89
|
).tap do |req|
|
76
90
|
req.on_complete do |response|
|
77
91
|
debug 'request:complete',
|
@@ -93,8 +107,6 @@ module Restify
|
|
93
107
|
end
|
94
108
|
end
|
95
109
|
end
|
96
|
-
# rubocop:enable Metrics/MethodLength
|
97
|
-
# rubocop:enable Metrics/AbcSize
|
98
110
|
|
99
111
|
def convert_back(response, request)
|
100
112
|
uri = request.uri
|
@@ -108,7 +120,7 @@ module Restify
|
|
108
120
|
def convert_headers(headers)
|
109
121
|
return {} unless headers.respond_to?(:each_pair)
|
110
122
|
|
111
|
-
headers.each_pair.
|
123
|
+
headers.each_pair.with_object({}) do |header, memo|
|
112
124
|
memo[header[0].upcase.tr('-', '_')] = header[1]
|
113
125
|
end
|
114
126
|
end
|
@@ -127,7 +139,6 @@ module Restify
|
|
127
139
|
@thread
|
128
140
|
end
|
129
141
|
|
130
|
-
# rubocop:disable Metrics/MethodLength
|
131
142
|
def run
|
132
143
|
runs = 0
|
133
144
|
|
@@ -154,7 +165,6 @@ module Restify
|
|
154
165
|
ensure
|
155
166
|
debug 'hydra:exit'
|
156
167
|
end
|
157
|
-
# rubocop:enable Metrics/MethodLength
|
158
168
|
|
159
169
|
def dequeue_all
|
160
170
|
loop do
|
data/lib/restify/context.rb
CHANGED
@@ -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
|
-
method
|
54
|
+
method:,
|
56
55
|
uri: join(uri),
|
57
|
-
data
|
56
|
+
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
|
-
|
64
|
-
|
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,12 +75,12 @@ 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
|
|
86
82
|
def marshal_load(dump)
|
87
|
-
initialize dump.delete(:uri),
|
83
|
+
initialize dump.delete(:uri),
|
88
84
|
headers: dump.fetch(:headers)
|
89
85
|
end
|
90
86
|
|
data/lib/restify/error.rb
CHANGED
@@ -55,8 +55,8 @@ module Restify
|
|
55
55
|
|
56
56
|
def initialize(response)
|
57
57
|
@response = response
|
58
|
-
super
|
59
|
-
"
|
58
|
+
super("#{response.message} (#{response.code}) for `#{response.uri}':\n " \
|
59
|
+
"#{errors.inspect}")
|
60
60
|
end
|
61
61
|
|
62
62
|
# Return response status.
|
data/lib/restify/global.rb
CHANGED
data/lib/restify/link.rb
CHANGED
@@ -25,10 +25,10 @@ module Restify
|
|
25
25
|
end
|
26
26
|
|
27
27
|
class << self
|
28
|
-
REGEXP_URI = /<[^>]*>\s
|
29
|
-
REGEXP_PAR = /;\s*\w+\s*=\s*/i
|
30
|
-
REGEXP_QUT = /"[^"]*"\s
|
31
|
-
REGEXP_ARG = /\w+\s*/i
|
28
|
+
REGEXP_URI = /<[^>]*>\s*/
|
29
|
+
REGEXP_PAR = /;\s*\w+\s*=\s*/i
|
30
|
+
REGEXP_QUT = /"[^"]*"\s*/
|
31
|
+
REGEXP_ARG = /\w+\s*/i
|
32
32
|
|
33
33
|
def parse(string)
|
34
34
|
scanner = StringScanner.new(string.strip)
|