httpx 0.24.7 → 1.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.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +0 -48
  3. data/README.md +4 -13
  4. data/doc/release_notes/0_24_4.md +3 -3
  5. data/doc/release_notes/1_0_0.md +60 -0
  6. data/lib/httpx/adapters/datadog.rb +40 -141
  7. data/lib/httpx/adapters/faraday.rb +9 -52
  8. data/lib/httpx/adapters/webmock.rb +2 -7
  9. data/lib/httpx/altsvc.rb +4 -22
  10. data/lib/httpx/base64.rb +27 -0
  11. data/lib/httpx/chainable.rb +0 -23
  12. data/lib/httpx/connection.rb +11 -32
  13. data/lib/httpx/domain_name.rb +5 -12
  14. data/lib/httpx/errors.rb +0 -2
  15. data/lib/httpx/extensions.rb +0 -124
  16. data/lib/httpx/io/ssl.rb +26 -59
  17. data/lib/httpx/io/tcp.rb +27 -68
  18. data/lib/httpx/io/udp.rb +13 -48
  19. data/lib/httpx/io/unix.rb +1 -8
  20. data/lib/httpx/loggable.rb +4 -19
  21. data/lib/httpx/options.rb +24 -84
  22. data/lib/httpx/plugins/{authentication → auth}/basic.rb +1 -5
  23. data/lib/httpx/plugins/{authentication → auth}/digest.rb +2 -5
  24. data/lib/httpx/plugins/{authentication → auth}/ntlm.rb +1 -3
  25. data/lib/httpx/plugins/{authentication → auth}/socks5.rb +0 -2
  26. data/lib/httpx/plugins/auth.rb +25 -0
  27. data/lib/httpx/plugins/aws_sigv4.rb +0 -1
  28. data/lib/httpx/plugins/{basic_authentication.rb → basic_auth.rb} +5 -6
  29. data/lib/httpx/plugins/brotli.rb +50 -0
  30. data/lib/httpx/plugins/circuit_breaker/circuit.rb +40 -16
  31. data/lib/httpx/plugins/circuit_breaker/circuit_store.rb +16 -5
  32. data/lib/httpx/plugins/circuit_breaker.rb +11 -4
  33. data/lib/httpx/plugins/cookies/set_cookie_parser.rb +0 -2
  34. data/lib/httpx/plugins/cookies.rb +1 -1
  35. data/lib/httpx/plugins/{digest_authentication.rb → digest_auth.rb} +5 -5
  36. data/lib/httpx/plugins/follow_redirects.rb +21 -24
  37. data/lib/httpx/plugins/grpc/grpc_encoding.rb +82 -0
  38. data/lib/httpx/plugins/grpc/message.rb +7 -39
  39. data/lib/httpx/plugins/grpc.rb +19 -37
  40. data/lib/httpx/plugins/h2c.rb +0 -1
  41. data/lib/httpx/plugins/{ntlm_authentication.rb → ntlm_auth.rb} +5 -5
  42. data/lib/httpx/plugins/oauth.rb +2 -2
  43. data/lib/httpx/plugins/proxy/http.rb +0 -2
  44. data/lib/httpx/plugins/proxy/socks4.rb +0 -4
  45. data/lib/httpx/plugins/proxy/socks5.rb +1 -5
  46. data/lib/httpx/plugins/proxy.rb +3 -32
  47. data/lib/httpx/plugins/retries.rb +3 -4
  48. data/lib/httpx/plugins/stream.rb +4 -6
  49. data/lib/httpx/punycode.rb +9 -291
  50. data/lib/httpx/request/body.rb +145 -0
  51. data/lib/httpx/request.rb +2 -119
  52. data/lib/httpx/resolver/https.rb +1 -1
  53. data/lib/httpx/resolver/native.rb +6 -14
  54. data/lib/httpx/resolver/resolver.rb +1 -1
  55. data/lib/httpx/resolver/system.rb +11 -9
  56. data/lib/httpx/response/body.rb +206 -0
  57. data/lib/httpx/response/buffer.rb +90 -0
  58. data/lib/httpx/response.rb +5 -208
  59. data/lib/httpx/selector.rb +0 -2
  60. data/lib/httpx/session.rb +0 -10
  61. data/lib/httpx/transcoder/body.rb +0 -1
  62. data/lib/httpx/transcoder/deflate.rb +37 -0
  63. data/lib/httpx/transcoder/form.rb +52 -32
  64. data/lib/httpx/transcoder/gzip.rb +74 -0
  65. data/lib/httpx/transcoder/json.rb +2 -4
  66. data/lib/httpx/transcoder/multipart/decoder.rb +139 -0
  67. data/lib/httpx/{plugins → transcoder}/multipart/encoder.rb +3 -3
  68. data/lib/httpx/{plugins → transcoder}/multipart/mime_type_detector.rb +1 -1
  69. data/lib/httpx/{plugins → transcoder}/multipart/part.rb +3 -2
  70. data/lib/httpx/transcoder/multipart.rb +17 -0
  71. data/lib/httpx/transcoder/utils/body_reader.rb +46 -0
  72. data/lib/httpx/transcoder/utils/deflater.rb +72 -0
  73. data/lib/httpx/transcoder/xml.rb +0 -2
  74. data/lib/httpx/transcoder.rb +2 -2
  75. data/lib/httpx/utils.rb +10 -20
  76. data/lib/httpx/version.rb +1 -1
  77. data/lib/httpx.rb +0 -8
  78. data/sig/chainable.rbs +5 -6
  79. data/sig/connection.rbs +0 -1
  80. data/sig/errors.rbs +0 -3
  81. data/sig/httpx.rbs +2 -1
  82. data/sig/io/unix.rbs +1 -1
  83. data/sig/options.rbs +12 -8
  84. data/sig/plugins/{authentication → auth}/basic.rbs +0 -2
  85. data/sig/plugins/auth.rbs +13 -0
  86. data/sig/plugins/{basic_authentication.rbs → basic_auth.rbs} +2 -2
  87. data/sig/plugins/brotli.rbs +22 -0
  88. data/sig/plugins/circuit_breaker.rbs +7 -3
  89. data/sig/plugins/compression.rbs +0 -2
  90. data/sig/plugins/{digest_authentication.rbs → digest_auth.rbs} +2 -2
  91. data/sig/plugins/follow_redirects.rbs +0 -1
  92. data/sig/plugins/grpc/call.rbs +19 -0
  93. data/sig/plugins/grpc/grpc_encoding.rbs +33 -0
  94. data/sig/plugins/grpc/message.rbs +17 -0
  95. data/sig/plugins/grpc.rbs +2 -32
  96. data/sig/plugins/{ntlm_authentication.rbs → ntlm_auth.rbs} +2 -2
  97. data/sig/plugins/oauth.rbs +1 -1
  98. data/sig/plugins/proxy/socks4.rbs +2 -3
  99. data/sig/plugins/proxy/socks5.rbs +0 -1
  100. data/sig/plugins/proxy/ssh.rbs +1 -1
  101. data/sig/plugins/response_cache.rbs +5 -2
  102. data/sig/request/body.rbs +42 -0
  103. data/sig/request.rbs +1 -27
  104. data/sig/resolver/resolver.rbs +1 -1
  105. data/sig/response/body.rbs +52 -0
  106. data/sig/response/buffer.rbs +24 -0
  107. data/sig/response.rbs +0 -39
  108. data/sig/transcoder/body.rbs +4 -3
  109. data/sig/transcoder/deflate.rbs +11 -0
  110. data/sig/transcoder/form.rbs +5 -3
  111. data/sig/transcoder/gzip.rbs +24 -0
  112. data/sig/transcoder/json.rbs +4 -2
  113. data/sig/{plugins → transcoder}/multipart.rbs +3 -10
  114. data/sig/transcoder/utils/body_reader.rbs +15 -0
  115. data/sig/transcoder/utils/deflater.rbs +29 -0
  116. data/sig/transcoder.rbs +18 -2
  117. metadata +50 -36
  118. data/doc/release_notes/0_24_7.md +0 -10
  119. data/lib/httpx/plugins/authentication.rb +0 -24
  120. data/lib/httpx/plugins/compression/brotli.rb +0 -54
  121. data/lib/httpx/plugins/compression/deflate.rb +0 -54
  122. data/lib/httpx/plugins/compression/gzip.rb +0 -90
  123. data/lib/httpx/plugins/compression.rb +0 -165
  124. data/lib/httpx/plugins/multipart/decoder.rb +0 -137
  125. data/lib/httpx/plugins/multipart.rb +0 -96
  126. data/sig/plugins/authentication.rbs +0 -13
  127. data/sig/plugins/compression/brotli.rbs +0 -21
  128. data/sig/plugins/compression/deflate.rbs +0 -17
  129. data/sig/plugins/compression/gzip.rbs +0 -29
  130. /data/sig/plugins/{authentication → auth}/digest.rbs +0 -0
  131. /data/sig/plugins/{authentication → auth}/ntlm.rbs +0 -0
  132. /data/sig/plugins/{authentication → auth}/socks5.rbs +0 -0
@@ -0,0 +1,29 @@
1
+ module HTTPX
2
+ module Transcoder
3
+ class Deflater
4
+ extend Forwardable
5
+
6
+ @body: BodyReader
7
+ @buffer: Response::Buffer?
8
+ @body: _Encoder | StringIO
9
+ @closed: bool
10
+
11
+ attr_reader content_type: String
12
+
13
+ def initialize: (_Encoder body) -> void
14
+
15
+ def bytesize: () -> (Integer | Float)
16
+
17
+ def read: (?int? length, ?string outbuf) -> String?
18
+
19
+ def close: () -> void
20
+
21
+ def deflate: (String? chunk) -> String?
22
+
23
+ private
24
+
25
+ def buffer_deflate!: () -> void
26
+
27
+ end
28
+ end
29
+ end
data/sig/transcoder.rbs CHANGED
@@ -1,7 +1,7 @@
1
1
  module HTTPX
2
- type bodyIO = _Reader | _Each[[String, untyped]] | _ToS
2
+ type bodyIO = _Reader | _Each[String] | _ToS
3
3
 
4
- type body_encoder = Transcoder::_Encoder | _Each[String]
4
+ type body_encoder = (Transcoder::_Encoder & _ToS) | (Transcoder::_Encoder & _Reader) | (Transcoder::_Encoder & _Each[String])
5
5
 
6
6
  module Transcoder
7
7
  def self?.normalize_keys: [U] (_ToS key, _ToAry[untyped] | _ToHash[_ToS, untyped] | untyped value, ?(^(untyped value) -> bool | nil) cond) { (String, ?untyped) -> U } -> U
@@ -18,10 +18,26 @@ module HTTPX
18
18
 
19
19
  interface _Encoder
20
20
  def bytesize: () -> (Integer | Float)
21
+
22
+ def content_type: () -> String
21
23
  end
22
24
 
23
25
  interface _Decoder
24
26
  def call: (Response response, *untyped) -> untyped
25
27
  end
28
+
29
+ interface _Inflater
30
+ def initialize: (Integer | Float bytesize) -> void
31
+
32
+ def call: (String chunk) -> String
33
+ end
34
+
35
+ interface _Deflater
36
+ def initialize: (Response body) -> void
37
+
38
+ def deflate: () -> void
39
+
40
+ def call: (StringIO | File buffer, ?chunk_size: Integer) ?{ (String chunk) -> void } -> void
41
+ end
26
42
  end
27
43
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.7
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-13 00:00:00.000000000 Z
11
+ date: 2023-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-2-next
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "<"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "<"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.0.0
27
27
  description: A client library for making HTTP requests from Ruby.
@@ -106,7 +106,6 @@ extra_rdoc_files:
106
106
  - doc/release_notes/0_24_4.md
107
107
  - doc/release_notes/0_24_5.md
108
108
  - doc/release_notes/0_24_6.md
109
- - doc/release_notes/0_24_7.md
110
109
  - doc/release_notes/0_2_0.md
111
110
  - doc/release_notes/0_2_1.md
112
111
  - doc/release_notes/0_3_0.md
@@ -128,6 +127,7 @@ extra_rdoc_files:
128
127
  - doc/release_notes/0_8_1.md
129
128
  - doc/release_notes/0_8_2.md
130
129
  - doc/release_notes/0_9_0.md
130
+ - doc/release_notes/1_0_0.md
131
131
  files:
132
132
  - LICENSE.txt
133
133
  - README.md
@@ -205,7 +205,6 @@ files:
205
205
  - doc/release_notes/0_24_4.md
206
206
  - doc/release_notes/0_24_5.md
207
207
  - doc/release_notes/0_24_6.md
208
- - doc/release_notes/0_24_7.md
209
208
  - doc/release_notes/0_2_0.md
210
209
  - doc/release_notes/0_2_1.md
211
210
  - doc/release_notes/0_3_0.md
@@ -227,12 +226,14 @@ files:
227
226
  - doc/release_notes/0_8_1.md
228
227
  - doc/release_notes/0_8_2.md
229
228
  - doc/release_notes/0_9_0.md
229
+ - doc/release_notes/1_0_0.md
230
230
  - lib/httpx.rb
231
231
  - lib/httpx/adapters/datadog.rb
232
232
  - lib/httpx/adapters/faraday.rb
233
233
  - lib/httpx/adapters/sentry.rb
234
234
  - lib/httpx/adapters/webmock.rb
235
235
  - lib/httpx/altsvc.rb
236
+ - lib/httpx/base64.rb
236
237
  - lib/httpx/buffer.rb
237
238
  - lib/httpx/callbacks.rb
238
239
  - lib/httpx/chainable.rb
@@ -251,39 +252,32 @@ files:
251
252
  - lib/httpx/loggable.rb
252
253
  - lib/httpx/options.rb
253
254
  - lib/httpx/parser/http1.rb
254
- - lib/httpx/plugins/authentication.rb
255
- - lib/httpx/plugins/authentication/basic.rb
256
- - lib/httpx/plugins/authentication/digest.rb
257
- - lib/httpx/plugins/authentication/ntlm.rb
258
- - lib/httpx/plugins/authentication/socks5.rb
255
+ - lib/httpx/plugins/auth.rb
256
+ - lib/httpx/plugins/auth/basic.rb
257
+ - lib/httpx/plugins/auth/digest.rb
258
+ - lib/httpx/plugins/auth/ntlm.rb
259
+ - lib/httpx/plugins/auth/socks5.rb
259
260
  - lib/httpx/plugins/aws_sdk_authentication.rb
260
261
  - lib/httpx/plugins/aws_sigv4.rb
261
- - lib/httpx/plugins/basic_authentication.rb
262
+ - lib/httpx/plugins/basic_auth.rb
263
+ - lib/httpx/plugins/brotli.rb
262
264
  - lib/httpx/plugins/circuit_breaker.rb
263
265
  - lib/httpx/plugins/circuit_breaker/circuit.rb
264
266
  - lib/httpx/plugins/circuit_breaker/circuit_store.rb
265
- - lib/httpx/plugins/compression.rb
266
- - lib/httpx/plugins/compression/brotli.rb
267
- - lib/httpx/plugins/compression/deflate.rb
268
- - lib/httpx/plugins/compression/gzip.rb
269
267
  - lib/httpx/plugins/cookies.rb
270
268
  - lib/httpx/plugins/cookies/cookie.rb
271
269
  - lib/httpx/plugins/cookies/jar.rb
272
270
  - lib/httpx/plugins/cookies/set_cookie_parser.rb
273
- - lib/httpx/plugins/digest_authentication.rb
271
+ - lib/httpx/plugins/digest_auth.rb
274
272
  - lib/httpx/plugins/expect.rb
275
273
  - lib/httpx/plugins/follow_redirects.rb
276
274
  - lib/httpx/plugins/grpc.rb
277
275
  - lib/httpx/plugins/grpc/call.rb
276
+ - lib/httpx/plugins/grpc/grpc_encoding.rb
278
277
  - lib/httpx/plugins/grpc/message.rb
279
278
  - lib/httpx/plugins/h2c.rb
280
279
  - lib/httpx/plugins/internal_telemetry.rb
281
- - lib/httpx/plugins/multipart.rb
282
- - lib/httpx/plugins/multipart/decoder.rb
283
- - lib/httpx/plugins/multipart/encoder.rb
284
- - lib/httpx/plugins/multipart/mime_type_detector.rb
285
- - lib/httpx/plugins/multipart/part.rb
286
- - lib/httpx/plugins/ntlm_authentication.rb
280
+ - lib/httpx/plugins/ntlm_auth.rb
287
281
  - lib/httpx/plugins/oauth.rb
288
282
  - lib/httpx/plugins/persistent.rb
289
283
  - lib/httpx/plugins/proxy.rb
@@ -305,6 +299,7 @@ files:
305
299
  - lib/httpx/pool.rb
306
300
  - lib/httpx/punycode.rb
307
301
  - lib/httpx/request.rb
302
+ - lib/httpx/request/body.rb
308
303
  - lib/httpx/resolver.rb
309
304
  - lib/httpx/resolver/https.rb
310
305
  - lib/httpx/resolver/multi.rb
@@ -312,6 +307,8 @@ files:
312
307
  - lib/httpx/resolver/resolver.rb
313
308
  - lib/httpx/resolver/system.rb
314
309
  - lib/httpx/response.rb
310
+ - lib/httpx/response/body.rb
311
+ - lib/httpx/response/buffer.rb
315
312
  - lib/httpx/selector.rb
316
313
  - lib/httpx/session.rb
317
314
  - lib/httpx/session2.rb
@@ -320,8 +317,17 @@ files:
320
317
  - lib/httpx/transcoder.rb
321
318
  - lib/httpx/transcoder/body.rb
322
319
  - lib/httpx/transcoder/chunker.rb
320
+ - lib/httpx/transcoder/deflate.rb
323
321
  - lib/httpx/transcoder/form.rb
322
+ - lib/httpx/transcoder/gzip.rb
324
323
  - lib/httpx/transcoder/json.rb
324
+ - lib/httpx/transcoder/multipart.rb
325
+ - lib/httpx/transcoder/multipart/decoder.rb
326
+ - lib/httpx/transcoder/multipart/encoder.rb
327
+ - lib/httpx/transcoder/multipart/mime_type_detector.rb
328
+ - lib/httpx/transcoder/multipart/part.rb
329
+ - lib/httpx/transcoder/utils/body_reader.rb
330
+ - lib/httpx/transcoder/utils/deflater.rb
325
331
  - lib/httpx/transcoder/xml.rb
326
332
  - lib/httpx/utils.rb
327
333
  - lib/httpx/version.rb
@@ -343,29 +349,29 @@ files:
343
349
  - sig/loggable.rbs
344
350
  - sig/options.rbs
345
351
  - sig/parser/http1.rbs
346
- - sig/plugins/authentication.rbs
347
- - sig/plugins/authentication/basic.rbs
348
- - sig/plugins/authentication/digest.rbs
349
- - sig/plugins/authentication/ntlm.rbs
350
- - sig/plugins/authentication/socks5.rbs
352
+ - sig/plugins/auth.rbs
353
+ - sig/plugins/auth/basic.rbs
354
+ - sig/plugins/auth/digest.rbs
355
+ - sig/plugins/auth/ntlm.rbs
356
+ - sig/plugins/auth/socks5.rbs
351
357
  - sig/plugins/aws_sdk_authentication.rbs
352
358
  - sig/plugins/aws_sigv4.rbs
353
- - sig/plugins/basic_authentication.rbs
359
+ - sig/plugins/basic_auth.rbs
360
+ - sig/plugins/brotli.rbs
354
361
  - sig/plugins/circuit_breaker.rbs
355
362
  - sig/plugins/compression.rbs
356
- - sig/plugins/compression/brotli.rbs
357
- - sig/plugins/compression/deflate.rbs
358
- - sig/plugins/compression/gzip.rbs
359
363
  - sig/plugins/cookies.rbs
360
364
  - sig/plugins/cookies/cookie.rbs
361
365
  - sig/plugins/cookies/jar.rbs
362
- - sig/plugins/digest_authentication.rbs
366
+ - sig/plugins/digest_auth.rbs
363
367
  - sig/plugins/expect.rbs
364
368
  - sig/plugins/follow_redirects.rbs
365
369
  - sig/plugins/grpc.rbs
370
+ - sig/plugins/grpc/call.rbs
371
+ - sig/plugins/grpc/grpc_encoding.rbs
372
+ - sig/plugins/grpc/message.rbs
366
373
  - sig/plugins/h2c.rbs
367
- - sig/plugins/multipart.rbs
368
- - sig/plugins/ntlm_authentication.rbs
374
+ - sig/plugins/ntlm_auth.rbs
369
375
  - sig/plugins/oauth.rbs
370
376
  - sig/plugins/persistent.rbs
371
377
  - sig/plugins/proxy.rbs
@@ -381,6 +387,7 @@ files:
381
387
  - sig/plugins/upgrade.rbs
382
388
  - sig/pool.rbs
383
389
  - sig/request.rbs
390
+ - sig/request/body.rbs
384
391
  - sig/resolver.rbs
385
392
  - sig/resolver/https.rbs
386
393
  - sig/resolver/multi.rbs
@@ -388,14 +395,21 @@ files:
388
395
  - sig/resolver/resolver.rbs
389
396
  - sig/resolver/system.rbs
390
397
  - sig/response.rbs
398
+ - sig/response/body.rbs
399
+ - sig/response/buffer.rbs
391
400
  - sig/selector.rbs
392
401
  - sig/session.rbs
393
402
  - sig/timers.rbs
394
403
  - sig/transcoder.rbs
395
404
  - sig/transcoder/body.rbs
396
405
  - sig/transcoder/chunker.rbs
406
+ - sig/transcoder/deflate.rbs
397
407
  - sig/transcoder/form.rbs
408
+ - sig/transcoder/gzip.rbs
398
409
  - sig/transcoder/json.rbs
410
+ - sig/transcoder/multipart.rbs
411
+ - sig/transcoder/utils/body_reader.rbs
412
+ - sig/transcoder/utils/deflater.rbs
399
413
  - sig/transcoder/xml.rbs
400
414
  - sig/utils.rbs
401
415
  homepage: https://gitlab.com/os85/httpx
@@ -416,7 +430,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
416
430
  requirements:
417
431
  - - ">="
418
432
  - !ruby/object:Gem::Version
419
- version: '0'
433
+ version: 2.7.0
420
434
  required_rubygems_version: !ruby/object:Gem::Requirement
421
435
  requirements:
422
436
  - - ">="
@@ -1,10 +0,0 @@
1
- # 0.24.6
2
-
3
- ## dependencies
4
-
5
- `http-2-next` last supported version for the 0.x series is the last version before v1. This shoul ensure that older versions of `httpx` won't be affected by any of the recent breaking changes.
6
-
7
- ## Bugfixes
8
-
9
- * `grpc`: setup of rpc calls from camel-cased symbols has been fixed. As an improvement, the GRPC-enabled session will now support both snake-cased, as well as camel-cased calls.
10
- * `datadog` adapter has now been patched to support the most recent breaking changes of `ddtrace` configuration DSL (`env_to_bool` is no longer supported).
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module HTTPX
4
- module Plugins
5
- #
6
- # This plugin adds a shim +authentication+ method to the session, which will fill
7
- # the HTTP Authorization header.
8
- #
9
- # https://gitlab.com/os85/httpx/wikis/Authentication#authentication
10
- #
11
- module Authentication
12
- module InstanceMethods
13
- def authentication(token)
14
- with(headers: { "authorization" => token })
15
- end
16
-
17
- def bearer_auth(token)
18
- authentication("Bearer #{token}")
19
- end
20
- end
21
- end
22
- register_plugin :authentication, Authentication
23
- end
24
- end
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module HTTPX
4
- module Plugins
5
- module Compression
6
- module Brotli
7
- class << self
8
- def load_dependencies(klass)
9
- require "brotli"
10
- klass.plugin(:compression)
11
- end
12
-
13
- def extra_options(options)
14
- options.merge(encodings: options.encodings.merge("br" => self))
15
- end
16
- end
17
-
18
- module Deflater
19
- module_function
20
-
21
- def deflate(raw, buffer = "".b, chunk_size: 16_384)
22
- while (chunk = raw.read(chunk_size))
23
- compressed = ::Brotli.deflate(chunk)
24
- buffer << compressed
25
- yield compressed if block_given?
26
- end
27
- buffer
28
- end
29
- end
30
-
31
- class Inflater
32
- def initialize(bytesize)
33
- @bytesize = bytesize
34
- end
35
-
36
- def inflate(chunk)
37
- ::Brotli.inflate(chunk)
38
- end
39
- end
40
-
41
- module_function
42
-
43
- def deflater
44
- Deflater
45
- end
46
-
47
- def inflater(bytesize)
48
- Inflater.new(bytesize)
49
- end
50
- end
51
- end
52
- register_plugin :"compression/brotli", Compression::Brotli
53
- end
54
- end
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module HTTPX
4
- module Plugins
5
- module Compression
6
- module Deflate
7
- class << self
8
- def load_dependencies(_klass)
9
- require "stringio"
10
- require "zlib"
11
- end
12
-
13
- def configure(klass)
14
- klass.plugin(:"compression/gzip")
15
- end
16
-
17
- def extra_options(options)
18
- options.merge(encodings: options.encodings.merge("deflate" => self))
19
- end
20
- end
21
-
22
- module Deflater
23
- module_function
24
-
25
- def deflate(raw, buffer = "".b, chunk_size: 16_384)
26
- deflater = Zlib::Deflate.new
27
- while (chunk = raw.read(chunk_size))
28
- compressed = deflater.deflate(chunk)
29
- buffer << compressed
30
- yield compressed if block_given?
31
- end
32
- last = deflater.finish
33
- buffer << last
34
- yield last if block_given?
35
- buffer
36
- ensure
37
- deflater.close if deflater
38
- end
39
- end
40
-
41
- module_function
42
-
43
- def deflater
44
- Deflater
45
- end
46
-
47
- def inflater(bytesize)
48
- GZIP::Inflater.new(bytesize)
49
- end
50
- end
51
- end
52
- register_plugin :"compression/deflate", Compression::Deflate
53
- end
54
- end
@@ -1,90 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "forwardable"
4
-
5
- module HTTPX
6
- module Plugins
7
- module Compression
8
- module GZIP
9
- class << self
10
- def load_dependencies(*)
11
- require "zlib"
12
- end
13
-
14
- def extra_options(options)
15
- options.merge(encodings: options.encodings.merge("gzip" => self))
16
- end
17
- end
18
-
19
- class Deflater
20
- def initialize
21
- @compressed_chunk = "".b
22
- end
23
-
24
- def deflate(raw, buffer = "".b, chunk_size: 16_384)
25
- gzip = Zlib::GzipWriter.new(self)
26
-
27
- begin
28
- while (chunk = raw.read(chunk_size))
29
- gzip.write(chunk)
30
- gzip.flush
31
- compressed = compressed_chunk
32
- buffer << compressed
33
- yield compressed if block_given?
34
- end
35
- ensure
36
- gzip.close
37
- end
38
-
39
- return unless (compressed = compressed_chunk)
40
-
41
- buffer << compressed
42
- yield compressed if block_given?
43
- buffer
44
- end
45
-
46
- private
47
-
48
- def write(chunk)
49
- @compressed_chunk << chunk
50
- end
51
-
52
- def compressed_chunk
53
- @compressed_chunk.dup
54
- ensure
55
- @compressed_chunk.clear
56
- end
57
- end
58
-
59
- class Inflater
60
- def initialize(bytesize)
61
- @inflater = Zlib::Inflate.new(Zlib::MAX_WBITS + 32)
62
- @bytesize = bytesize
63
- @buffer = nil
64
- end
65
-
66
- def inflate(chunk)
67
- buffer = @inflater.inflate(chunk)
68
- @bytesize -= chunk.bytesize
69
- if @bytesize <= 0
70
- buffer << @inflater.finish
71
- @inflater.close
72
- end
73
- buffer
74
- end
75
- end
76
-
77
- module_function
78
-
79
- def deflater
80
- Deflater.new
81
- end
82
-
83
- def inflater(bytesize)
84
- Inflater.new(bytesize)
85
- end
86
- end
87
- end
88
- register_plugin :"compression/gzip", Compression::GZIP
89
- end
90
- end
@@ -1,165 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module HTTPX
4
- module Plugins
5
- #
6
- # This plugin adds compression support. Namely it:
7
- #
8
- # * Compresses the request body when passed a supported "Content-Encoding" mime-type;
9
- # * Decompresses the response body from a supported "Content-Encoding" mime-type;
10
- #
11
- # It supports both *gzip* and *deflate*.
12
- #
13
- # https://gitlab.com/os85/httpx/wikis/Compression
14
- #
15
- module Compression
16
- class << self
17
- def configure(klass)
18
- klass.plugin(:"compression/gzip")
19
- klass.plugin(:"compression/deflate")
20
- end
21
-
22
- def extra_options(options)
23
- options.merge(encodings: {})
24
- end
25
- end
26
-
27
- module OptionsMethods
28
- def option_compression_threshold_size(value)
29
- bytes = Integer(value)
30
- raise TypeError, ":compression_threshold_size must be positive" unless bytes.positive?
31
-
32
- bytes
33
- end
34
-
35
- def option_encodings(value)
36
- raise TypeError, ":encodings must be an Hash" unless value.is_a?(Hash)
37
-
38
- value
39
- end
40
- end
41
-
42
- module RequestMethods
43
- def initialize(*)
44
- super
45
- # forego compression in the Range cases
46
- if @headers.key?("range")
47
- @headers.delete("accept-encoding")
48
- else
49
- @headers["accept-encoding"] ||= @options.encodings.keys
50
- end
51
- end
52
- end
53
-
54
- module RequestBodyMethods
55
- def initialize(*, options)
56
- super
57
- return if @body.nil?
58
-
59
- threshold = options.compression_threshold_size
60
- return if threshold && !unbounded_body? && @body.bytesize < threshold
61
-
62
- @headers.get("content-encoding").each do |encoding|
63
- next if encoding == "identity"
64
-
65
- next unless options.encodings.key?(encoding)
66
-
67
- @body = Encoder.new(@body, options.encodings[encoding].deflater)
68
- end
69
- @headers["content-length"] = @body.bytesize unless unbounded_body?
70
- end
71
- end
72
-
73
- module ResponseBodyMethods
74
- using ArrayExtensions::FilterMap
75
-
76
- attr_reader :encodings
77
-
78
- def initialize(*)
79
- @encodings = []
80
-
81
- super
82
-
83
- return unless @headers.key?("content-encoding")
84
-
85
- # remove encodings that we are able to decode
86
- @headers["content-encoding"] = @headers.get("content-encoding") - @encodings
87
-
88
- compressed_length = if @headers.key?("content-length")
89
- @headers["content-length"].to_i
90
- else
91
- Float::INFINITY
92
- end
93
-
94
- @_inflaters = @headers.get("content-encoding").filter_map do |encoding|
95
- next if encoding == "identity"
96
-
97
- next unless @options.encodings.key?(encoding)
98
-
99
- inflater = @options.encodings[encoding].inflater(compressed_length)
100
- # do not uncompress if there is no decoder available. In fact, we can't reliably
101
- # continue decompressing beyond that, so ignore.
102
- break unless inflater
103
-
104
- @encodings << encoding
105
- inflater
106
- end
107
-
108
- # this can happen if the only declared encoding is "identity"
109
- remove_instance_variable(:@_inflaters) if @_inflaters.empty?
110
- end
111
-
112
- def write(chunk)
113
- return super unless defined?(@_inflaters) && !chunk.empty?
114
-
115
- chunk = decompress(chunk)
116
- super(chunk)
117
- end
118
-
119
- private
120
-
121
- def decompress(buffer)
122
- @_inflaters.reverse_each do |inflater|
123
- buffer = inflater.inflate(buffer)
124
- end
125
- buffer
126
- end
127
- end
128
-
129
- class Encoder
130
- attr_reader :content_type
131
-
132
- def initialize(body, deflater)
133
- @content_type = body.content_type
134
- @body = body.respond_to?(:read) ? body : StringIO.new(body.to_s)
135
- @buffer = StringIO.new("".b, File::RDWR)
136
- @deflater = deflater
137
- end
138
-
139
- def each(&blk)
140
- return enum_for(__method__) unless blk
141
-
142
- return deflate(&blk) if @buffer.size.zero? # rubocop:disable Style/ZeroLengthPredicate
143
-
144
- @buffer.rewind
145
- @buffer.each(&blk)
146
- end
147
-
148
- def bytesize
149
- deflate
150
- @buffer.size
151
- end
152
-
153
- private
154
-
155
- def deflate(&blk)
156
- return unless @buffer.size.zero? # rubocop:disable Style/ZeroLengthPredicate
157
-
158
- @body.rewind
159
- @deflater.deflate(@body, @buffer, chunk_size: 16_384, &blk)
160
- end
161
- end
162
- end
163
- register_plugin :compression, Compression
164
- end
165
- end