http 4.4.1 → 5.1.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/.github/workflows/ci.yml +85 -0
- data/.gitignore +6 -10
- data/.rspec +0 -4
- data/.rubocop/layout.yml +8 -0
- data/.rubocop/style.yml +32 -0
- data/.rubocop.yml +8 -110
- data/.rubocop_todo.yml +206 -0
- data/.yardopts +1 -1
- data/CHANGES.md +200 -3
- data/Gemfile +18 -10
- data/LICENSE.txt +1 -1
- data/README.md +48 -86
- data/Rakefile +2 -10
- data/SECURITY.md +5 -0
- data/http.gemspec +9 -8
- data/lib/http/chainable.rb +23 -17
- data/lib/http/client.rb +44 -34
- data/lib/http/connection.rb +11 -7
- data/lib/http/content_type.rb +12 -7
- data/lib/http/errors.rb +3 -0
- data/lib/http/feature.rb +3 -1
- data/lib/http/features/auto_deflate.rb +6 -6
- data/lib/http/features/auto_inflate.rb +6 -7
- data/lib/http/features/instrumentation.rb +1 -1
- data/lib/http/features/logging.rb +19 -21
- data/lib/http/headers.rb +50 -13
- data/lib/http/mime_type/adapter.rb +3 -1
- data/lib/http/mime_type/json.rb +1 -0
- data/lib/http/options.rb +5 -8
- data/lib/http/redirector.rb +55 -4
- data/lib/http/request/body.rb +1 -0
- data/lib/http/request/writer.rb +9 -4
- data/lib/http/request.rb +28 -11
- data/lib/http/response/body.rb +6 -4
- data/lib/http/response/inflater.rb +1 -1
- data/lib/http/response/parser.rb +74 -62
- data/lib/http/response/status.rb +4 -3
- data/lib/http/response.rb +44 -18
- data/lib/http/timeout/global.rb +20 -36
- data/lib/http/timeout/null.rb +2 -1
- data/lib/http/timeout/per_operation.rb +32 -55
- data/lib/http/uri.rb +51 -6
- data/lib/http/version.rb +1 -1
- data/spec/lib/http/client_spec.rb +155 -30
- data/spec/lib/http/connection_spec.rb +8 -5
- data/spec/lib/http/features/auto_inflate_spec.rb +3 -2
- data/spec/lib/http/features/instrumentation_spec.rb +27 -21
- data/spec/lib/http/features/logging_spec.rb +8 -10
- data/spec/lib/http/headers_spec.rb +53 -18
- data/spec/lib/http/options/headers_spec.rb +1 -1
- data/spec/lib/http/options/merge_spec.rb +16 -16
- data/spec/lib/http/redirector_spec.rb +133 -3
- data/spec/lib/http/request/body_spec.rb +3 -3
- data/spec/lib/http/request/writer_spec.rb +25 -2
- data/spec/lib/http/request_spec.rb +5 -5
- data/spec/lib/http/response/body_spec.rb +5 -5
- data/spec/lib/http/response/parser_spec.rb +33 -4
- data/spec/lib/http/response/status_spec.rb +3 -3
- data/spec/lib/http/response_spec.rb +80 -3
- data/spec/lib/http/uri_spec.rb +39 -0
- data/spec/lib/http_spec.rb +30 -3
- data/spec/spec_helper.rb +21 -21
- data/spec/support/black_hole.rb +1 -1
- data/spec/support/dummy_server/servlet.rb +19 -6
- data/spec/support/dummy_server.rb +7 -7
- data/spec/support/fuubar.rb +21 -0
- data/spec/support/http_handling_shared.rb +5 -5
- data/spec/support/simplecov.rb +19 -0
- data/spec/support/ssl_helper.rb +4 -4
- metadata +22 -14
- data/.coveralls.yml +0 -1
- data/.travis.yml +0 -39
data/CHANGES.md
CHANGED
@@ -1,9 +1,183 @@
|
|
1
|
-
##
|
1
|
+
## 5.1.1 (2022-12-17)
|
2
2
|
|
3
|
-
*
|
4
|
-
|
3
|
+
* [#731](https://github.com/httprb/http/pull/731)
|
4
|
+
Strip brackets from IPv6 addresses in `HTTP::URI`.
|
5
|
+
([@jeraki])
|
6
|
+
|
7
|
+
* [#722](https://github.com/httprb/http/pull/722)
|
8
|
+
Add `on_redirect` callback.
|
9
|
+
([@benubois])
|
10
|
+
|
11
|
+
## 5.1.0 (2022-06-17)
|
12
|
+
|
13
|
+
* Drop ruby-2.5 support.
|
14
|
+
|
15
|
+
* [#715](https://github.com/httprb/http/pull/715)
|
16
|
+
Set default encoding to UTF-8 for `application/json`.
|
17
|
+
([@drwl])
|
18
|
+
|
19
|
+
* [#712](https://github.com/httprb/http/pull/712)
|
20
|
+
Recognize cookies set by redirect.
|
21
|
+
([@tkellogg])
|
22
|
+
|
23
|
+
* [#707](https://github.com/httprb/http/pull/707)
|
24
|
+
Distinguish connection timeouts.
|
25
|
+
([@YuLeven])
|
26
|
+
|
27
|
+
## 5.0.4 (2021-10-07)
|
28
|
+
|
29
|
+
* [#698](https://github.com/httprb/http/pull/698)
|
30
|
+
Fix `HTTP::Timeout::Global#connect_ssl`.
|
31
|
+
([@tarcieri])
|
32
|
+
|
33
|
+
## 5.0.3 (2021-10-06)
|
34
|
+
|
35
|
+
* [#695](https://github.com/httprb/http/pull/695)
|
36
|
+
Revert DNS resolving feature.
|
37
|
+
([@PhilCoggins])
|
38
|
+
|
39
|
+
* [#694](https://github.com/httprb/http/pull/694)
|
40
|
+
Fix cookies extraction.
|
41
|
+
([@flosacca])
|
42
|
+
|
43
|
+
## 5.0.2 (2021-09-10)
|
44
|
+
|
45
|
+
* [#686](https://github.com/httprb/http/pull/686)
|
46
|
+
Correctly reset the parser.
|
47
|
+
([@bryanp])
|
48
|
+
|
49
|
+
* [#684](https://github.com/httprb/http/pull/684)
|
50
|
+
Don't set Content-Length for GET, HEAD, DELETE, or CONNECT requests without a BODY.
|
51
|
+
([@jyn514])
|
52
|
+
|
53
|
+
* [#679](https://github.com/httprb/http/pull/679)
|
54
|
+
Use features on redirected requests.
|
55
|
+
([@nomis])
|
56
|
+
|
57
|
+
* [#678](https://github.com/schwern)
|
58
|
+
Restore `HTTP::Response` `:uri` option for backwards compatibility.
|
59
|
+
([@schwern])
|
60
|
+
|
61
|
+
* [#676](https://github.com/httprb/http/pull/676)
|
62
|
+
Update addressable because of CVE-2021-32740.
|
63
|
+
([@matheussilvasantos])
|
64
|
+
|
65
|
+
* [#653](https://github.com/httprb/http/pull/653)
|
66
|
+
Avoid force encodings on frozen strings.
|
67
|
+
([@bvicenzo])
|
68
|
+
|
69
|
+
* [#638](https://github.com/httprb/http/pull/638)
|
70
|
+
DNS failover handling.
|
71
|
+
([@midnight-wonderer])
|
72
|
+
|
73
|
+
|
74
|
+
## 5.0.1 (2021-06-26)
|
75
|
+
|
76
|
+
* [#670](https://github.com/httprb/http/pull/670)
|
77
|
+
Revert `Response#parse` behavior introduced in [#540].
|
78
|
+
([@DannyBen])
|
79
|
+
|
80
|
+
* [#669](https://github.com/httprb/http/pull/669)
|
81
|
+
Prevent bodies from being resubmitted when following unsafe redirects.
|
82
|
+
([@odinhb])
|
83
|
+
|
84
|
+
* [#664](https://github.com/httprb/http/pull/664)
|
85
|
+
Bump llhttp-ffi to 0.3.0.
|
86
|
+
([@bryanp])
|
87
|
+
|
88
|
+
|
89
|
+
## 5.0.0 (2021-05-12)
|
90
|
+
|
91
|
+
* [#656](https://github.com/httprb/http/pull/656)
|
92
|
+
Handle connection timeouts in `Features`
|
93
|
+
([@semenyukdmitry])
|
94
|
+
|
95
|
+
* [#651](https://github.com/httprb/http/pull/651)
|
96
|
+
Replace `http-parser` with `llhttp`
|
97
|
+
([@bryanp])
|
98
|
+
|
99
|
+
* [#647](https://github.com/httprb/http/pull/647)
|
100
|
+
Add support for `MKCALENDAR` HTTP verb
|
101
|
+
([@meanphil])
|
102
|
+
|
103
|
+
* [#632](https://github.com/httprb/http/pull/632)
|
104
|
+
Respect the SSL context's `verify_hostname` value
|
105
|
+
([@colemannugent])
|
106
|
+
|
107
|
+
* [#625](https://github.com/httprb/http/pull/625)
|
108
|
+
Fix inflator with empty responses
|
109
|
+
([@LukaszMaslej])
|
110
|
+
|
111
|
+
* [#599](https://github.com/httprb/http/pull/599)
|
112
|
+
Allow passing `HTTP::FormData::{Multipart,UrlEncoded}` object directly.
|
113
|
+
([@ixti])
|
114
|
+
|
115
|
+
* [#593](https://github.com/httprb/http/pull/593)
|
116
|
+
[#592](https://github.com/httprb/http/issues/592)
|
117
|
+
Support informational (1XX) responses.
|
118
|
+
([@ixti])
|
119
|
+
|
120
|
+
* [#590](https://github.com/httprb/http/pull/590)
|
121
|
+
[#589](https://github.com/httprb/http/issues/589)
|
122
|
+
Fix response headers paring.
|
123
|
+
([@Bonias])
|
124
|
+
|
125
|
+
* [#587](https://github.com/httprb/http/pull/587)
|
126
|
+
[#585](https://github.com/httprb/http/issues/585)
|
127
|
+
Fix redirections when server responds with multiple Location headers.
|
128
|
+
([@ixti])
|
129
|
+
|
130
|
+
* [#581](https://github.com/httprb/http/pull/581)
|
131
|
+
[#582](https://github.com/httprb/http/issues/582)
|
132
|
+
Add Ruby 2.7.x support.
|
133
|
+
([@janko])
|
134
|
+
|
135
|
+
* [#577](https://github.com/httprb/http/pull/577)
|
136
|
+
Fix `Chainable#timeout` with frozen Hash.
|
137
|
+
([@antonvolkoff])
|
138
|
+
|
139
|
+
* [#576](https://github.com/httprb/http/pull/576)
|
140
|
+
[#524](https://github.com/httprb/http/issues/524)
|
141
|
+
**BREAKING CHANGE**
|
142
|
+
Preserve header names casing.
|
143
|
+
([@joshuaflanagan])
|
144
|
+
|
145
|
+
* [#540](https://github.com/httprb/http/pull/540)
|
146
|
+
[#538](https://github.com/httprb/http/issues/538)
|
147
|
+
**BREAKING CHANGE**
|
148
|
+
Require explicit MIME type for Response#parse
|
149
|
+
([@ixti])
|
150
|
+
|
151
|
+
* [#532](https://github.com/httprb/http/pull/532)
|
152
|
+
Fix pipes support in request bodies.
|
5
153
|
([@ixti])
|
6
154
|
|
155
|
+
* [#530](https://github.com/httprb/http/pull/530)
|
156
|
+
Improve header fields name/value validation.
|
157
|
+
([@Bonias])
|
158
|
+
|
159
|
+
* [#506](https://github.com/httprb/http/pull/506)
|
160
|
+
[#521](https://github.com/httprb/http/issues/521)
|
161
|
+
Skip auto-deflate when there is no body.
|
162
|
+
([@Bonias])
|
163
|
+
|
164
|
+
* [#489](https://github.com/httprb/http/pull/489)
|
165
|
+
Fix HTTP parser.
|
166
|
+
([@ixti], [@fxposter])
|
167
|
+
|
168
|
+
* [#546](https://github.com/httprb/http/pull/546)
|
169
|
+
**BREAKING CHANGE**
|
170
|
+
Provide initiating `HTTP::Request` object on `HTTP::Response`.
|
171
|
+
([@joshuaflanagan])
|
172
|
+
|
173
|
+
* [#571](https://github.com/httprb/http/pull/571)
|
174
|
+
Drop Ruby 2.3.x support.
|
175
|
+
([@ixti])
|
176
|
+
|
177
|
+
* [3ed0c31](https://github.com/httprb/http/commit/3ed0c318eab6a8c390654cda17bf6df9e963c7d6)
|
178
|
+
Drop Ruby 2.4.x support.
|
179
|
+
|
180
|
+
|
7
181
|
## 4.4.0 (2020-03-25)
|
8
182
|
|
9
183
|
* Backport [#587](https://github.com/httprb/http/pull/587)
|
@@ -14,6 +188,7 @@
|
|
14
188
|
Allow passing HTTP::FormData::{Multipart,UrlEncoded} object directly.
|
15
189
|
([@ixti])
|
16
190
|
|
191
|
+
|
17
192
|
## 4.3.0 (2020-01-09)
|
18
193
|
|
19
194
|
* Backport [#581](https://github.com/httprb/http/pull/581)
|
@@ -803,3 +978,25 @@ end
|
|
803
978
|
[@RickCSong]: https://github.com/RickCSong
|
804
979
|
[@fxposter]: https://github.com/fxposter
|
805
980
|
[@mamoonraja]: https://github.com/mamoonraja
|
981
|
+
[@joshuaflanagan]: https://github.com/joshuaflanagan
|
982
|
+
[@antonvolkoff]: https://github.com/antonvolkoff
|
983
|
+
[@LukaszMaslej]: https://github.com/LukaszMaslej
|
984
|
+
[@colemannugent]: https://github.com/colemannugent
|
985
|
+
[@semenyukdmitry]: https://github.com/semenyukdmitry
|
986
|
+
[@bryanp]: https://github.com/bryanp
|
987
|
+
[@meanphil]: https://github.com/meanphil
|
988
|
+
[@odinhb]: https://github.com/odinhb
|
989
|
+
[@DannyBen]: https://github.com/DannyBen
|
990
|
+
[@jyn514]: https://github.com/jyn514
|
991
|
+
[@bvicenzo]: https://github.com/bvicenzo
|
992
|
+
[@nomis]: https://github.com/nomis
|
993
|
+
[@midnight-wonderer]: https://github.com/midnight-wonderer
|
994
|
+
[@schwern]: https://github.com/schwern
|
995
|
+
[@matheussilvasantos]: https://github.com/matheussilvasantos
|
996
|
+
[@PhilCoggins]: https://github.com/PhilCoggins
|
997
|
+
[@flosacca]: https://github.com/flosacca
|
998
|
+
[@YuLeven]: https://github.com/YuLeven
|
999
|
+
[@drwl]: https://github.com/drwl
|
1000
|
+
[@tkellogg]: https://github.com/tkellogg
|
1001
|
+
[@jeraki]: https://github.com/jeraki
|
1002
|
+
[@benubois]: https://github.com/benubois
|
data/Gemfile
CHANGED
@@ -5,30 +5,38 @@ ruby RUBY_VERSION
|
|
5
5
|
|
6
6
|
gem "rake"
|
7
7
|
|
8
|
+
# Ruby 3.0 does not ship it anymore.
|
9
|
+
# TODO: We should probably refactor specs to avoid need for it.
|
10
|
+
gem "webrick"
|
11
|
+
|
8
12
|
group :development do
|
9
13
|
gem "guard-rspec", :require => false
|
10
14
|
gem "nokogiri", :require => false
|
11
15
|
gem "pry", :require => false
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
|
17
|
+
# RSpec formatter
|
18
|
+
gem "fuubar", :require => false
|
19
|
+
|
20
|
+
platform :mri do
|
21
|
+
gem "pry-byebug"
|
16
22
|
end
|
17
23
|
end
|
18
24
|
|
19
25
|
group :test do
|
20
|
-
gem "
|
21
|
-
gem "certificate_authority", :require => false
|
26
|
+
gem "certificate_authority", "~> 1.0", :require => false
|
22
27
|
|
23
28
|
gem "backports"
|
24
29
|
|
25
|
-
gem "
|
26
|
-
gem "
|
30
|
+
gem "rubocop", "~> 1.30.0"
|
31
|
+
gem "rubocop-performance"
|
32
|
+
gem "rubocop-rake"
|
33
|
+
gem "rubocop-rspec"
|
27
34
|
|
28
|
-
gem "
|
29
|
-
gem "
|
35
|
+
gem "simplecov", :require => false
|
36
|
+
gem "simplecov-lcov", :require => false
|
30
37
|
|
31
|
-
gem "
|
38
|
+
gem "rspec", "~> 3.10"
|
39
|
+
gem "rspec-its"
|
32
40
|
|
33
41
|
gem "yardstick"
|
34
42
|
end
|
data/LICENSE.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2011-
|
1
|
+
Copyright (c) 2011-2022 Tony Arcieri, Erik Michaels-Ober, 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
@@ -1,85 +1,32 @@
|
|
1
|
-
# 
|
2
2
|
|
3
|
-
[![Gem Version]
|
4
|
-
[](https://github.com/httprb/http/blob/4-x-stable/LICENSE.txt)
|
3
|
+
[![Gem Version][gem-image]][gem-link]
|
4
|
+
[![MIT licensed][license-image]][license-link]
|
5
|
+
[![Build Status][build-image]][build-link]
|
6
|
+
[![Code Climate][codeclimate-image]][codeclimate-link]
|
8
7
|
|
9
8
|
[Documentation]
|
10
9
|
|
11
|
-
_NOTE: This is the 4.x **stable** branch. For the 3.x **stable** branch, please see:_
|
12
|
-
|
13
|
-
https://github.com/httprb/http/tree/3-x-stable
|
14
|
-
|
15
10
|
## About
|
16
11
|
|
17
12
|
HTTP (The Gem! a.k.a. http.rb) is an easy-to-use client library for making requests
|
18
13
|
from Ruby. It uses a simple method chaining system for building requests, similar to
|
19
14
|
Python's [Requests].
|
20
15
|
|
21
|
-
Under the hood, http.rb uses [
|
22
|
-
|
23
|
-
|
24
|
-
natively and outsources the parsing to native extensions.
|
25
|
-
|
26
|
-
[requests]: http://docs.python-requests.org/en/latest/
|
27
|
-
[http_parser.rb]: https://github.com/tmm1/http_parser.rb
|
28
|
-
|
29
|
-
|
30
|
-
## Another Ruby HTTP library? Why should I care?
|
31
|
-
|
32
|
-
There are a lot of HTTP libraries to choose from in the Ruby ecosystem.
|
33
|
-
So why would you choose this one?
|
16
|
+
Under the hood, http.rb uses the [llhttp] parser, a fast HTTP parsing native extension.
|
17
|
+
This library isn't just yet another wrapper around `Net::HTTP`. It implements the HTTP
|
18
|
+
protocol natively and outsources the parsing to native extensions.
|
34
19
|
|
35
|
-
|
20
|
+
### Why http.rb?
|
36
21
|
|
37
|
-
|
22
|
+
- **Clean API**: http.rb offers an easy-to-use API that should be a
|
38
23
|
breath of fresh air after using something like Net::HTTP.
|
39
24
|
|
40
|
-
|
25
|
+
- **Maturity**: http.rb is one of the most mature Ruby HTTP clients, supporting
|
41
26
|
features like persistent connections and fine-grained timeouts.
|
42
27
|
|
43
|
-
|
44
|
-
http.rb achieves
|
45
|
-
implements the HTTP protocol in Ruby instead of C:
|
46
|
-
|
47
|
-
| HTTP client | Time | Implementation |
|
48
|
-
|--------------------------|--------|-----------------------|
|
49
|
-
| curb (persistent) | 2.519 | libcurl wrapper |
|
50
|
-
| em-http-request | 2.731 | EM + http_parser.rb |
|
51
|
-
| Typhoeus | 2.851 | libcurl wrapper |
|
52
|
-
| StreamlyFFI (persistent) | 2.853 | libcurl wrapper |
|
53
|
-
| http.rb (persistent) | 2.970 | Ruby + http_parser.rb |
|
54
|
-
| http.rb | 3.588 | Ruby + http_parser.rb |
|
55
|
-
| HTTParty | 3.931 | Net::HTTP wrapper |
|
56
|
-
| Net::HTTP | 3.959 | Pure Ruby |
|
57
|
-
| Net::HTTP (persistent) | 4.043 | Pure Ruby |
|
58
|
-
| open-uri | 4.479 | Net::HTTP wrapper |
|
59
|
-
| Excon (persistent) | 4.618 | Pure Ruby |
|
60
|
-
| Excon | 4.701 | Pure Ruby |
|
61
|
-
| RestClient | 26.838 | Net::HTTP wrapper |
|
62
|
-
|
63
|
-
Benchmarks performed using excon's benchmarking tool
|
64
|
-
|
65
|
-
DISCLAIMER: Most benchmarks you find in READMEs are crap,
|
66
|
-
including this one. These are out-of-date. If you care about
|
67
|
-
performance, benchmark for yourself for your own use cases!
|
68
|
-
|
69
|
-
## Help and Discussion
|
70
|
-
|
71
|
-
If you need help or just want to talk about the http.rb,
|
72
|
-
visit the http.rb Google Group:
|
73
|
-
|
74
|
-
https://groups.google.com/forum/#!forum/httprb
|
75
|
-
|
76
|
-
You can join by email by sending a message to:
|
77
|
-
|
78
|
-
[httprb+subscribe@googlegroups.com](mailto:httprb+subscribe@googlegroups.com)
|
79
|
-
|
80
|
-
If you believe you've found a bug, please report it at:
|
81
|
-
|
82
|
-
https://github.com/httprb/http/issues
|
28
|
+
- **Performance**: using native parsers and a clean, lightweight implementation,
|
29
|
+
http.rb achieves high performance while implementing HTTP in Ruby instead of C.
|
83
30
|
|
84
31
|
|
85
32
|
## Installation
|
@@ -114,10 +61,9 @@ for more detailed documentation and usage notes.
|
|
114
61
|
|
115
62
|
The following API documentation is also available:
|
116
63
|
|
117
|
-
|
118
|
-
|
64
|
+
- [YARD API documentation](https://www.rubydoc.info/github/httprb/http)
|
65
|
+
- [Chainable module (all chainable methods)](https://www.rubydoc.info/github/httprb/http/HTTP/Chainable)
|
119
66
|
|
120
|
-
[documentation]: https://github.com/httprb/http/wiki
|
121
67
|
|
122
68
|
### Basic Usage
|
123
69
|
|
@@ -144,7 +90,7 @@ We can also obtain an `HTTP::Response::Body` object for this response:
|
|
144
90
|
```
|
145
91
|
|
146
92
|
The response body can be streamed with `HTTP::Response::Body#readpartial`.
|
147
|
-
In practice, you'll want to bind the HTTP::Response::Body to a local variable
|
93
|
+
In practice, you'll want to bind the `HTTP::Response::Body` to a local variable
|
148
94
|
and call `#readpartial` on it repeatedly until it returns `nil`:
|
149
95
|
|
150
96
|
```ruby
|
@@ -161,14 +107,14 @@ and call `#readpartial` on it repeatedly until it returns `nil`:
|
|
161
107
|
|
162
108
|
## Supported Ruby Versions
|
163
109
|
|
164
|
-
This library aims to support and is [tested against][
|
165
|
-
versions:
|
110
|
+
This library aims to support and is [tested against][build-link]
|
111
|
+
the following Ruby versions:
|
166
112
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
113
|
+
- Ruby 2.6
|
114
|
+
- Ruby 2.7
|
115
|
+
- Ruby 3.0
|
116
|
+
- Ruby 3.1
|
117
|
+
- JRuby 9.3
|
172
118
|
|
173
119
|
If something doesn't work on one of these versions, it's a bug.
|
174
120
|
|
@@ -183,20 +129,36 @@ patches in a timely fashion. If critical issues for a particular implementation
|
|
183
129
|
exist at the time of a major release, support for that Ruby version may be
|
184
130
|
dropped.
|
185
131
|
|
186
|
-
[travis]: http://travis-ci.org/httprb/http
|
187
|
-
|
188
132
|
|
189
133
|
## Contributing to http.rb
|
190
134
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
135
|
+
- Fork http.rb on GitHub
|
136
|
+
- Make your changes
|
137
|
+
- Ensure all tests pass (`bundle exec rake`)
|
138
|
+
- Send a pull request
|
139
|
+
- If we like them we'll merge them
|
140
|
+
- If we've accepted a patch, feel free to ask for commit access!
|
197
141
|
|
198
142
|
|
199
143
|
## Copyright
|
200
144
|
|
201
|
-
Copyright
|
145
|
+
Copyright © 2011-2022 Tony Arcieri, Alexey V. Zapparov, Erik Michaels-Ober, Zachary Anker.
|
202
146
|
See LICENSE.txt for further details.
|
147
|
+
|
148
|
+
|
149
|
+
[//]: # (badges)
|
150
|
+
|
151
|
+
[gem-image]: https://img.shields.io/gem/v/http?logo=ruby
|
152
|
+
[gem-link]: https://rubygems.org/gems/http
|
153
|
+
[license-image]: https://img.shields.io/badge/license-MIT-blue.svg
|
154
|
+
[license-link]: https://github.com/httprb/http/blob/main/LICENSE.txt
|
155
|
+
[build-image]: https://github.com/httprb/http/workflows/CI/badge.svg
|
156
|
+
[build-link]: https://github.com/httprb/http/actions/workflows/ci.yml
|
157
|
+
[codeclimate-image]: https://codeclimate.com/github/httprb/http.svg?branch=main
|
158
|
+
[codeclimate-link]: https://codeclimate.com/github/httprb/http
|
159
|
+
|
160
|
+
[//]: # (links)
|
161
|
+
|
162
|
+
[documentation]: https://github.com/httprb/http/wiki
|
163
|
+
[requests]: http://docs.python-requests.org/en/latest/
|
164
|
+
[llhttp]: https://llhttp.org/
|
data/Rakefile
CHANGED
@@ -35,7 +35,7 @@ task :generate_status_codes do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
File.open("./lib/http/response/status/reasons.rb", "w") do |io|
|
38
|
-
io.puts
|
38
|
+
io.puts <<~TPL
|
39
39
|
# AUTO-GENERATED FILE, DO NOT CHANGE IT MANUALLY
|
40
40
|
|
41
41
|
require "delegate"
|
@@ -61,12 +61,4 @@ task :generate_status_codes do
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
|
65
|
-
task :default => %i[spec rubocop verify_measurements]
|
66
|
-
else
|
67
|
-
case ENV["SUITE"]
|
68
|
-
when "rubocop" then task :default => :rubocop
|
69
|
-
when "yardstick" then task :default => :verify_measurements
|
70
|
-
else task :default => :spec
|
71
|
-
end
|
72
|
-
end
|
64
|
+
task :default => %i[spec rubocop verify_measurements]
|
data/SECURITY.md
ADDED
data/http.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path("
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
require "http/version"
|
6
6
|
|
@@ -25,19 +25,20 @@ Gem::Specification.new do |gem|
|
|
25
25
|
gem.require_paths = ["lib"]
|
26
26
|
gem.version = HTTP::VERSION
|
27
27
|
|
28
|
-
gem.required_ruby_version = ">= 2.
|
28
|
+
gem.required_ruby_version = ">= 2.6"
|
29
29
|
|
30
|
-
gem.add_runtime_dependency "addressable", "~> 2.
|
30
|
+
gem.add_runtime_dependency "addressable", "~> 2.8"
|
31
31
|
gem.add_runtime_dependency "http-cookie", "~> 1.0"
|
32
32
|
gem.add_runtime_dependency "http-form_data", "~> 2.2"
|
33
|
-
gem.add_runtime_dependency "
|
33
|
+
gem.add_runtime_dependency "llhttp-ffi", "~> 0.4.0"
|
34
34
|
|
35
35
|
gem.add_development_dependency "bundler", "~> 2.0"
|
36
36
|
|
37
37
|
gem.metadata = {
|
38
|
-
"source_code_uri"
|
39
|
-
"wiki_uri"
|
40
|
-
"bug_tracker_uri"
|
41
|
-
"changelog_uri"
|
38
|
+
"source_code_uri" => "https://github.com/httprb/http",
|
39
|
+
"wiki_uri" => "https://github.com/httprb/http/wiki",
|
40
|
+
"bug_tracker_uri" => "https://github.com/httprb/http/issues",
|
41
|
+
"changelog_uri" => "https://github.com/httprb/http/blob/v#{HTTP::VERSION}/CHANGES.md",
|
42
|
+
"rubygems_mfa_required" => "true"
|
42
43
|
}
|
43
44
|
end
|
data/lib/http/chainable.rb
CHANGED
@@ -9,63 +9,63 @@ module HTTP
|
|
9
9
|
# Request a get sans response body
|
10
10
|
# @param uri
|
11
11
|
# @option options [Hash]
|
12
|
-
def head(uri, options = {})
|
12
|
+
def head(uri, options = {})
|
13
13
|
request :head, uri, options
|
14
14
|
end
|
15
15
|
|
16
16
|
# Get a resource
|
17
17
|
# @param uri
|
18
18
|
# @option options [Hash]
|
19
|
-
def get(uri, options = {})
|
19
|
+
def get(uri, options = {})
|
20
20
|
request :get, uri, options
|
21
21
|
end
|
22
22
|
|
23
23
|
# Post to a resource
|
24
24
|
# @param uri
|
25
25
|
# @option options [Hash]
|
26
|
-
def post(uri, options = {})
|
26
|
+
def post(uri, options = {})
|
27
27
|
request :post, uri, options
|
28
28
|
end
|
29
29
|
|
30
30
|
# Put to a resource
|
31
31
|
# @param uri
|
32
32
|
# @option options [Hash]
|
33
|
-
def put(uri, options = {})
|
33
|
+
def put(uri, options = {})
|
34
34
|
request :put, uri, options
|
35
35
|
end
|
36
36
|
|
37
37
|
# Delete a resource
|
38
38
|
# @param uri
|
39
39
|
# @option options [Hash]
|
40
|
-
def delete(uri, options = {})
|
40
|
+
def delete(uri, options = {})
|
41
41
|
request :delete, uri, options
|
42
42
|
end
|
43
43
|
|
44
44
|
# Echo the request back to the client
|
45
45
|
# @param uri
|
46
46
|
# @option options [Hash]
|
47
|
-
def trace(uri, options = {})
|
47
|
+
def trace(uri, options = {})
|
48
48
|
request :trace, uri, options
|
49
49
|
end
|
50
50
|
|
51
51
|
# Return the methods supported on the given URI
|
52
52
|
# @param uri
|
53
53
|
# @option options [Hash]
|
54
|
-
def options(uri, options = {})
|
54
|
+
def options(uri, options = {})
|
55
55
|
request :options, uri, options
|
56
56
|
end
|
57
57
|
|
58
58
|
# Convert to a transparent TCP/IP tunnel
|
59
59
|
# @param uri
|
60
60
|
# @option options [Hash]
|
61
|
-
def connect(uri, options = {})
|
61
|
+
def connect(uri, options = {})
|
62
62
|
request :connect, uri, options
|
63
63
|
end
|
64
64
|
|
65
65
|
# Apply partial modifications to a resource
|
66
66
|
# @param uri
|
67
67
|
# @option options [Hash]
|
68
|
-
def patch(uri, options = {})
|
68
|
+
def patch(uri, options = {})
|
69
69
|
request :patch, uri, options
|
70
70
|
end
|
71
71
|
|
@@ -93,7 +93,7 @@ module HTTP
|
|
93
93
|
def timeout(options)
|
94
94
|
klass, options = case options
|
95
95
|
when Numeric then [HTTP::Timeout::Global, {:global => options}]
|
96
|
-
when Hash then [HTTP::Timeout::PerOperation, options]
|
96
|
+
when Hash then [HTTP::Timeout::PerOperation, options.dup]
|
97
97
|
when :null then [HTTP::Timeout::Null, {}]
|
98
98
|
else raise ArgumentError, "Use `.timeout(global_timeout_in_seconds)` or `.timeout(connect: x, write: y, read: z)`."
|
99
99
|
|
@@ -101,11 +101,12 @@ module HTTP
|
|
101
101
|
|
102
102
|
%i[global read write connect].each do |k|
|
103
103
|
next unless options.key? k
|
104
|
+
|
104
105
|
options["#{k}_timeout".to_sym] = options.delete k
|
105
106
|
end
|
106
107
|
|
107
108
|
branch default_options.merge(
|
108
|
-
:timeout_class
|
109
|
+
:timeout_class => klass,
|
109
110
|
:timeout_options => options
|
110
111
|
)
|
111
112
|
end
|
@@ -144,9 +145,10 @@ module HTTP
|
|
144
145
|
options = {:keep_alive_timeout => timeout}
|
145
146
|
p_client = branch default_options.merge(options).with_persistent host
|
146
147
|
return p_client unless block_given?
|
148
|
+
|
147
149
|
yield p_client
|
148
150
|
ensure
|
149
|
-
p_client
|
151
|
+
p_client&.close
|
150
152
|
end
|
151
153
|
|
152
154
|
# Make a request through an HTTP proxy
|
@@ -168,10 +170,10 @@ module HTTP
|
|
168
170
|
alias through via
|
169
171
|
|
170
172
|
# Make client follow redirects.
|
171
|
-
# @param
|
173
|
+
# @param options
|
172
174
|
# @return [HTTP::Client]
|
173
175
|
# @see Redirector#initialize
|
174
|
-
def follow(options = {})
|
176
|
+
def follow(options = {})
|
175
177
|
branch default_options.with_follow options
|
176
178
|
end
|
177
179
|
|
@@ -209,10 +211,11 @@ module HTTP
|
|
209
211
|
# @option opts [#to_s] :user
|
210
212
|
# @option opts [#to_s] :pass
|
211
213
|
def basic_auth(opts)
|
212
|
-
user
|
213
|
-
pass
|
214
|
+
user = opts.fetch(:user)
|
215
|
+
pass = opts.fetch(:pass)
|
216
|
+
creds = "#{user}:#{pass}"
|
214
217
|
|
215
|
-
auth("Basic
|
218
|
+
auth("Basic #{Base64.strict_encode64(creds)}")
|
216
219
|
end
|
217
220
|
|
218
221
|
# Get options for HTTP
|
@@ -236,6 +239,9 @@ module HTTP
|
|
236
239
|
# Turn on given features. Available features are:
|
237
240
|
# * auto_inflate
|
238
241
|
# * auto_deflate
|
242
|
+
# * instrumentation
|
243
|
+
# * logging
|
244
|
+
# * normalize_uri
|
239
245
|
# @param features
|
240
246
|
def use(*features)
|
241
247
|
branch default_options.with_features(features)
|