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.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +110 -13
- 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/http.rbs +1619 -0
- metadata +36 -171
- 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/CHANGELOG.md +0 -67
- data/CHANGES_OLD.md +0 -1002
- data/CONTRIBUTING.md +0 -26
- data/Gemfile +0 -51
- data/Guardfile +0 -18
- data/Rakefile +0 -64
- data/SECURITY.md +0 -17
- 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/capture_warning.rb +0 -10
- data/spec/support/dummy_server/servlet.rb +0 -203
- data/spec/support/dummy_server.rb +0 -44
- data/spec/support/fakeio.rb +0 -21
- 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/simplecov.rb +0 -19
- data/spec/support/ssl_helper.rb +0 -104
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 96efa876d9e4c3e5bb5100ab7862338a66b435d02a93e19075f2755a396acd7b
|
|
4
|
+
data.tar.gz: 3d91fccfe7a3e616dcb892fe416b6d1cffbadea286c492f524093ba1bfbdcdeb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: de74b67fced0df2fc1093d4eb6969edddd43d2f7da5dec73d1ee54bff44712ac173ac3141e909c0f061ab3323820b9498028e5cebc11b74282feab70ef730d33
|
|
7
|
+
data.tar.gz: 361e27f92a887ccf3bd220188e60e9feed23cf750b4e13f8acb2085f0b9beddc381f504f3fa7c4bfe1ddb8dada2f0014141a3a3e2cf575681f39e23f39d8ef66
|
data/LICENSE.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c) 2011-
|
|
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
|
-
[![
|
|
6
|
-
[![
|
|
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-
|
|
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
|
-
[
|
|
158
|
-
[
|
|
159
|
-
[
|
|
160
|
-
[
|
|
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
|
-
|
|
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 |
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
22
|
-
|
|
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
|
-
|
|
31
|
+
ls.readlines("\x0", chomp: true).select do |f|
|
|
32
|
+
f.start_with?("lib/") || extras.include?(f)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
29
35
|
|
|
30
|
-
|
|
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
|
-
|
|
38
|
+
spec.required_ruby_version = ">= 3.2"
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
spec.add_dependency "http-cookie", "~> 1.0"
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
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
|
-
#
|
|
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
|