restify 1.13.0 → 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 +4 -4
- data/CHANGELOG.md +98 -6
- data/lib/restify/adapter/em.rb +6 -13
- data/lib/restify/adapter/pooled_em.rb +35 -40
- data/lib/restify/adapter/typhoeus.rb +57 -51
- data/lib/restify/context.rb +5 -9
- data/lib/restify/error.rb +24 -0
- data/lib/restify/global.rb +1 -0
- data/lib/restify/logging.rb +1 -1
- data/lib/restify/processors/base/parsing.rb +5 -9
- data/lib/restify/processors/base.rb +2 -6
- data/lib/restify/promise.rb +1 -3
- data/lib/restify/request.rb +13 -5
- data/lib/restify/resource.rb +2 -2
- data/lib/restify/response.rb +0 -2
- data/lib/restify/timeout.rb +1 -3
- data/lib/restify/version.rb +3 -3
- data/spec/restify/cache_spec.rb +2 -2
- data/spec/restify/context_spec.rb +10 -7
- data/spec/restify/error_spec.rb +10 -0
- data/spec/restify/features/head_requests_spec.rb +7 -7
- data/spec/restify/features/request_bodies_spec.rb +84 -0
- data/spec/restify/features/request_errors_spec.rb +19 -0
- data/spec/restify/features/request_headers_spec.rb +16 -17
- data/spec/restify/features/response_errors_spec.rb +127 -0
- data/spec/restify/global_spec.rb +6 -6
- data/spec/restify/link_spec.rb +9 -9
- data/spec/restify/processors/base_spec.rb +1 -0
- data/spec/restify/processors/json_spec.rb +2 -1
- data/spec/restify/processors/msgpack_spec.rb +8 -7
- data/spec/restify/promise_spec.rb +8 -4
- data/spec/restify/registry_spec.rb +2 -2
- data/spec/restify/relation_spec.rb +18 -17
- data/spec/restify/resource_spec.rb +9 -8
- data/spec/restify/timeout_spec.rb +4 -4
- data/spec/restify_spec.rb +52 -57
- data/spec/spec_helper.rb +11 -8
- data/spec/support/stub_server.rb +106 -0
- metadata +30 -23
- data/spec/restify/features/response_errors.rb +0 -79
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'puma'
|
4
|
+
require 'rack'
|
5
|
+
require 'webmock'
|
6
|
+
require 'webmock/rspec/matchers'
|
7
|
+
|
8
|
+
module Stub
|
9
|
+
# This Rack application matches the request received from rack against the
|
10
|
+
# webmock stub database and returns the response.
|
11
|
+
#
|
12
|
+
# A custom server name is used to
|
13
|
+
# 1) has a stable name without a dynamic port for easier `#stub_request`
|
14
|
+
# calls, and
|
15
|
+
# 2) to ensure no actual request is intercepted (they are send to
|
16
|
+
# `localhost:<port>`).
|
17
|
+
#
|
18
|
+
# If no stub is found a special HTTP 599 error code will be returned.
|
19
|
+
class Handler
|
20
|
+
def call(env)
|
21
|
+
signature = WebMock::RequestSignature.new(
|
22
|
+
env['REQUEST_METHOD'].downcase,
|
23
|
+
"http://stubserver#{env['REQUEST_URI']}",
|
24
|
+
)
|
25
|
+
|
26
|
+
# Extract request headers from rack env. Most header should start with
|
27
|
+
# `HTTP_` but at least content type is present as `CONTENT_TYPE`.
|
28
|
+
headers = {}
|
29
|
+
env.each_pair do |key, value|
|
30
|
+
case key
|
31
|
+
when /^HTTP_(.*)$/, /^(CONTENT_.*)$/
|
32
|
+
headers[Regexp.last_match(1)] = value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Read request body from socket into string
|
37
|
+
signature.body = env['rack.input'].read
|
38
|
+
signature.headers = headers
|
39
|
+
|
40
|
+
WebMock::RequestRegistry.instance.requested_signatures.put(signature)
|
41
|
+
response = ::WebMock::StubRegistry.instance.response_for_request(signature)
|
42
|
+
|
43
|
+
# Return special HTTP 599 with the error message that would normally
|
44
|
+
# appear on missing stubs.
|
45
|
+
unless response
|
46
|
+
return [599, {}, [WebMock::NetConnectNotAllowedError.new(signature).message]]
|
47
|
+
end
|
48
|
+
|
49
|
+
if response.should_timeout
|
50
|
+
sleep 10
|
51
|
+
return [599, {}, ['Timeout']]
|
52
|
+
end
|
53
|
+
|
54
|
+
status = response.status
|
55
|
+
status = status.to_s.split(' ', 2) unless status.is_a?(Array)
|
56
|
+
status = Integer(status[0])
|
57
|
+
|
58
|
+
[status, response.headers || {}, [response.body.to_s]]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Exception < ::StandardError; end
|
63
|
+
|
64
|
+
# Inject into base adapter to have HTTP 599 (missing stub) error raised as an
|
65
|
+
# extra exception, not just a server error.
|
66
|
+
module Patch
|
67
|
+
def call(request)
|
68
|
+
super.then do |response|
|
69
|
+
next response unless response.code == 599
|
70
|
+
|
71
|
+
raise ::Stub::Exception.new(response.body)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
::Restify::Adapter::Base.prepend(self)
|
76
|
+
end
|
77
|
+
|
78
|
+
class << self
|
79
|
+
def start_server!
|
80
|
+
@server = ::Puma::Server.new(Handler.new)
|
81
|
+
@server.add_tcp_listener('localhost', 9292)
|
82
|
+
|
83
|
+
Thread.new do
|
84
|
+
@server.run
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
RSpec.configure do |config|
|
91
|
+
config.include WebMock::API
|
92
|
+
config.include WebMock::Matchers
|
93
|
+
|
94
|
+
config.before(:suite) do
|
95
|
+
Stub.start_server!
|
96
|
+
|
97
|
+
# Net::HTTP adapter must be enabled, otherwise webmock fails to create mock
|
98
|
+
# responses from raw strings.
|
99
|
+
WebMock.disable!(except: %i[net_http])
|
100
|
+
end
|
101
|
+
|
102
|
+
config.around do |example|
|
103
|
+
example.run
|
104
|
+
WebMock.reset!
|
105
|
+
end
|
106
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.15.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -73,7 +73,7 @@ dependencies:
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '5.0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
76
|
+
name: hitimes
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - ">="
|
@@ -86,20 +86,6 @@ dependencies:
|
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: typhoeus
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: '1.3'
|
96
|
-
type: :runtime
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: '1.3'
|
103
89
|
- !ruby/object:Gem::Dependency
|
104
90
|
name: logging
|
105
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,7 +115,7 @@ dependencies:
|
|
129
115
|
- !ruby/object:Gem::Version
|
130
116
|
version: '1.2'
|
131
117
|
- !ruby/object:Gem::Dependency
|
132
|
-
name:
|
118
|
+
name: rack
|
133
119
|
requirement: !ruby/object:Gem::Requirement
|
134
120
|
requirements:
|
135
121
|
- - ">="
|
@@ -142,6 +128,20 @@ dependencies:
|
|
142
128
|
- - ">="
|
143
129
|
- !ruby/object:Gem::Version
|
144
130
|
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: typhoeus
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '1.3'
|
138
|
+
type: :runtime
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '1.3'
|
145
145
|
- !ruby/object:Gem::Dependency
|
146
146
|
name: bundler
|
147
147
|
requirement: !ruby/object:Gem::Requirement
|
@@ -194,8 +194,10 @@ files:
|
|
194
194
|
- spec/restify/context_spec.rb
|
195
195
|
- spec/restify/error_spec.rb
|
196
196
|
- spec/restify/features/head_requests_spec.rb
|
197
|
+
- spec/restify/features/request_bodies_spec.rb
|
198
|
+
- spec/restify/features/request_errors_spec.rb
|
197
199
|
- spec/restify/features/request_headers_spec.rb
|
198
|
-
- spec/restify/features/
|
200
|
+
- spec/restify/features/response_errors_spec.rb
|
199
201
|
- spec/restify/global_spec.rb
|
200
202
|
- spec/restify/link_spec.rb
|
201
203
|
- spec/restify/processors/base_spec.rb
|
@@ -208,10 +210,12 @@ files:
|
|
208
210
|
- spec/restify/timeout_spec.rb
|
209
211
|
- spec/restify_spec.rb
|
210
212
|
- spec/spec_helper.rb
|
213
|
+
- spec/support/stub_server.rb
|
211
214
|
homepage: https://github.com/jgraichen/restify
|
212
215
|
licenses:
|
213
216
|
- LGPL-3.0+
|
214
|
-
metadata:
|
217
|
+
metadata:
|
218
|
+
rubygems_mfa_required: 'true'
|
215
219
|
post_install_message:
|
216
220
|
rdoc_options: []
|
217
221
|
require_paths:
|
@@ -220,14 +224,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
220
224
|
requirements:
|
221
225
|
- - ">="
|
222
226
|
- !ruby/object:Gem::Version
|
223
|
-
version:
|
227
|
+
version: 2.5.0
|
224
228
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
229
|
requirements:
|
226
230
|
- - ">="
|
227
231
|
- !ruby/object:Gem::Version
|
228
232
|
version: '0'
|
229
233
|
requirements: []
|
230
|
-
rubygems_version: 3.1.
|
234
|
+
rubygems_version: 3.1.6
|
231
235
|
signing_key:
|
232
236
|
specification_version: 4
|
233
237
|
summary: An experimental hypermedia REST client.
|
@@ -236,8 +240,10 @@ test_files:
|
|
236
240
|
- spec/restify/context_spec.rb
|
237
241
|
- spec/restify/error_spec.rb
|
238
242
|
- spec/restify/features/head_requests_spec.rb
|
243
|
+
- spec/restify/features/request_bodies_spec.rb
|
244
|
+
- spec/restify/features/request_errors_spec.rb
|
239
245
|
- spec/restify/features/request_headers_spec.rb
|
240
|
-
- spec/restify/features/
|
246
|
+
- spec/restify/features/response_errors_spec.rb
|
241
247
|
- spec/restify/global_spec.rb
|
242
248
|
- spec/restify/link_spec.rb
|
243
249
|
- spec/restify/processors/base_spec.rb
|
@@ -250,3 +256,4 @@ test_files:
|
|
250
256
|
- spec/restify/timeout_spec.rb
|
251
257
|
- spec/restify_spec.rb
|
252
258
|
- spec/spec_helper.rb
|
259
|
+
- spec/support/stub_server.rb
|
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Restify do
|
6
|
-
let!(:request_stub) do
|
7
|
-
stub_request(:get, 'http://localhost/base')
|
8
|
-
.to_return do
|
9
|
-
<<-RESPONSE.gsub(/^ {8}/, '')
|
10
|
-
HTTP/1.1 #{http_status}
|
11
|
-
Content-Length: 333
|
12
|
-
Transfer-Encoding: chunked
|
13
|
-
Link: <http://localhost/other>; rel="neat"
|
14
|
-
RESPONSE
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
let(:http_status) { '200 OK' }
|
19
|
-
|
20
|
-
describe 'Error handling' do
|
21
|
-
subject(:request) { Restify.new('http://localhost/base').get.value! }
|
22
|
-
|
23
|
-
context 'for 400 status codes' do
|
24
|
-
let(:http_status) { '400 Bad Request' }
|
25
|
-
|
26
|
-
it 'throws a BadRequest exception' do
|
27
|
-
expect { request }.to raise_error Restify::BadRequest
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'for 401 status codes' do
|
32
|
-
let(:http_status) { '401 Unauthorized' }
|
33
|
-
|
34
|
-
it 'throws an Unauthorized exception' do
|
35
|
-
expect { request }.to raise_error Restify::Unauthorized
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'for 404 status codes' do
|
40
|
-
let(:http_status) { '404 Not Found' }
|
41
|
-
|
42
|
-
it 'throws a ClientError exception' do
|
43
|
-
expect { request }.to raise_error Restify::NotFoundError
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'for 406 status codes' do
|
48
|
-
let(:http_status) { '406 Not Acceptable' }
|
49
|
-
|
50
|
-
it 'throws a NotAcceptable exception' do
|
51
|
-
expect { request }.to raise_error Restify::NotAcceptable
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'for 422 status codes' do
|
56
|
-
let(:http_status) { '422 Unprocessable Entity' }
|
57
|
-
|
58
|
-
it 'throws a UnprocessableEntity exception' do
|
59
|
-
expect { request }.to raise_error Restify::UnprocessableEntity
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'for any other 4xx status codes' do
|
64
|
-
let(:http_status) { '415 Unsupported Media Type' }
|
65
|
-
|
66
|
-
it 'throws a generic ClientError exception' do
|
67
|
-
expect { request }.to raise_error Restify::ClientError
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context 'for any 5xx status codes' do
|
72
|
-
let(:http_status) { '500 Internal Server Error' }
|
73
|
-
|
74
|
-
it 'throws a generic ServerError exception' do
|
75
|
-
expect { request }.to raise_error Restify::ServerError
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|