http 6.0.0 → 6.0.1
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/http.gemspec +2 -2
- data/lib/http/version.rb +1 -1
- metadata +4 -79
- data/CHANGELOG.md +0 -267
- data/CONTRIBUTING.md +0 -26
- data/SECURITY.md +0 -17
- data/UPGRADING.md +0 -491
- data/sig/deps.rbs +0 -122
- data/test/http/base64_test.rb +0 -28
- data/test/http/client_test.rb +0 -739
- data/test/http/connection_test.rb +0 -1533
- data/test/http/content_type_test.rb +0 -190
- data/test/http/errors_test.rb +0 -28
- data/test/http/feature_test.rb +0 -49
- data/test/http/features/auto_deflate_test.rb +0 -317
- data/test/http/features/auto_inflate_test.rb +0 -213
- data/test/http/features/caching_test.rb +0 -942
- data/test/http/features/digest_auth_test.rb +0 -996
- data/test/http/features/instrumentation_test.rb +0 -246
- data/test/http/features/logging_test.rb +0 -654
- data/test/http/features/normalize_uri_test.rb +0 -41
- data/test/http/features/raise_error_test.rb +0 -77
- data/test/http/form_data/composite_io_test.rb +0 -215
- data/test/http/form_data/file_test.rb +0 -255
- data/test/http/form_data/fixtures/the-http-gem.info +0 -1
- data/test/http/form_data/multipart_test.rb +0 -303
- data/test/http/form_data/part_test.rb +0 -90
- data/test/http/form_data/urlencoded_test.rb +0 -164
- data/test/http/form_data_test.rb +0 -232
- data/test/http/headers/normalizer_test.rb +0 -93
- data/test/http/headers_test.rb +0 -888
- data/test/http/mime_type/json_test.rb +0 -39
- data/test/http/mime_type_test.rb +0 -150
- data/test/http/options/base_uri_test.rb +0 -148
- data/test/http/options/body_test.rb +0 -21
- data/test/http/options/features_test.rb +0 -38
- data/test/http/options/form_test.rb +0 -21
- data/test/http/options/headers_test.rb +0 -32
- data/test/http/options/json_test.rb +0 -21
- data/test/http/options/merge_test.rb +0 -78
- data/test/http/options/new_test.rb +0 -37
- data/test/http/options/proxy_test.rb +0 -32
- data/test/http/options_test.rb +0 -575
- data/test/http/redirector_test.rb +0 -639
- data/test/http/request/body_test.rb +0 -318
- data/test/http/request/builder_test.rb +0 -623
- data/test/http/request/writer_test.rb +0 -391
- data/test/http/request_test.rb +0 -1733
- data/test/http/response/body_test.rb +0 -292
- data/test/http/response/parser_test.rb +0 -105
- data/test/http/response/status_test.rb +0 -322
- data/test/http/response_test.rb +0 -502
- data/test/http/retriable/delay_calculator_test.rb +0 -194
- data/test/http/retriable/errors_test.rb +0 -71
- data/test/http/retriable/performer_test.rb +0 -551
- data/test/http/session_test.rb +0 -424
- data/test/http/timeout/global_test.rb +0 -239
- data/test/http/timeout/null_test.rb +0 -218
- data/test/http/timeout/per_operation_test.rb +0 -220
- data/test/http/uri/normalizer_test.rb +0 -89
- data/test/http/uri_test.rb +0 -1140
- data/test/http/version_test.rb +0 -15
- data/test/http_test.rb +0 -818
- data/test/regression_tests.rb +0 -27
- data/test/support/capture_warning.rb +0 -10
- data/test/support/dummy_server/encoding_routes.rb +0 -47
- data/test/support/dummy_server/routes.rb +0 -201
- data/test/support/dummy_server/servlet.rb +0 -81
- data/test/support/dummy_server.rb +0 -200
- data/test/support/fakeio.rb +0 -21
- data/test/support/http_handling_shared/connection_reuse_tests.rb +0 -97
- data/test/support/http_handling_shared/timeout_tests.rb +0 -134
- data/test/support/http_handling_shared.rb +0 -11
- data/test/support/proxy_server.rb +0 -207
- data/test/support/servers/runner.rb +0 -67
- data/test/support/simplecov.rb +0 -28
- data/test/support/ssl_helper.rb +0 -108
- data/test/test_helper.rb +0 -38
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "test_helper"
|
|
4
|
-
|
|
5
|
-
class HTTPFeaturesInstrumentationTest < Minitest::Test
|
|
6
|
-
cover "HTTP::Features::Instrumentation*"
|
|
7
|
-
|
|
8
|
-
def instrumenter_class
|
|
9
|
-
@instrumenter_class ||= Class.new(HTTP::Features::Instrumentation::NullInstrumenter) do
|
|
10
|
-
attr_reader :events
|
|
11
|
-
|
|
12
|
-
def initialize
|
|
13
|
-
super
|
|
14
|
-
@events = []
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def start(name, payload)
|
|
18
|
-
events << { type: :start, name: name, payload: payload.dup }
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def finish(name, payload)
|
|
22
|
-
events << { type: :finish, name: name, payload: payload.dup }
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def instrumenter
|
|
28
|
-
@instrumenter ||= instrumenter_class.new
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def feature
|
|
32
|
-
@feature ||= HTTP::Features::Instrumentation.new(instrumenter: instrumenter)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def request
|
|
36
|
-
@request ||= HTTP::Request.new(
|
|
37
|
-
verb: :post,
|
|
38
|
-
uri: "https://example.com/",
|
|
39
|
-
headers: { accept: "application/json" },
|
|
40
|
-
body: '{"hello": "world!"}'
|
|
41
|
-
)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def response
|
|
45
|
-
@response ||= HTTP::Response.new(
|
|
46
|
-
version: "1.1",
|
|
47
|
-
status: 200,
|
|
48
|
-
headers: { content_type: "application/json" },
|
|
49
|
-
body: '{"success": true}',
|
|
50
|
-
request: request
|
|
51
|
-
)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# -- initialization --
|
|
55
|
-
|
|
56
|
-
def test_initialization_uses_null_instrumenter_when_no_instrumenter_provided
|
|
57
|
-
f = HTTP::Features::Instrumentation.new
|
|
58
|
-
|
|
59
|
-
assert_instance_of HTTP::Features::Instrumentation::NullInstrumenter, f.instrumenter
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def test_initialization_sets_name_to_request_http_by_default
|
|
63
|
-
f = HTTP::Features::Instrumentation.new
|
|
64
|
-
|
|
65
|
-
assert_equal "request.http", f.name
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def test_initialization_sets_error_name_to_error_http_by_default
|
|
69
|
-
f = HTTP::Features::Instrumentation.new
|
|
70
|
-
|
|
71
|
-
assert_equal "error.http", f.error_name
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def test_initialization_uses_a_custom_namespace
|
|
75
|
-
f = HTTP::Features::Instrumentation.new(namespace: "my_app")
|
|
76
|
-
|
|
77
|
-
assert_equal "request.my_app", f.name
|
|
78
|
-
assert_equal "error.my_app", f.error_name
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
# -- around_request --
|
|
82
|
-
|
|
83
|
-
def test_around_request_emits_start_event_with_correct_name
|
|
84
|
-
feature.around_request(request) { response }
|
|
85
|
-
first_event = instrumenter.events.first
|
|
86
|
-
|
|
87
|
-
assert_equal "start_request.http", first_event[:name]
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def test_around_request_emits_start_event_with_request_payload
|
|
91
|
-
feature.around_request(request) { response }
|
|
92
|
-
first_event = instrumenter.events.first
|
|
93
|
-
|
|
94
|
-
assert_equal({ request: request }, first_event[:payload])
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def test_around_request_finishes_instrumentation_span_with_response
|
|
98
|
-
feature.around_request(request) { response }
|
|
99
|
-
last_finish = instrumenter.events.reverse.find { |e| e[:type] == :finish }
|
|
100
|
-
|
|
101
|
-
assert_equal({ request: request, response: response }, last_finish[:payload])
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def test_around_request_emits_main_event_with_correct_name
|
|
105
|
-
feature.around_request(request) { response }
|
|
106
|
-
main_finishes = instrumenter.events.select { |e| e[:type] == :finish && e[:name] == "request.http" }
|
|
107
|
-
|
|
108
|
-
assert_equal 1, main_finishes.length
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def test_around_request_returns_the_response_from_the_block
|
|
112
|
-
result = feature.around_request(request) { response }
|
|
113
|
-
|
|
114
|
-
assert_same response, result
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def test_around_request_passes_the_request_to_the_block
|
|
118
|
-
received = nil
|
|
119
|
-
feature.around_request(request) do |req|
|
|
120
|
-
received = req
|
|
121
|
-
response
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
assert_same request, received
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
def test_around_request_finishes_span_even_when_block_raises
|
|
128
|
-
assert_raises(RuntimeError) do
|
|
129
|
-
feature.around_request(request) { raise "boom" }
|
|
130
|
-
end
|
|
131
|
-
last_finish = instrumenter.events.reverse.find { |e| e[:type] == :finish }
|
|
132
|
-
|
|
133
|
-
assert_equal({ request: request }, last_finish[:payload])
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
# -- on_error --
|
|
137
|
-
|
|
138
|
-
def test_on_error_instruments_the_error_with_correct_event_name
|
|
139
|
-
error = HTTP::TimeoutError.new
|
|
140
|
-
feature.on_error(request, error)
|
|
141
|
-
finish_event = instrumenter.events.find { |e| e[:type] == :finish }
|
|
142
|
-
|
|
143
|
-
assert_equal "error.http", finish_event[:name]
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
def test_on_error_logs_the_error_payload
|
|
147
|
-
error = HTTP::TimeoutError.new
|
|
148
|
-
feature.on_error(request, error)
|
|
149
|
-
finish_event = instrumenter.events.find { |e| e[:type] == :finish }
|
|
150
|
-
|
|
151
|
-
assert_equal({ request: request, error: error }, finish_event[:payload])
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
# -- NullInstrumenter --
|
|
155
|
-
|
|
156
|
-
def test_null_instrumenter_start_is_callable
|
|
157
|
-
null_instrumenter = HTTP::Features::Instrumentation::NullInstrumenter.new
|
|
158
|
-
null_instrumenter.start("test", {})
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def test_null_instrumenter_finish_is_callable
|
|
162
|
-
null_instrumenter = HTTP::Features::Instrumentation::NullInstrumenter.new
|
|
163
|
-
null_instrumenter.finish("test", {})
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
def test_null_instrumenter_instrument_is_callable_without_a_block
|
|
167
|
-
null_instrumenter = HTTP::Features::Instrumentation::NullInstrumenter.new
|
|
168
|
-
null_instrumenter.instrument("test")
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
def test_null_instrumenter_instrument_yields_the_payload_to_the_block
|
|
172
|
-
null_instrumenter = HTTP::Features::Instrumentation::NullInstrumenter.new
|
|
173
|
-
received = nil
|
|
174
|
-
null_instrumenter.instrument("test", { key: "value" }) { |payload| received = payload }
|
|
175
|
-
|
|
176
|
-
assert_equal({ key: "value" }, received)
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
def test_null_instrumenter_instrument_defaults_payload_to_empty_hash
|
|
180
|
-
null_instrumenter = HTTP::Features::Instrumentation::NullInstrumenter.new
|
|
181
|
-
received = nil
|
|
182
|
-
null_instrumenter.instrument("test") { |payload| received = payload }
|
|
183
|
-
|
|
184
|
-
assert_equal({}, received)
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
def test_null_instrumenter_instrument_passes_name_to_start_and_finish
|
|
188
|
-
names = []
|
|
189
|
-
inst = HTTP::Features::Instrumentation::NullInstrumenter.new
|
|
190
|
-
inst.define_singleton_method(:start) { |name, _payload| names << [:start, name] }
|
|
191
|
-
inst.define_singleton_method(:finish) { |name, _payload| names << [:finish, name] }
|
|
192
|
-
inst.instrument("test.event") { nil }
|
|
193
|
-
|
|
194
|
-
assert_equal [[:start, "test.event"], [:finish, "test.event"]], names
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
def test_null_instrumenter_instrument_calls_finish_even_when_block_raises
|
|
198
|
-
finished = false
|
|
199
|
-
inst = HTTP::Features::Instrumentation::NullInstrumenter.new
|
|
200
|
-
inst.define_singleton_method(:finish) { |_name, _payload| finished = true }
|
|
201
|
-
assert_raises(RuntimeError) do
|
|
202
|
-
inst.instrument("test") { raise "boom" }
|
|
203
|
-
end
|
|
204
|
-
assert finished
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
# -- with an instrumenter that unconditionally yields --
|
|
208
|
-
|
|
209
|
-
def test_with_yielding_instrumenter_returns_the_response_even_without_payload
|
|
210
|
-
yielding_instrumenter = Class.new do
|
|
211
|
-
def instrument(_name, _payload = {})
|
|
212
|
-
yield
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
def start(_name, _payload = {}); end
|
|
216
|
-
def finish(_name, _payload = {}); end
|
|
217
|
-
end.new
|
|
218
|
-
|
|
219
|
-
feat = HTTP::Features::Instrumentation.new(instrumenter: yielding_instrumenter)
|
|
220
|
-
req = HTTP::Request.new(verb: :get, uri: "https://example.com/", headers: {})
|
|
221
|
-
resp = HTTP::Response.new(
|
|
222
|
-
version: "1.1",
|
|
223
|
-
status: 200,
|
|
224
|
-
body: "",
|
|
225
|
-
request: req
|
|
226
|
-
)
|
|
227
|
-
result = feat.around_request(req) { resp }
|
|
228
|
-
|
|
229
|
-
assert_same resp, result
|
|
230
|
-
end
|
|
231
|
-
|
|
232
|
-
def test_with_yielding_instrumenter_does_not_raise_local_jump_error_in_on_error
|
|
233
|
-
yielding_instrumenter = Class.new do
|
|
234
|
-
def instrument(_name, _payload = {})
|
|
235
|
-
yield
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
def start(_name, _payload = {}); end
|
|
239
|
-
def finish(_name, _payload = {}); end
|
|
240
|
-
end.new
|
|
241
|
-
|
|
242
|
-
feat = HTTP::Features::Instrumentation.new(instrumenter: yielding_instrumenter)
|
|
243
|
-
req = HTTP::Request.new(verb: :get, uri: "https://example.com/", headers: {})
|
|
244
|
-
feat.on_error(req, HTTP::TimeoutError.new)
|
|
245
|
-
end
|
|
246
|
-
end
|