http 3.1.0 → 5.3.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 (93) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +67 -0
  3. data/.gitignore +6 -9
  4. data/.rspec +0 -4
  5. data/.rubocop/layout.yml +8 -0
  6. data/.rubocop/metrics.yml +4 -0
  7. data/.rubocop/rspec.yml +9 -0
  8. data/.rubocop/style.yml +32 -0
  9. data/.rubocop.yml +9 -108
  10. data/.rubocop_todo.yml +219 -0
  11. data/.yardopts +1 -1
  12. data/CHANGELOG.md +67 -0
  13. data/{CHANGES.md → CHANGES_OLD.md} +358 -0
  14. data/Gemfile +19 -10
  15. data/LICENSE.txt +1 -1
  16. data/README.md +53 -85
  17. data/Rakefile +3 -11
  18. data/SECURITY.md +17 -0
  19. data/http.gemspec +15 -6
  20. data/lib/http/base64.rb +12 -0
  21. data/lib/http/chainable.rb +71 -41
  22. data/lib/http/client.rb +73 -52
  23. data/lib/http/connection.rb +28 -18
  24. data/lib/http/content_type.rb +12 -7
  25. data/lib/http/errors.rb +19 -0
  26. data/lib/http/feature.rb +18 -1
  27. data/lib/http/features/auto_deflate.rb +27 -6
  28. data/lib/http/features/auto_inflate.rb +32 -6
  29. data/lib/http/features/instrumentation.rb +69 -0
  30. data/lib/http/features/logging.rb +53 -0
  31. data/lib/http/features/normalize_uri.rb +17 -0
  32. data/lib/http/features/raise_error.rb +22 -0
  33. data/lib/http/headers/known.rb +3 -0
  34. data/lib/http/headers/normalizer.rb +69 -0
  35. data/lib/http/headers.rb +72 -49
  36. data/lib/http/mime_type/adapter.rb +3 -1
  37. data/lib/http/mime_type/json.rb +1 -0
  38. data/lib/http/options.rb +31 -28
  39. data/lib/http/redirector.rb +56 -4
  40. data/lib/http/request/body.rb +31 -0
  41. data/lib/http/request/writer.rb +29 -9
  42. data/lib/http/request.rb +76 -41
  43. data/lib/http/response/body.rb +6 -4
  44. data/lib/http/response/inflater.rb +1 -1
  45. data/lib/http/response/parser.rb +78 -26
  46. data/lib/http/response/status.rb +4 -3
  47. data/lib/http/response.rb +45 -27
  48. data/lib/http/retriable/client.rb +37 -0
  49. data/lib/http/retriable/delay_calculator.rb +64 -0
  50. data/lib/http/retriable/errors.rb +14 -0
  51. data/lib/http/retriable/performer.rb +153 -0
  52. data/lib/http/timeout/global.rb +29 -47
  53. data/lib/http/timeout/null.rb +12 -8
  54. data/lib/http/timeout/per_operation.rb +32 -57
  55. data/lib/http/uri.rb +75 -1
  56. data/lib/http/version.rb +1 -1
  57. data/lib/http.rb +2 -2
  58. data/spec/lib/http/client_spec.rb +189 -36
  59. data/spec/lib/http/connection_spec.rb +31 -6
  60. data/spec/lib/http/features/auto_inflate_spec.rb +40 -23
  61. data/spec/lib/http/features/instrumentation_spec.rb +81 -0
  62. data/spec/lib/http/features/logging_spec.rb +65 -0
  63. data/spec/lib/http/features/raise_error_spec.rb +62 -0
  64. data/spec/lib/http/headers/normalizer_spec.rb +52 -0
  65. data/spec/lib/http/headers_spec.rb +53 -18
  66. data/spec/lib/http/options/headers_spec.rb +6 -2
  67. data/spec/lib/http/options/merge_spec.rb +16 -16
  68. data/spec/lib/http/redirector_spec.rb +147 -3
  69. data/spec/lib/http/request/body_spec.rb +71 -4
  70. data/spec/lib/http/request/writer_spec.rb +45 -2
  71. data/spec/lib/http/request_spec.rb +11 -5
  72. data/spec/lib/http/response/body_spec.rb +5 -5
  73. data/spec/lib/http/response/parser_spec.rb +74 -0
  74. data/spec/lib/http/response/status_spec.rb +3 -3
  75. data/spec/lib/http/response_spec.rb +83 -7
  76. data/spec/lib/http/retriable/delay_calculator_spec.rb +69 -0
  77. data/spec/lib/http/retriable/performer_spec.rb +302 -0
  78. data/spec/lib/http/uri/normalizer_spec.rb +95 -0
  79. data/spec/lib/http/uri_spec.rb +39 -0
  80. data/spec/lib/http_spec.rb +121 -68
  81. data/spec/regression_specs.rb +7 -0
  82. data/spec/spec_helper.rb +22 -21
  83. data/spec/support/black_hole.rb +1 -1
  84. data/spec/support/dummy_server/servlet.rb +42 -11
  85. data/spec/support/dummy_server.rb +9 -8
  86. data/spec/support/fuubar.rb +21 -0
  87. data/spec/support/http_handling_shared.rb +62 -66
  88. data/spec/support/simplecov.rb +19 -0
  89. data/spec/support/ssl_helper.rb +4 -4
  90. metadata +66 -27
  91. data/.coveralls.yml +0 -1
  92. data/.ruby-version +0 -1
  93. data/.travis.yml +0 -36
@@ -1,3 +1,334 @@
1
+ ## 5.1.1 (2022-12-17)
2
+
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/httprb/http/pull/678)
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.
153
+ ([@ixti])
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
+
181
+ ## 4.4.0 (2020-03-25)
182
+
183
+ * Backport [#587](https://github.com/httprb/http/pull/587)
184
+ Fix redirections when server responds with multiple Location headers.
185
+ ([@ixti])
186
+
187
+ * Backport [#599](https://github.com/httprb/http/pull/599)
188
+ Allow passing HTTP::FormData::{Multipart,UrlEncoded} object directly.
189
+ ([@ixti])
190
+
191
+
192
+ ## 4.3.0 (2020-01-09)
193
+
194
+ * Backport [#581](https://github.com/httprb/http/pull/581)
195
+ Add Ruby-2.7 compatibility.
196
+ ([@ixti], [@janko])
197
+
198
+
199
+ ## 4.2.0 (2019-10-22)
200
+
201
+ * Backport [#489](https://github.com/httprb/http/pull/489)
202
+ Fix HTTP parser.
203
+ ([@ixti], [@fxposter])
204
+
205
+
206
+ ## 4.1.1 (2019-03-12)
207
+
208
+ * Add `HTTP::Headers::ACCEPT_ENCODING` constant.
209
+ ([@ixti])
210
+
211
+
212
+ ## 4.1.0 (2019-03-11)
213
+
214
+ * [#533](https://github.com/httprb/http/pull/533)
215
+ Add URI normalizer feature that allows to swap default URI normalizer.
216
+ ([@mamoonraja])
217
+
218
+
219
+ ## 4.0.5 (2019-02-15)
220
+
221
+ * Backport [#532](https://github.com/httprb/http/pull/532) from master.
222
+ Fix pipes support in request bodies.
223
+ ([@ixti])
224
+
225
+
226
+ ## 4.0.4 (2019-02-12)
227
+
228
+ * Backport [#506](https://github.com/httprb/http/pull/506) from master.
229
+ Skip auto-deflate when there is no body.
230
+ ([@Bonias])
231
+
232
+
233
+ ## 4.0.3 (2019-01-18)
234
+
235
+ * Fix missing URL in response wrapped by auto inflate.
236
+ ([@ixti])
237
+
238
+ * Provide `HTTP::Request#inspect` method for debugging purposes.
239
+ ([@ixti])
240
+
241
+
242
+ ## 4.0.2 (2019-01-15)
243
+
244
+ * [#506](https://github.com/httprb/http/pull/506)
245
+ Fix instrumentation feature.
246
+ ([@paul])
247
+
248
+
249
+ ## 4.0.1 (2019-01-14)
250
+
251
+ * [#515](https://github.com/httprb/http/pull/515)
252
+ Fix `#build_request` and `#request` to respect default options.
253
+ ([@RickCSong])
254
+
255
+
256
+ ## 4.0.0 (2018-10-15)
257
+
258
+ * [#482](https://github.com/httprb/http/pull/482)
259
+ [#499](https://github.com/httprb/http/pull/499)
260
+ Introduce new features injection API with 2 new feaures: instrumentation
261
+ (compatible with ActiveSupport::Notification) and logging.
262
+ ([@paul])
263
+
264
+ * [#473](https://github.com/httprb/http/pull/473)
265
+ Handle early responses.
266
+ ([@janko-m])
267
+
268
+ * [#468](https://github.com/httprb/http/pull/468)
269
+ Rewind `HTTP::Request::Body#source` once `#each` is complete.
270
+ ([@ixti])
271
+
272
+ * [#467](https://github.com/httprb/http/pull/467)
273
+ Drop Ruby 2.2 support.
274
+ ([@ixti])
275
+
276
+ * [#436](https://github.com/httprb/http/pull/436)
277
+ Raise ConnectionError when writing to socket fails.
278
+ ([@janko-m])
279
+
280
+ * [#438](https://github.com/httprb/http/pull/438)
281
+ Expose `HTTP::Request::Body#source`.
282
+ ([@janko-m])
283
+
284
+ * [#446](https://github.com/httprb/http/pull/446)
285
+ Simplify setting a timeout.
286
+ ([@mikegee])
287
+
288
+ * [#451](https://github.com/httprb/http/pull/451)
289
+ Reduce memory usage when reading response body.
290
+ ([@janko-m])
291
+
292
+ * [#458](https://github.com/httprb/http/pull/458)
293
+ Extract HTTP::Client#build_request method.
294
+ ([@tycoon])
295
+
296
+ * [#462](https://github.com/httprb/http/pull/462)
297
+ Fix HTTP::Request#headline to allow two leading slashes in path.
298
+ ([@scarfacedeb])
299
+
300
+ * [#454](https://github.com/httprb/http/pull/454)
301
+ [#464](https://github.com/httprb/http/pull/464)
302
+ [#384](https://github.com/httprb/http/issues/384)
303
+ Fix #readpartial not respecting max length argument.
304
+ ([@janko-m], [@marshall-lee])
305
+
306
+
307
+ ## 3.3.0 (2018-04-25)
308
+
309
+ This version backports some of the fixes and improvements made to development
310
+ version of the HTTP gem:
311
+
312
+ * [#458](https://github.com/httprb/http/pull/458)
313
+ Extract HTTP::Client#build_request method.
314
+ ([@tycoon])
315
+
316
+
317
+ ## 3.2.1 (2018-04-24)
318
+
319
+ * [#468](https://github.com/httprb/http/pull/468)
320
+ Rewind `HTTP::Request::Body#source` once `#each` is complete.
321
+ ([@ixti])
322
+
323
+
324
+ ## 3.2.0 (2018-04-22)
325
+
326
+ This version backports one change we missed to backport in previous release:
327
+
328
+ * Reduce memory usage when reading response body
329
+ ([@janko-m])
330
+
331
+
1
332
  ## 3.1.0 (2018-04-22)
2
333
 
3
334
  This version backports some of the fixes and improvements made to development
@@ -642,3 +973,30 @@ end
642
973
  [@marshall-lee]: https://github.com/marshall-lee
643
974
  [@scarfacedeb]: https://github.com/scarfacedeb
644
975
  [@mikegee]: https://github.com/mikegee
976
+ [@tycoon]: https://github.com/tycooon
977
+ [@paul]: https://github.com/paul
978
+ [@RickCSong]: https://github.com/RickCSong
979
+ [@fxposter]: https://github.com/fxposter
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,39 @@ 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
- platform :ruby_20 do
14
- gem "pry-debugger", :require => false
15
- gem "pry-stack_explorer", :require => false
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 "activemodel", :require => false # Used by certificate_authority
21
- gem "certificate_authority", :require => false
26
+ gem "certificate_authority", "~> 1.0", :require => false
22
27
 
23
28
  gem "backports"
24
29
 
25
- gem "coveralls", :require => false
26
- gem "simplecov", ">= 0.9"
30
+ gem "rubocop", "~> 1.30.0"
31
+ gem "rubocop-performance"
32
+ gem "rubocop-rake"
33
+ gem "rubocop-rspec"
27
34
 
28
- gem "rspec", "~> 3.0"
29
- gem "rspec-its"
35
+ gem "simplecov", :require => false
36
+ gem "simplecov-lcov", :require => false
30
37
 
31
- gem "rubocop", "= 0.49.1"
38
+ gem "rspec", "~> 3.10"
39
+ gem "rspec-its"
40
+ gem "rspec-memory"
32
41
 
33
42
  gem "yardstick"
34
43
  end
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2016 Tony Arcieri, Erik Michaels-Ober, Alexey V. Zapparov, Zachary Anker
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,15 +1,11 @@
1
- # ![http.rb](https://raw.github.com/httprb/http.rb/master/logo.png)
1
+ # ![http.rb](https://raw.github.com/httprb/http.rb/main/logo.png)
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/http.svg)](https://rubygems.org/gems/http)
4
- [![Build Status](https://secure.travis-ci.org/httprb/http.svg?branch=master)](https://travis-ci.org/httprb/http)
5
- [![Code Climate](https://codeclimate.com/github/httprb/http.svg?branch=master)](https://codeclimate.com/github/httprb/http)
6
- [![Coverage Status](https://coveralls.io/repos/httprb/http/badge.svg?branch=master)](https://coveralls.io/r/httprb/http)
7
- [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/httprb/http/blob/master/LICENSE.txt)
8
-
9
- _NOTE: This is the 3.x **stable** branch. For the 4.x **development** branch, please see:_
10
-
11
- https://github.com/httprb/http/
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]
12
7
 
8
+ [Documentation]
13
9
 
14
10
  ## About
15
11
 
@@ -17,68 +13,20 @@ HTTP (The Gem! a.k.a. http.rb) is an easy-to-use client library for making reque
17
13
  from Ruby. It uses a simple method chaining system for building requests, similar to
18
14
  Python's [Requests].
19
15
 
20
- Under the hood, http.rb uses [http_parser.rb], a fast HTTP parsing native
21
- extension based on the Node.js parser and a Java port thereof. This library
22
- isn't just yet another wrapper around Net::HTTP. It implements the HTTP protocol
23
- natively and outsources the parsing to native extensions.
24
-
25
- [requests]: http://docs.python-requests.org/en/latest/
26
- [http_parser.rb]: https://github.com/tmm1/http_parser.rb
27
-
28
-
29
- ## Another Ruby HTTP library? Why should I care?
30
-
31
- There are a lot of HTTP libraries to choose from in the Ruby ecosystem.
32
- 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.
33
19
 
34
- Top three reasons:
20
+ ### Why http.rb?
35
21
 
36
- 1. **Clean API**: http.rb offers an easy-to-use API that should be a
22
+ - **Clean API**: http.rb offers an easy-to-use API that should be a
37
23
  breath of fresh air after using something like Net::HTTP.
38
24
 
39
- 2. **Maturity**: http.rb is one of the most mature Ruby HTTP clients, supporting
25
+ - **Maturity**: http.rb is one of the most mature Ruby HTTP clients, supporting
40
26
  features like persistent connections and fine-grained timeouts.
41
27
 
42
- 3. **Performance**: using native parsers and a clean, lightweight implementation,
43
- http.rb achieves the best performance of any Ruby HTTP library which
44
- implements the HTTP protocol in Ruby instead of C:
45
-
46
- | HTTP client | Time | Implementation |
47
- |--------------------------|--------|-----------------------|
48
- | curb (persistent) | 2.519 | libcurl wrapper |
49
- | em-http-request | 2.731 | EM + http_parser.rb |
50
- | Typhoeus | 2.851 | libcurl wrapper |
51
- | StreamlyFFI (persistent) | 2.853 | libcurl wrapper |
52
- | http.rb (persistent) | 2.970 | Ruby + http_parser.rb |
53
- | http.rb | 3.588 | Ruby + http_parser.rb |
54
- | HTTParty | 3.931 | Net::HTTP wrapper |
55
- | Net::HTTP | 3.959 | Pure Ruby |
56
- | Net::HTTP (persistent) | 4.043 | Pure Ruby |
57
- | open-uri | 4.479 | Net::HTTP wrapper |
58
- | Excon (persistent) | 4.618 | Pure Ruby |
59
- | Excon | 4.701 | Pure Ruby |
60
- | RestClient | 26.838 | Net::HTTP wrapper |
61
-
62
- Benchmarks performed using excon's benchmarking tool
63
-
64
- DISCLAIMER: Most benchmarks you find in READMEs are crap,
65
- including this one. These are out-of-date. If you care about
66
- performance, benchmark for yourself for your own use cases!
67
-
68
- ## Help and Discussion
69
-
70
- If you need help or just want to talk about the http.rb,
71
- visit the http.rb Google Group:
72
-
73
- https://groups.google.com/forum/#!forum/httprb
74
-
75
- You can join by email by sending a message to:
76
-
77
- [httprb+subscribe@googlegroups.com](mailto:httprb+subscribe@googlegroups.com)
78
-
79
- If you believe you've found a bug, please report it at:
80
-
81
- 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.
82
30
 
83
31
 
84
32
  ## Installation
@@ -108,13 +56,14 @@ require "http"
108
56
 
109
57
  ## Documentation
110
58
 
111
- [Please see the http.rb wiki](https://github.com/httprb/http/wiki)
59
+ [Please see the http.rb wiki][documentation]
112
60
  for more detailed documentation and usage notes.
113
61
 
114
62
  The following API documentation is also available:
115
63
 
116
- * [YARD API documentation](http://www.rubydoc.info/gems/http/frames)
117
- * [Chainable module (all chainable methods)](http://www.rubydoc.info/gems/http/HTTP/Chainable)
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)
66
+
118
67
 
119
68
  ### Basic Usage
120
69
 
@@ -141,7 +90,7 @@ We can also obtain an `HTTP::Response::Body` object for this response:
141
90
  ```
142
91
 
143
92
  The response body can be streamed with `HTTP::Response::Body#readpartial`.
144
- 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
145
94
  and call `#readpartial` on it repeatedly until it returns `nil`:
146
95
 
147
96
  ```ruby
@@ -158,13 +107,16 @@ and call `#readpartial` on it repeatedly until it returns `nil`:
158
107
 
159
108
  ## Supported Ruby Versions
160
109
 
161
- This library aims to support and is [tested against][travis] the following Ruby
162
- versions:
110
+ This library aims to support and is [tested against][build-link]
111
+ the following Ruby versions:
163
112
 
164
- * Ruby 2.2.x
165
- * Ruby 2.3.x
166
- * Ruby 2.4.x
167
- * JRuby 9.1.x.x
113
+ - JRuby 9.3
114
+ - Ruby 2.6
115
+ - Ruby 2.7
116
+ - Ruby 3.0
117
+ - Ruby 3.1
118
+ - Ruby 3.2
119
+ - Ruby 3.3
168
120
 
169
121
  If something doesn't work on one of these versions, it's a bug.
170
122
 
@@ -179,20 +131,36 @@ patches in a timely fashion. If critical issues for a particular implementation
179
131
  exist at the time of a major release, support for that Ruby version may be
180
132
  dropped.
181
133
 
182
- [travis]: http://travis-ci.org/httprb/http
183
-
184
134
 
185
135
  ## Contributing to http.rb
186
136
 
187
- * Fork http.rb on GitHub
188
- * Make your changes
189
- * Ensure all tests pass (`bundle exec rake`)
190
- * Send a pull request
191
- * If we like them we'll merge them
192
- * If we've accepted a patch, feel free to ask for commit access!
137
+ - Fork http.rb on GitHub
138
+ - Make your changes
139
+ - Ensure all tests pass (`bundle exec rake`)
140
+ - Send a pull request
141
+ - If we like them we'll merge them
142
+ - If we've accepted a patch, feel free to ask for commit access!
193
143
 
194
144
 
195
145
  ## Copyright
196
146
 
197
- Copyright (c) 2011-2018 Tony Arcieri, Alexey V. Zapparov, Erik Michaels-Ober, Zachary Anker.
147
+ Copyright © 2011-2022 Tony Arcieri, Alexey V. Zapparov, Erik Michaels-Ober, Zachary Anker.
198
148
  See LICENSE.txt for further details.
149
+
150
+
151
+ [//]: # (badges)
152
+
153
+ [gem-image]: https://img.shields.io/gem/v/http?logo=ruby
154
+ [gem-link]: https://rubygems.org/gems/http
155
+ [license-image]: https://img.shields.io/badge/license-MIT-blue.svg
156
+ [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
161
+
162
+ [//]: # (links)
163
+
164
+ [documentation]: https://github.com/httprb/http/wiki
165
+ [requests]: https://docs.python-requests.org/en/latest/
166
+ [llhttp]: https://llhttp.org/
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ task :generate_status_codes do
25
25
 
26
26
  url = "http://www.iana.org/assignments/http-status-codes/http-status-codes.xml"
27
27
  xml = Nokogiri::XML HTTP.get url
28
- arr = xml.xpath("//xmlns:record").reduce [] do |a, e|
28
+ arr = xml.xpath("//xmlns:record").reduce([]) do |a, e|
29
29
  code = e.xpath("xmlns:value").text.to_s
30
30
  desc = e.xpath("xmlns:description").text.to_s
31
31
 
@@ -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 <<-TPL.gsub(/^[ ]{6}/, "")
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
- if ENV["CI"].nil?
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
@@ -0,0 +1,17 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Security updates are applied only to the most recent release.
6
+
7
+ ## Reporting a Vulnerability
8
+
9
+ If you have discovered a security vulnerability in this project, please report
10
+ it privately. **Do not disclose it as a public issue.** This gives us time to
11
+ work with you to fix the issue before public exposure, reducing the chance that
12
+ the exploit will be used before a patch is released.
13
+
14
+ Please disclose it at [security advisory](https://github.com/httprb/http/security/advisories/new).
15
+
16
+ This project is maintained by a team of volunteers on a reasonable-effort basis.
17
+ As such, please give us at least 90 days to work on a fix before public exposure.