http 5.3.1 → 6.0.0
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 +241 -41
- data/LICENSE.txt +1 -1
- data/README.md +110 -13
- data/UPGRADING.md +491 -0
- data/http.gemspec +32 -29
- data/lib/http/base64.rb +11 -1
- data/lib/http/chainable/helpers.rb +62 -0
- data/lib/http/chainable/verbs.rb +136 -0
- data/lib/http/chainable.rb +232 -136
- data/lib/http/client.rb +158 -127
- data/lib/http/connection/internals.rb +141 -0
- data/lib/http/connection.rb +126 -97
- data/lib/http/content_type.rb +61 -6
- data/lib/http/errors.rb +25 -1
- data/lib/http/feature.rb +65 -5
- data/lib/http/features/auto_deflate.rb +124 -17
- data/lib/http/features/auto_inflate.rb +38 -15
- data/lib/http/features/caching/entry.rb +178 -0
- data/lib/http/features/caching/in_memory_store.rb +63 -0
- data/lib/http/features/caching.rb +216 -0
- data/lib/http/features/digest_auth.rb +234 -0
- data/lib/http/features/instrumentation.rb +97 -17
- data/lib/http/features/logging.rb +183 -5
- data/lib/http/features/normalize_uri.rb +17 -0
- data/lib/http/features/raise_error.rb +18 -3
- data/lib/http/form_data/composite_io.rb +106 -0
- data/lib/http/form_data/file.rb +95 -0
- data/lib/http/form_data/multipart/param.rb +62 -0
- data/lib/http/form_data/multipart.rb +106 -0
- data/lib/http/form_data/part.rb +52 -0
- data/lib/http/form_data/readable.rb +58 -0
- data/lib/http/form_data/urlencoded.rb +175 -0
- data/lib/http/form_data/version.rb +8 -0
- data/lib/http/form_data.rb +102 -0
- data/lib/http/headers/known.rb +3 -0
- data/lib/http/headers/normalizer.rb +17 -36
- data/lib/http/headers.rb +172 -65
- data/lib/http/mime_type/adapter.rb +24 -9
- data/lib/http/mime_type/json.rb +19 -4
- data/lib/http/mime_type.rb +21 -3
- data/lib/http/options/definitions.rb +189 -0
- data/lib/http/options.rb +172 -125
- data/lib/http/redirector.rb +80 -75
- data/lib/http/request/body.rb +87 -6
- data/lib/http/request/builder.rb +184 -0
- data/lib/http/request/proxy.rb +83 -0
- data/lib/http/request/writer.rb +76 -16
- data/lib/http/request.rb +214 -98
- data/lib/http/response/body.rb +103 -18
- data/lib/http/response/inflater.rb +35 -7
- data/lib/http/response/parser.rb +98 -4
- data/lib/http/response/status/reasons.rb +2 -4
- data/lib/http/response/status.rb +141 -31
- data/lib/http/response.rb +219 -61
- data/lib/http/retriable/delay_calculator.rb +38 -11
- data/lib/http/retriable/errors.rb +21 -0
- data/lib/http/retriable/performer.rb +82 -38
- data/lib/http/session.rb +280 -0
- data/lib/http/timeout/global.rb +147 -34
- data/lib/http/timeout/null.rb +155 -9
- data/lib/http/timeout/per_operation.rb +139 -18
- data/lib/http/uri/normalizer.rb +82 -0
- data/lib/http/uri/parsing.rb +182 -0
- data/lib/http/uri.rb +289 -124
- data/lib/http/version.rb +2 -1
- data/lib/http.rb +11 -2
- data/sig/deps.rbs +122 -0
- data/sig/http.rbs +1619 -0
- data/test/http/base64_test.rb +28 -0
- data/test/http/client_test.rb +739 -0
- data/test/http/connection_test.rb +1533 -0
- data/test/http/content_type_test.rb +190 -0
- data/test/http/errors_test.rb +28 -0
- data/test/http/feature_test.rb +49 -0
- data/test/http/features/auto_deflate_test.rb +317 -0
- data/test/http/features/auto_inflate_test.rb +213 -0
- data/test/http/features/caching_test.rb +942 -0
- data/test/http/features/digest_auth_test.rb +996 -0
- data/test/http/features/instrumentation_test.rb +246 -0
- data/test/http/features/logging_test.rb +654 -0
- data/test/http/features/normalize_uri_test.rb +41 -0
- data/test/http/features/raise_error_test.rb +77 -0
- data/test/http/form_data/composite_io_test.rb +215 -0
- data/test/http/form_data/file_test.rb +255 -0
- data/test/http/form_data/fixtures/the-http-gem.info +1 -0
- data/test/http/form_data/multipart_test.rb +303 -0
- data/test/http/form_data/part_test.rb +90 -0
- data/test/http/form_data/urlencoded_test.rb +164 -0
- data/test/http/form_data_test.rb +232 -0
- data/test/http/headers/normalizer_test.rb +93 -0
- data/test/http/headers_test.rb +888 -0
- data/test/http/mime_type/json_test.rb +39 -0
- data/test/http/mime_type_test.rb +150 -0
- data/test/http/options/base_uri_test.rb +148 -0
- data/test/http/options/body_test.rb +21 -0
- data/test/http/options/features_test.rb +38 -0
- data/test/http/options/form_test.rb +21 -0
- data/test/http/options/headers_test.rb +32 -0
- data/test/http/options/json_test.rb +21 -0
- data/test/http/options/merge_test.rb +78 -0
- data/test/http/options/new_test.rb +37 -0
- data/test/http/options/proxy_test.rb +32 -0
- data/test/http/options_test.rb +575 -0
- data/test/http/redirector_test.rb +639 -0
- data/test/http/request/body_test.rb +318 -0
- data/test/http/request/builder_test.rb +623 -0
- data/test/http/request/writer_test.rb +391 -0
- data/test/http/request_test.rb +1733 -0
- data/test/http/response/body_test.rb +292 -0
- data/test/http/response/parser_test.rb +105 -0
- data/test/http/response/status_test.rb +322 -0
- data/test/http/response_test.rb +502 -0
- data/test/http/retriable/delay_calculator_test.rb +194 -0
- data/test/http/retriable/errors_test.rb +71 -0
- data/test/http/retriable/performer_test.rb +551 -0
- data/test/http/session_test.rb +424 -0
- data/test/http/timeout/global_test.rb +239 -0
- data/test/http/timeout/null_test.rb +218 -0
- data/test/http/timeout/per_operation_test.rb +220 -0
- data/test/http/uri/normalizer_test.rb +89 -0
- data/test/http/uri_test.rb +1140 -0
- data/test/http/version_test.rb +15 -0
- data/test/http_test.rb +818 -0
- data/test/regression_tests.rb +27 -0
- data/test/support/dummy_server/encoding_routes.rb +47 -0
- data/test/support/dummy_server/routes.rb +201 -0
- data/test/support/dummy_server/servlet.rb +81 -0
- data/test/support/dummy_server.rb +200 -0
- data/{spec → test}/support/fakeio.rb +2 -2
- data/test/support/http_handling_shared/connection_reuse_tests.rb +97 -0
- data/test/support/http_handling_shared/timeout_tests.rb +134 -0
- data/test/support/http_handling_shared.rb +11 -0
- data/test/support/proxy_server.rb +207 -0
- data/test/support/servers/runner.rb +67 -0
- data/{spec → test}/support/simplecov.rb +11 -2
- data/test/support/ssl_helper.rb +108 -0
- data/test/test_helper.rb +38 -0
- metadata +108 -168
- data/.github/workflows/ci.yml +0 -67
- data/.gitignore +0 -15
- data/.rspec +0 -1
- data/.rubocop/layout.yml +0 -8
- data/.rubocop/metrics.yml +0 -4
- data/.rubocop/rspec.yml +0 -9
- data/.rubocop/style.yml +0 -32
- data/.rubocop.yml +0 -11
- data/.rubocop_todo.yml +0 -219
- data/.yardopts +0 -2
- data/CHANGES_OLD.md +0 -1002
- data/Gemfile +0 -51
- data/Guardfile +0 -18
- data/Rakefile +0 -64
- data/lib/http/headers/mixin.rb +0 -34
- data/lib/http/retriable/client.rb +0 -37
- data/logo.png +0 -0
- data/spec/lib/http/client_spec.rb +0 -556
- data/spec/lib/http/connection_spec.rb +0 -88
- data/spec/lib/http/content_type_spec.rb +0 -47
- data/spec/lib/http/features/auto_deflate_spec.rb +0 -77
- data/spec/lib/http/features/auto_inflate_spec.rb +0 -86
- data/spec/lib/http/features/instrumentation_spec.rb +0 -81
- data/spec/lib/http/features/logging_spec.rb +0 -65
- data/spec/lib/http/features/raise_error_spec.rb +0 -62
- data/spec/lib/http/headers/mixin_spec.rb +0 -36
- data/spec/lib/http/headers/normalizer_spec.rb +0 -52
- data/spec/lib/http/headers_spec.rb +0 -527
- data/spec/lib/http/options/body_spec.rb +0 -15
- data/spec/lib/http/options/features_spec.rb +0 -33
- data/spec/lib/http/options/form_spec.rb +0 -15
- data/spec/lib/http/options/headers_spec.rb +0 -24
- data/spec/lib/http/options/json_spec.rb +0 -15
- data/spec/lib/http/options/merge_spec.rb +0 -68
- data/spec/lib/http/options/new_spec.rb +0 -30
- data/spec/lib/http/options/proxy_spec.rb +0 -20
- data/spec/lib/http/options_spec.rb +0 -13
- data/spec/lib/http/redirector_spec.rb +0 -530
- data/spec/lib/http/request/body_spec.rb +0 -211
- data/spec/lib/http/request/writer_spec.rb +0 -121
- data/spec/lib/http/request_spec.rb +0 -234
- data/spec/lib/http/response/body_spec.rb +0 -85
- data/spec/lib/http/response/parser_spec.rb +0 -74
- data/spec/lib/http/response/status_spec.rb +0 -253
- data/spec/lib/http/response_spec.rb +0 -262
- data/spec/lib/http/retriable/delay_calculator_spec.rb +0 -69
- data/spec/lib/http/retriable/performer_spec.rb +0 -302
- data/spec/lib/http/uri/normalizer_spec.rb +0 -95
- data/spec/lib/http/uri_spec.rb +0 -71
- data/spec/lib/http_spec.rb +0 -535
- data/spec/regression_specs.rb +0 -24
- data/spec/spec_helper.rb +0 -89
- data/spec/support/black_hole.rb +0 -13
- data/spec/support/dummy_server/servlet.rb +0 -203
- data/spec/support/dummy_server.rb +0 -44
- data/spec/support/fuubar.rb +0 -21
- data/spec/support/http_handling_shared.rb +0 -190
- data/spec/support/proxy_server.rb +0 -39
- data/spec/support/servers/config.rb +0 -11
- data/spec/support/servers/runner.rb +0 -19
- data/spec/support/ssl_helper.rb +0 -104
- /data/{spec → test}/support/capture_warning.rb +0 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class HTTPFeaturesAutoInflateTest < Minitest::Test
|
|
6
|
+
cover "HTTP::Features::AutoInflate*"
|
|
7
|
+
|
|
8
|
+
def feature
|
|
9
|
+
@feature ||= HTTP::Features::AutoInflate.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def connection
|
|
13
|
+
@connection ||= fake
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def proxy_hdrs
|
|
17
|
+
{ "Proxy-Connection" => "keep-alive" }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def build_response(headers: {})
|
|
21
|
+
HTTP::Response.new(
|
|
22
|
+
version: "1.1",
|
|
23
|
+
status: 200,
|
|
24
|
+
headers: headers,
|
|
25
|
+
proxy_headers: proxy_hdrs,
|
|
26
|
+
connection: connection,
|
|
27
|
+
request: HTTP::Request.new(verb: :get, uri: "http://example.com")
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# -- #wrap_response: no Content-Encoding --
|
|
32
|
+
|
|
33
|
+
def test_wrap_response_when_no_content_encoding_returns_original_response
|
|
34
|
+
response = build_response
|
|
35
|
+
result = feature.wrap_response(response)
|
|
36
|
+
|
|
37
|
+
assert_same response, result
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_wrap_response_for_identity_content_encoding_returns_original_response
|
|
41
|
+
response = build_response(headers: { content_encoding: "identity" })
|
|
42
|
+
result = feature.wrap_response(response)
|
|
43
|
+
|
|
44
|
+
assert_same response, result
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_wrap_response_for_unknown_content_encoding_returns_original_response
|
|
48
|
+
response = build_response(headers: { content_encoding: "not-supported" })
|
|
49
|
+
result = feature.wrap_response(response)
|
|
50
|
+
|
|
51
|
+
assert_same response, result
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# -- #wrap_response: deflate --
|
|
55
|
+
|
|
56
|
+
def test_wrap_response_for_deflate_returns_a_new_response
|
|
57
|
+
response = build_response(headers: { content_encoding: "deflate" })
|
|
58
|
+
result = feature.wrap_response(response)
|
|
59
|
+
|
|
60
|
+
refute_same response, result
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_wrap_response_for_deflate_returns_an_http_response
|
|
64
|
+
response = build_response(headers: { content_encoding: "deflate" })
|
|
65
|
+
result = feature.wrap_response(response)
|
|
66
|
+
|
|
67
|
+
assert_instance_of HTTP::Response, result
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_wrap_response_for_deflate_wraps_the_body_with_an_inflating_body
|
|
71
|
+
response = build_response(headers: { content_encoding: "deflate" })
|
|
72
|
+
result = feature.wrap_response(response)
|
|
73
|
+
|
|
74
|
+
assert_instance_of HTTP::Response::Body, result.body
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def test_wrap_response_for_deflate_preserves_the_status
|
|
78
|
+
response = build_response(headers: { content_encoding: "deflate" })
|
|
79
|
+
result = feature.wrap_response(response)
|
|
80
|
+
|
|
81
|
+
assert_equal response.status.code, result.status.code
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_wrap_response_for_deflate_preserves_the_version
|
|
85
|
+
response = build_response(headers: { content_encoding: "deflate" })
|
|
86
|
+
result = feature.wrap_response(response)
|
|
87
|
+
|
|
88
|
+
assert_equal response.version, result.version
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_wrap_response_for_deflate_preserves_the_headers
|
|
92
|
+
response = build_response(headers: { content_encoding: "deflate" })
|
|
93
|
+
result = feature.wrap_response(response)
|
|
94
|
+
|
|
95
|
+
assert_equal response.headers.to_h, result.headers.to_h
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_wrap_response_for_deflate_preserves_the_proxy_headers
|
|
99
|
+
response = build_response(headers: { content_encoding: "deflate" })
|
|
100
|
+
result = feature.wrap_response(response)
|
|
101
|
+
|
|
102
|
+
assert_equal response.proxy_headers.to_h, result.proxy_headers.to_h
|
|
103
|
+
refute_empty result.proxy_headers.to_h
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def test_wrap_response_for_deflate_preserves_the_request
|
|
107
|
+
response = build_response(headers: { content_encoding: "deflate" })
|
|
108
|
+
result = feature.wrap_response(response)
|
|
109
|
+
|
|
110
|
+
assert_equal response.request, result.request
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def test_wrap_response_for_deflate_wraps_body_stream_in_an_inflater
|
|
114
|
+
response = build_response(headers: { content_encoding: "deflate" })
|
|
115
|
+
result = feature.wrap_response(response)
|
|
116
|
+
stream = result.body.instance_variable_get(:@stream)
|
|
117
|
+
|
|
118
|
+
assert_instance_of HTTP::Response::Inflater, stream
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def test_wrap_response_for_deflate_passes_original_connection_to_inflater
|
|
122
|
+
response = build_response(headers: { content_encoding: "deflate" })
|
|
123
|
+
result = feature.wrap_response(response)
|
|
124
|
+
stream = result.body.instance_variable_get(:@stream)
|
|
125
|
+
|
|
126
|
+
assert_same connection, stream.connection
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def test_wrap_response_for_deflate_preserves_the_connection_on_wrapped_response
|
|
130
|
+
response = build_response(headers: { content_encoding: "deflate" })
|
|
131
|
+
result = feature.wrap_response(response)
|
|
132
|
+
|
|
133
|
+
assert_same connection, result.connection
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# -- #wrap_response: gzip --
|
|
137
|
+
|
|
138
|
+
def test_wrap_response_for_gzip_returns_a_new_response_wrapping_inflated_body
|
|
139
|
+
response = build_response(headers: { content_encoding: "gzip" })
|
|
140
|
+
result = feature.wrap_response(response)
|
|
141
|
+
|
|
142
|
+
refute_same response, result
|
|
143
|
+
assert_instance_of HTTP::Response::Body, result.body
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# -- #wrap_response: x-gzip --
|
|
147
|
+
|
|
148
|
+
def test_wrap_response_for_x_gzip_returns_a_new_response_wrapping_inflated_body
|
|
149
|
+
response = build_response(headers: { content_encoding: "x-gzip" })
|
|
150
|
+
result = feature.wrap_response(response)
|
|
151
|
+
|
|
152
|
+
refute_same response, result
|
|
153
|
+
assert_instance_of HTTP::Response::Body, result.body
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# -- #wrap_response: gzip with charset --
|
|
157
|
+
|
|
158
|
+
def test_wrap_response_for_gzip_with_charset_preserves_encoding
|
|
159
|
+
response = build_response(headers: { content_encoding: "gzip", content_type: "text/html; charset=Shift_JIS" })
|
|
160
|
+
result = feature.wrap_response(response)
|
|
161
|
+
|
|
162
|
+
assert_equal Encoding::Shift_JIS, result.body.encoding
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# -- #wrap_response: response with uri --
|
|
166
|
+
|
|
167
|
+
def test_wrap_response_preserves_uri_in_wrapped_response
|
|
168
|
+
response = HTTP::Response.new(
|
|
169
|
+
version: "1.1",
|
|
170
|
+
status: 200,
|
|
171
|
+
headers: { content_encoding: "gzip" },
|
|
172
|
+
connection: connection,
|
|
173
|
+
request: HTTP::Request.new(verb: :get, uri: "https://example.com")
|
|
174
|
+
)
|
|
175
|
+
result = feature.wrap_response(response)
|
|
176
|
+
|
|
177
|
+
assert_equal HTTP::URI.parse("https://example.com"), result.uri
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# -- #stream_for --
|
|
181
|
+
|
|
182
|
+
def test_stream_for_returns_an_http_response_body
|
|
183
|
+
result = feature.stream_for(connection)
|
|
184
|
+
|
|
185
|
+
assert_instance_of HTTP::Response::Body, result
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def test_stream_for_defaults_to_binary_encoding
|
|
189
|
+
result = feature.stream_for(connection)
|
|
190
|
+
|
|
191
|
+
assert_equal Encoding::BINARY, result.encoding
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def test_stream_for_uses_the_given_encoding
|
|
195
|
+
result = feature.stream_for(connection, encoding: Encoding::UTF_8)
|
|
196
|
+
|
|
197
|
+
assert_equal Encoding::UTF_8, result.encoding
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def test_stream_for_wraps_the_connection_in_an_inflater
|
|
201
|
+
result = feature.stream_for(connection)
|
|
202
|
+
stream = result.instance_variable_get(:@stream)
|
|
203
|
+
|
|
204
|
+
assert_instance_of HTTP::Response::Inflater, stream
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def test_stream_for_passes_the_connection_to_the_inflater
|
|
208
|
+
result = feature.stream_for(connection)
|
|
209
|
+
stream = result.instance_variable_get(:@stream)
|
|
210
|
+
|
|
211
|
+
assert_same connection, stream.connection
|
|
212
|
+
end
|
|
213
|
+
end
|