http 5.3.1 → 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.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +110 -13
  4. data/http.gemspec +32 -29
  5. data/lib/http/base64.rb +11 -1
  6. data/lib/http/chainable/helpers.rb +62 -0
  7. data/lib/http/chainable/verbs.rb +136 -0
  8. data/lib/http/chainable.rb +232 -136
  9. data/lib/http/client.rb +158 -127
  10. data/lib/http/connection/internals.rb +141 -0
  11. data/lib/http/connection.rb +126 -97
  12. data/lib/http/content_type.rb +61 -6
  13. data/lib/http/errors.rb +25 -1
  14. data/lib/http/feature.rb +65 -5
  15. data/lib/http/features/auto_deflate.rb +124 -17
  16. data/lib/http/features/auto_inflate.rb +38 -15
  17. data/lib/http/features/caching/entry.rb +178 -0
  18. data/lib/http/features/caching/in_memory_store.rb +63 -0
  19. data/lib/http/features/caching.rb +216 -0
  20. data/lib/http/features/digest_auth.rb +234 -0
  21. data/lib/http/features/instrumentation.rb +97 -17
  22. data/lib/http/features/logging.rb +183 -5
  23. data/lib/http/features/normalize_uri.rb +17 -0
  24. data/lib/http/features/raise_error.rb +18 -3
  25. data/lib/http/form_data/composite_io.rb +106 -0
  26. data/lib/http/form_data/file.rb +95 -0
  27. data/lib/http/form_data/multipart/param.rb +62 -0
  28. data/lib/http/form_data/multipart.rb +106 -0
  29. data/lib/http/form_data/part.rb +52 -0
  30. data/lib/http/form_data/readable.rb +58 -0
  31. data/lib/http/form_data/urlencoded.rb +175 -0
  32. data/lib/http/form_data/version.rb +8 -0
  33. data/lib/http/form_data.rb +102 -0
  34. data/lib/http/headers/known.rb +3 -0
  35. data/lib/http/headers/normalizer.rb +17 -36
  36. data/lib/http/headers.rb +172 -65
  37. data/lib/http/mime_type/adapter.rb +24 -9
  38. data/lib/http/mime_type/json.rb +19 -4
  39. data/lib/http/mime_type.rb +21 -3
  40. data/lib/http/options/definitions.rb +189 -0
  41. data/lib/http/options.rb +172 -125
  42. data/lib/http/redirector.rb +80 -75
  43. data/lib/http/request/body.rb +87 -6
  44. data/lib/http/request/builder.rb +184 -0
  45. data/lib/http/request/proxy.rb +83 -0
  46. data/lib/http/request/writer.rb +76 -16
  47. data/lib/http/request.rb +214 -98
  48. data/lib/http/response/body.rb +103 -18
  49. data/lib/http/response/inflater.rb +35 -7
  50. data/lib/http/response/parser.rb +98 -4
  51. data/lib/http/response/status/reasons.rb +2 -4
  52. data/lib/http/response/status.rb +141 -31
  53. data/lib/http/response.rb +219 -61
  54. data/lib/http/retriable/delay_calculator.rb +38 -11
  55. data/lib/http/retriable/errors.rb +21 -0
  56. data/lib/http/retriable/performer.rb +82 -38
  57. data/lib/http/session.rb +280 -0
  58. data/lib/http/timeout/global.rb +147 -34
  59. data/lib/http/timeout/null.rb +155 -9
  60. data/lib/http/timeout/per_operation.rb +139 -18
  61. data/lib/http/uri/normalizer.rb +82 -0
  62. data/lib/http/uri/parsing.rb +182 -0
  63. data/lib/http/uri.rb +289 -124
  64. data/lib/http/version.rb +2 -1
  65. data/lib/http.rb +11 -2
  66. data/sig/http.rbs +1619 -0
  67. metadata +36 -171
  68. data/.github/workflows/ci.yml +0 -67
  69. data/.gitignore +0 -15
  70. data/.rspec +0 -1
  71. data/.rubocop/layout.yml +0 -8
  72. data/.rubocop/metrics.yml +0 -4
  73. data/.rubocop/rspec.yml +0 -9
  74. data/.rubocop/style.yml +0 -32
  75. data/.rubocop.yml +0 -11
  76. data/.rubocop_todo.yml +0 -219
  77. data/.yardopts +0 -2
  78. data/CHANGELOG.md +0 -67
  79. data/CHANGES_OLD.md +0 -1002
  80. data/CONTRIBUTING.md +0 -26
  81. data/Gemfile +0 -51
  82. data/Guardfile +0 -18
  83. data/Rakefile +0 -64
  84. data/SECURITY.md +0 -17
  85. data/lib/http/headers/mixin.rb +0 -34
  86. data/lib/http/retriable/client.rb +0 -37
  87. data/logo.png +0 -0
  88. data/spec/lib/http/client_spec.rb +0 -556
  89. data/spec/lib/http/connection_spec.rb +0 -88
  90. data/spec/lib/http/content_type_spec.rb +0 -47
  91. data/spec/lib/http/features/auto_deflate_spec.rb +0 -77
  92. data/spec/lib/http/features/auto_inflate_spec.rb +0 -86
  93. data/spec/lib/http/features/instrumentation_spec.rb +0 -81
  94. data/spec/lib/http/features/logging_spec.rb +0 -65
  95. data/spec/lib/http/features/raise_error_spec.rb +0 -62
  96. data/spec/lib/http/headers/mixin_spec.rb +0 -36
  97. data/spec/lib/http/headers/normalizer_spec.rb +0 -52
  98. data/spec/lib/http/headers_spec.rb +0 -527
  99. data/spec/lib/http/options/body_spec.rb +0 -15
  100. data/spec/lib/http/options/features_spec.rb +0 -33
  101. data/spec/lib/http/options/form_spec.rb +0 -15
  102. data/spec/lib/http/options/headers_spec.rb +0 -24
  103. data/spec/lib/http/options/json_spec.rb +0 -15
  104. data/spec/lib/http/options/merge_spec.rb +0 -68
  105. data/spec/lib/http/options/new_spec.rb +0 -30
  106. data/spec/lib/http/options/proxy_spec.rb +0 -20
  107. data/spec/lib/http/options_spec.rb +0 -13
  108. data/spec/lib/http/redirector_spec.rb +0 -530
  109. data/spec/lib/http/request/body_spec.rb +0 -211
  110. data/spec/lib/http/request/writer_spec.rb +0 -121
  111. data/spec/lib/http/request_spec.rb +0 -234
  112. data/spec/lib/http/response/body_spec.rb +0 -85
  113. data/spec/lib/http/response/parser_spec.rb +0 -74
  114. data/spec/lib/http/response/status_spec.rb +0 -253
  115. data/spec/lib/http/response_spec.rb +0 -262
  116. data/spec/lib/http/retriable/delay_calculator_spec.rb +0 -69
  117. data/spec/lib/http/retriable/performer_spec.rb +0 -302
  118. data/spec/lib/http/uri/normalizer_spec.rb +0 -95
  119. data/spec/lib/http/uri_spec.rb +0 -71
  120. data/spec/lib/http_spec.rb +0 -535
  121. data/spec/regression_specs.rb +0 -24
  122. data/spec/spec_helper.rb +0 -89
  123. data/spec/support/black_hole.rb +0 -13
  124. data/spec/support/capture_warning.rb +0 -10
  125. data/spec/support/dummy_server/servlet.rb +0 -203
  126. data/spec/support/dummy_server.rb +0 -44
  127. data/spec/support/fakeio.rb +0 -21
  128. data/spec/support/fuubar.rb +0 -21
  129. data/spec/support/http_handling_shared.rb +0 -190
  130. data/spec/support/proxy_server.rb +0 -39
  131. data/spec/support/servers/config.rb +0 -11
  132. data/spec/support/servers/runner.rb +0 -19
  133. data/spec/support/simplecov.rb +0 -19
  134. data/spec/support/ssl_helper.rb +0 -104
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6053cab7210860d3464e9441746186b46c7ac1dc5716ea59cc69dff0d4ef460
4
- data.tar.gz: 49f6d6c66a674e792208f1c17fff2c5dd8fdda330c6bdbabbaddec1f69eebac8
3
+ metadata.gz: 96efa876d9e4c3e5bb5100ab7862338a66b435d02a93e19075f2755a396acd7b
4
+ data.tar.gz: 3d91fccfe7a3e616dcb892fe416b6d1cffbadea286c492f524093ba1bfbdcdeb
5
5
  SHA512:
6
- metadata.gz: 11585d59c45a6e762e6df8792e30107ec1011440ddc4597ad63f4ab5951f0e5c3fd801153bdb32bf74cae90c8ca716368003b3fb59cd98d8dc28c595899be177
7
- data.tar.gz: 481d4f96d65e80226f505b93ff0da954ee4d0c3ee443d6dd4b72711cd0b44ae95c150eeb82d24442a34105dbb75013cb689f4b2ee0a2272d8320b473d91fc72d
6
+ metadata.gz: de74b67fced0df2fc1093d4eb6969edddd43d2f7da5dec73d1ee54bff44712ac173ac3141e909c0f061ab3323820b9498028e5cebc11b74282feab70ef730d33
7
+ data.tar.gz: 361e27f92a887ccf3bd220188e60e9feed23cf750b4e13f8acb2085f0b9beddc381f504f3fa7c4bfe1ddb8dada2f0014141a3a3e2cf575681f39e23f39d8ef66
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2022 Tony Arcieri, Erik Michaels-Ober, Alexey V. Zapparov, Zachary Anker
1
+ Copyright (c) 2011-2026 Tony Arcieri, Erik Berlin, Alexey V. Zapparov, Zachary Anker
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -2,8 +2,11 @@
2
2
 
3
3
  [![Gem Version][gem-image]][gem-link]
4
4
  [![MIT licensed][license-image]][license-link]
5
- [![Build Status][build-image]][build-link]
6
- [![Code Climate][codeclimate-image]][codeclimate-link]
5
+ [![Docs][docs-image]][docs-link]
6
+ [![Lint][lint-image]][lint-link]
7
+ [![Mutant][mutant-image]][mutant-link]
8
+ [![Test][test-image]][test-link]
9
+ [![Typecheck][typecheck-image]][typecheck-link]
7
10
 
8
11
  [Documentation]
9
12
 
@@ -105,18 +108,91 @@ and call `#readpartial` on it repeatedly until it returns `nil`:
105
108
  => nil
106
109
  ```
107
110
 
111
+ ### Pattern Matching
112
+
113
+ Response objects support Ruby's pattern matching:
114
+
115
+ ```ruby
116
+ case HTTP.get("https://api.example.com/users")
117
+ in { status: 200..299, body: body }
118
+ JSON.parse(body.to_s)
119
+ in { status: 404 }
120
+ nil
121
+ in { status: 400.. }
122
+ raise "request failed"
123
+ end
124
+ ```
125
+
126
+ Pattern matching is also supported on `HTTP::Response::Status`, `HTTP::Headers`,
127
+ `HTTP::ContentType`, and `HTTP::URI`.
128
+
129
+ ### Base URI
130
+
131
+ Set a base URI to avoid repeating the scheme and host in every request:
132
+
133
+ ```ruby
134
+ api = HTTP.base_uri("https://api.example.com/v1")
135
+ api.get("users") # GET https://api.example.com/v1/users
136
+ api.get("users/1") # GET https://api.example.com/v1/users/1
137
+ ```
138
+
139
+ Relative paths are resolved per [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986#section-5).
140
+ Combine with `persistent` to reuse the connection:
141
+
142
+ ```ruby
143
+ HTTP.base_uri("https://api.example.com/v1").persistent do |http|
144
+ http.get("users")
145
+ http.get("posts")
146
+ end
147
+ ```
148
+
149
+ ### Thread Safety
150
+
151
+ Configured sessions are safe to share across threads:
152
+
153
+ ```ruby
154
+ # Build a session once, use it from any thread
155
+ session = HTTP.headers("Accept" => "application/json")
156
+ .timeout(10)
157
+ .auth("Bearer token")
158
+
159
+ threads = 10.times.map do
160
+ Thread.new { session.get("https://example.com/api/data") }
161
+ end
162
+ threads.each(&:join)
163
+ ```
164
+
165
+ Chainable configuration methods (`.headers`, `.timeout`, `.auth`, etc.) return
166
+ an `HTTP::Session`, which creates a fresh `HTTP::Client` for every request.
167
+
168
+ Persistent connections (`HTTP.persistent`) return an `HTTP::Session` that pools
169
+ one `HTTP::Client` per origin. The session itself is **not** thread-safe. For
170
+ thread-safe persistent connections, use the
171
+ [connection_pool](https://rubygems.org/gems/connection_pool) gem:
172
+
173
+ ```ruby
174
+ pool = ConnectionPool.new(size: 5) { HTTP.persistent("https://example.com") }
175
+ pool.with { |http| http.get("/path") }
176
+ ```
177
+
178
+ Cross-origin redirects are handled transparently — the session opens a separate
179
+ persistent connection for each origin encountered during a redirect chain:
180
+
181
+ ```ruby
182
+ HTTP.persistent("https://example.com").follow do |http|
183
+ http.get("/moved-to-other-domain") # follows redirect across origins
184
+ end
185
+ ```
186
+
108
187
  ## Supported Ruby Versions
109
188
 
110
189
  This library aims to support and is [tested against][build-link]
111
190
  the following Ruby versions:
112
191
 
113
- - JRuby 9.3
114
- - Ruby 2.6
115
- - Ruby 2.7
116
- - Ruby 3.0
117
- - Ruby 3.1
118
192
  - Ruby 3.2
119
193
  - Ruby 3.3
194
+ - Ruby 3.4
195
+ - Ruby 4.0
120
196
 
121
197
  If something doesn't work on one of these versions, it's a bug.
122
198
 
@@ -132,8 +208,20 @@ exist at the time of a major release, support for that Ruby version may be
132
208
  dropped.
133
209
 
134
210
 
211
+ ## Upgrading
212
+
213
+ See [UPGRADING.md] for a detailed migration guide between major versions.
214
+
215
+
216
+ ## Security
217
+
218
+ See [SECURITY.md] for reporting vulnerabilities.
219
+
220
+
135
221
  ## Contributing to http.rb
136
222
 
223
+ See [CONTRIBUTING.md] for guidelines, or the quick version:
224
+
137
225
  - Fork http.rb on GitHub
138
226
  - Make your changes
139
227
  - Ensure all tests pass (`bundle exec rake`)
@@ -144,7 +232,7 @@ dropped.
144
232
 
145
233
  ## Copyright
146
234
 
147
- Copyright © 2011-2022 Tony Arcieri, Alexey V. Zapparov, Erik Michaels-Ober, Zachary Anker.
235
+ Copyright © 2011-2026 Tony Arcieri, Erik Berlin, Alexey V. Zapparov, Zachary Anker.
148
236
  See LICENSE.txt for further details.
149
237
 
150
238
 
@@ -154,13 +242,22 @@ See LICENSE.txt for further details.
154
242
  [gem-link]: https://rubygems.org/gems/http
155
243
  [license-image]: https://img.shields.io/badge/license-MIT-blue.svg
156
244
  [license-link]: https://github.com/httprb/http/blob/main/LICENSE.txt
157
- [build-image]: https://github.com/httprb/http/workflows/CI/badge.svg
158
- [build-link]: https://github.com/httprb/http/actions/workflows/ci.yml
159
- [codeclimate-image]: https://codeclimate.com/github/httprb/http.svg?branch=main
160
- [codeclimate-link]: https://codeclimate.com/github/httprb/http
245
+ [docs-image]: https://github.com/httprb/http/actions/workflows/docs.yml/badge.svg
246
+ [docs-link]: https://github.com/httprb/http/actions/workflows/docs.yml
247
+ [lint-image]: https://github.com/httprb/http/actions/workflows/lint.yml/badge.svg
248
+ [lint-link]: https://github.com/httprb/http/actions/workflows/lint.yml
249
+ [mutant-image]: https://github.com/httprb/http/actions/workflows/mutant.yml/badge.svg
250
+ [mutant-link]: https://github.com/httprb/http/actions/workflows/mutant.yml
251
+ [test-image]: https://github.com/httprb/http/actions/workflows/test.yml/badge.svg
252
+ [test-link]: https://github.com/httprb/http/actions/workflows/test.yml
253
+ [typecheck-image]: https://github.com/httprb/http/actions/workflows/typecheck.yml/badge.svg
254
+ [typecheck-link]: https://github.com/httprb/http/actions/workflows/typecheck.yml
161
255
 
162
256
  [//]: # (links)
163
257
 
258
+ [contributing.md]: https://github.com/httprb/http/blob/main/CONTRIBUTING.md
164
259
  [documentation]: https://github.com/httprb/http/wiki
165
- [requests]: https://docs.python-requests.org/en/latest/
166
260
  [llhttp]: https://llhttp.org/
261
+ [requests]: https://docs.python-requests.org/en/latest/
262
+ [security.md]: https://github.com/httprb/http/blob/main/SECURITY.md
263
+ [upgrading.md]: https://github.com/httprb/http/blob/main/UPGRADING.md
data/http.gemspec CHANGED
@@ -1,45 +1,48 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path("lib", __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require "http/version"
3
+ require_relative "lib/http/version"
6
4
 
7
- Gem::Specification.new do |gem|
8
- gem.authors = ["Tony Arcieri", "Erik Michaels-Ober", "Alexey V. Zapparov", "Zachary Anker"]
9
- gem.email = ["bascule@gmail.com"]
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "http"
7
+ spec.version = HTTP::VERSION
8
+ spec.authors = ["Tony Arcieri", "Erik Berlin", "Alexey V. Zapparov", "Zachary Anker"]
9
+ spec.email = ["bascule@gmail.com"]
10
10
 
11
- gem.description = <<-DESCRIPTION.strip.gsub(/\s+/, " ")
11
+ spec.summary = "HTTP should be easy"
12
+ spec.homepage = "https://github.com/httprb/http"
13
+ spec.license = "MIT"
14
+
15
+ spec.description = <<~DESCRIPTION.strip.gsub(/\s+/, " ")
12
16
  An easy-to-use client library for making requests from Ruby.
13
17
  It uses a simple method chaining system for building requests,
14
18
  similar to Python's Requests.
15
19
  DESCRIPTION
16
20
 
17
- gem.summary = "HTTP should be easy"
18
- gem.homepage = "https://github.com/httprb/http"
19
- gem.licenses = ["MIT"]
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "#{spec.homepage}/tree/v#{spec.version}"
23
+ spec.metadata["bug_tracker_uri"] = "#{spec.homepage}/issues"
24
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md"
25
+ spec.metadata["documentation_uri"] = "https://www.rubydoc.info/gems/http/#{spec.version}"
26
+ spec.metadata["rubygems_mfa_required"] = "true"
20
27
 
21
- gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
22
- gem.files = `git ls-files`.split("\n")
23
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
- gem.name = "http"
25
- gem.require_paths = ["lib"]
26
- gem.version = HTTP::VERSION
28
+ spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls|
29
+ extras = %w[LICENSE.txt README.md sig/http.rbs] << File.basename(__FILE__)
27
30
 
28
- gem.required_ruby_version = ">= 2.6"
31
+ ls.readlines("\x0", chomp: true).select do |f|
32
+ f.start_with?("lib/") || extras.include?(f)
33
+ end
34
+ end
29
35
 
30
- gem.add_runtime_dependency "addressable", "~> 2.8"
31
- gem.add_runtime_dependency "http-cookie", "~> 1.0"
32
- gem.add_runtime_dependency "http-form_data", "~> 2.2"
36
+ spec.require_paths = ["lib"]
33
37
 
34
- gem.add_runtime_dependency "llhttp-ffi", "~> 0.5.0"
38
+ spec.required_ruby_version = ">= 3.2"
35
39
 
36
- gem.add_development_dependency "bundler", "~> 2.0"
40
+ spec.add_dependency "http-cookie", "~> 1.0"
37
41
 
38
- gem.metadata = {
39
- "source_code_uri" => "https://github.com/httprb/http",
40
- "wiki_uri" => "https://github.com/httprb/http/wiki",
41
- "bug_tracker_uri" => "https://github.com/httprb/http/issues",
42
- "changelog_uri" => "https://github.com/httprb/http/blob/v#{HTTP::VERSION}/CHANGELOG.md",
43
- "rubygems_mfa_required" => "true"
44
- }
42
+ if RUBY_ENGINE == "jruby"
43
+ spec.platform = "java" if ENV["HTTP_PLATFORM"] == "java"
44
+ spec.add_dependency "llhttp-ffi", "~> 0.5.1"
45
+ else
46
+ spec.add_dependency "llhttp", "~> 0.6.1"
47
+ end
45
48
  end
data/lib/http/base64.rb CHANGED
@@ -1,10 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTP
4
+ # Strict Base64 encoding utilities
4
5
  module Base64
5
6
  module_function
6
7
 
7
- # Equivalent to Base64.strict_encode64
8
+ # Encode data using strict Base64 encoding
9
+ #
10
+ # @example
11
+ # HTTP::Base64.encode64("hello")
12
+ #
13
+ # @param input [String] data to encode
14
+ #
15
+ # @return [String]
16
+ #
17
+ # @api private
8
18
  def encode64(input)
9
19
  [input].pack("m0")
10
20
  end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HTTP
4
+ # HTTP verb methods and client configuration DSL
5
+ module Chainable
6
+ # Mapping of proxy argument positions to hash keys and expected types
7
+ PROXY_ARG_MAP = [
8
+ [:proxy_address, 0, String],
9
+ [:proxy_port, 1, Integer],
10
+ [:proxy_username, 2, String],
11
+ [:proxy_password, 3, String],
12
+ [:proxy_headers, 2, Hash],
13
+ [:proxy_headers, 4, Hash]
14
+ ].freeze
15
+
16
+ private
17
+
18
+ # Build proxy configuration hash from positional arguments
19
+ #
20
+ # @param [Array] proxy positional proxy arguments
21
+ # @return [Hash] proxy configuration
22
+ # @api private
23
+ def build_proxy_hash(proxy)
24
+ result = {} #: Hash[Symbol, untyped]
25
+ PROXY_ARG_MAP.each do |key, index, type|
26
+ result[key] = proxy[index] if proxy[index].is_a?(type)
27
+ end
28
+ result
29
+ end
30
+
31
+ # Resolve a timeout hash into a timeout class and normalized options
32
+ #
33
+ # @example
34
+ # resolve_timeout_hash(global: 60, read: 30)
35
+ #
36
+ # @param [Hash] options timeout options
37
+ # @return [Array(Class, Hash)] timeout class and normalized options
38
+ # @raise [ArgumentError] if options are invalid
39
+ # @api private
40
+ def resolve_timeout_hash(options)
41
+ remaining = options.dup
42
+ global = HTTP::Timeout::PerOperation.send(:extract_global_timeout!, remaining)
43
+
44
+ return resolve_global_only(global) if remaining.empty?
45
+
46
+ per_op = HTTP::Timeout::PerOperation.normalize_options(remaining)
47
+ global ? [HTTP::Timeout::Global, per_op.merge(global_timeout: global)] : [HTTP::Timeout::PerOperation, per_op]
48
+ end
49
+
50
+ # Build options for a global-only timeout from a hash
51
+ #
52
+ # @param [Numeric, nil] global the global timeout value
53
+ # @return [Array(Class, Hash)] timeout class and options
54
+ # @raise [ArgumentError] if no global timeout given
55
+ # @api private
56
+ def resolve_global_only(global)
57
+ raise ArgumentError, "no timeout options given" unless global
58
+
59
+ [HTTP::Timeout::Global, { global_timeout: global }]
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,136 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HTTP
4
+ module Chainable
5
+ # HTTP verb shortcut methods
6
+ #
7
+ # Each method delegates to {Chainable#request} with the appropriate verb.
8
+ module Verbs
9
+ # Request a get sans response body
10
+ #
11
+ # @example
12
+ # HTTP.head("http://example.com")
13
+ #
14
+ # @param [String, URI] uri URI to request
15
+ # @param options [Hash] request options
16
+ # @yieldparam response [HTTP::Response] the response
17
+ # @return [HTTP::Response, Object] the response, or block return value
18
+ # @api public
19
+ def head(uri, **, &)
20
+ request(:head, uri, **, &) # steep:ignore
21
+ end
22
+
23
+ # Get a resource
24
+ #
25
+ # @example
26
+ # HTTP.get("http://example.com")
27
+ #
28
+ # @param [String, URI] uri URI to request
29
+ # @param options [Hash] request options
30
+ # @yieldparam response [HTTP::Response] the response
31
+ # @return [HTTP::Response, Object] the response, or block return value
32
+ # @api public
33
+ def get(uri, **, &)
34
+ request(:get, uri, **, &) # steep:ignore
35
+ end
36
+
37
+ # Post to a resource
38
+ #
39
+ # @example
40
+ # HTTP.post("http://example.com", body: "data")
41
+ #
42
+ # @param [String, URI] uri URI to request
43
+ # @param options [Hash] request options
44
+ # @yieldparam response [HTTP::Response] the response
45
+ # @return [HTTP::Response, Object] the response, or block return value
46
+ # @api public
47
+ def post(uri, **, &)
48
+ request(:post, uri, **, &) # steep:ignore
49
+ end
50
+
51
+ # Put to a resource
52
+ #
53
+ # @example
54
+ # HTTP.put("http://example.com", body: "data")
55
+ #
56
+ # @param [String, URI] uri URI to request
57
+ # @param options [Hash] request options
58
+ # @yieldparam response [HTTP::Response] the response
59
+ # @return [HTTP::Response, Object] the response, or block return value
60
+ # @api public
61
+ def put(uri, **, &)
62
+ request(:put, uri, **, &) # steep:ignore
63
+ end
64
+
65
+ # Delete a resource
66
+ #
67
+ # @example
68
+ # HTTP.delete("http://example.com/resource")
69
+ #
70
+ # @param [String, URI] uri URI to request
71
+ # @param options [Hash] request options
72
+ # @yieldparam response [HTTP::Response] the response
73
+ # @return [HTTP::Response, Object] the response, or block return value
74
+ # @api public
75
+ def delete(uri, **, &)
76
+ request(:delete, uri, **, &) # steep:ignore
77
+ end
78
+
79
+ # Echo the request back to the client
80
+ #
81
+ # @example
82
+ # HTTP.trace("http://example.com")
83
+ #
84
+ # @param [String, URI] uri URI to request
85
+ # @param options [Hash] request options
86
+ # @yieldparam response [HTTP::Response] the response
87
+ # @return [HTTP::Response, Object] the response, or block return value
88
+ # @api public
89
+ def trace(uri, **, &)
90
+ request(:trace, uri, **, &) # steep:ignore
91
+ end
92
+
93
+ # Return the methods supported on the given URI
94
+ #
95
+ # @example
96
+ # HTTP.options("http://example.com")
97
+ #
98
+ # @param [String, URI] uri URI to request
99
+ # @param options [Hash] request options
100
+ # @yieldparam response [HTTP::Response] the response
101
+ # @return [HTTP::Response, Object] the response, or block return value
102
+ # @api public
103
+ def options(uri, **, &)
104
+ request(:options, uri, **, &) # steep:ignore
105
+ end
106
+
107
+ # Convert to a transparent TCP/IP tunnel
108
+ #
109
+ # @example
110
+ # HTTP.connect("http://example.com")
111
+ #
112
+ # @param [String, URI] uri URI to request
113
+ # @param options [Hash] request options
114
+ # @yieldparam response [HTTP::Response] the response
115
+ # @return [HTTP::Response, Object] the response, or block return value
116
+ # @api public
117
+ def connect(uri, **, &)
118
+ request(:connect, uri, **, &) # steep:ignore
119
+ end
120
+
121
+ # Apply partial modifications to a resource
122
+ #
123
+ # @example
124
+ # HTTP.patch("http://example.com/resource", body: "data")
125
+ #
126
+ # @param [String, URI] uri URI to request
127
+ # @param options [Hash] request options
128
+ # @yieldparam response [HTTP::Response] the response
129
+ # @return [HTTP::Response, Object] the response, or block return value
130
+ # @api public
131
+ def patch(uri, **, &)
132
+ request(:patch, uri, **, &) # steep:ignore
133
+ end
134
+ end
135
+ end
136
+ end