ethon 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +2 -2
- data/CHANGELOG.md +3 -0
- data/README.md +23 -0
- data/lib/ethon/curls/classes.rb +12 -2
- data/lib/ethon/curls/options.rb +4 -3
- data/lib/ethon/easy/callbacks.rb +2 -1
- data/lib/ethon/easy/informations.rb +3 -0
- data/lib/ethon/easy/response_callbacks.rb +6 -1
- data/lib/ethon/version.rb +1 -1
- data/spec/ethon/easy/callbacks_spec.rb +22 -0
- data/spec/ethon/easy/informations_spec.rb +6 -0
- data/spec/ethon/easy/mirror_spec.rb +1 -1
- data/spec/ethon/easy/operations_spec.rb +3 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30f75feeae963db1b4648a0b88e028361c78fda7aec43524a35f93b287ab2305
|
4
|
+
data.tar.gz: eb0ccd002c324dedaaceaa001172a61c520cd58e34d1a92440182faada17df74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6ec09378cd37ec552caee9a9153fb9e0582a770b18da882ec27f59028799885e1a9d9d7c496f1cfb4803ba3eb14bdd5e508f930cdc9523d16747d2a87ba1dfb
|
7
|
+
data.tar.gz: 77a50827108e8c6bc44f293bae5c2bfe6e871c94f40f93904ff611245143ef7900cf4cc2aa8a1511d0797dd80c03578e06b4e256f929deab544c73f9ef0d9e33
|
data/.github/workflows/ruby.yml
CHANGED
@@ -20,7 +20,7 @@ jobs:
|
|
20
20
|
fail-fast: false
|
21
21
|
matrix:
|
22
22
|
os: [ubuntu, macos]
|
23
|
-
ruby-version: [2.5, 2.6, 2.7, 3.0, head, debug, truffleruby
|
23
|
+
ruby-version: [2.5, 2.6, 2.7, 3.0, head, debug, truffleruby]
|
24
24
|
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
|
25
25
|
steps:
|
26
26
|
- uses: actions/checkout@v2
|
@@ -30,7 +30,7 @@ jobs:
|
|
30
30
|
then
|
31
31
|
brew install curl
|
32
32
|
else
|
33
|
-
sudo apt install -y libcurl4-openssl-dev
|
33
|
+
sudo apt update && sudo apt install -y --no-install-recommends libcurl4-openssl-dev
|
34
34
|
fi
|
35
35
|
- name: Set up Ruby
|
36
36
|
uses: ruby/setup-ruby@v1
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,9 @@
|
|
4
4
|
|
5
5
|
[Full Changelog](https://github.com/typhoeus/ethon/compare/v0.15.0...master)
|
6
6
|
|
7
|
+
* Added `redirect_url` value to available informations and `Easy::Mirror`.
|
8
|
+
([Adrien Rey-Jarthon](https://github.com/jarthod)
|
9
|
+
|
7
10
|
## 0.15.0
|
8
11
|
|
9
12
|
[Full Changelog](https://github.com/typhoeus/ethon/compare/v0.14.0...v0.15.0)
|
data/README.md
CHANGED
@@ -70,6 +70,29 @@ easy.perform
|
|
70
70
|
This is really handy when making requests since you don't have to care about setting
|
71
71
|
everything up correctly.
|
72
72
|
|
73
|
+
## Http2
|
74
|
+
Standard http2 servers require the client to connect once and create a session (multi) and then add simple requests to the multi handler.
|
75
|
+
The `perform` method then takes all the requests in the multi handler and sends them to the server.
|
76
|
+
|
77
|
+
See the following example
|
78
|
+
```ruby
|
79
|
+
multi = Ethon::Multi.new
|
80
|
+
easy = Ethon::Easy.new
|
81
|
+
|
82
|
+
easy.http_request("www.example.com/get", :get, { http_version: :httpv2_0 })
|
83
|
+
|
84
|
+
# Sending a request with http version 2 will send an Upgrade header to the server, which many older servers will not support
|
85
|
+
# See below for more info: https://everything.curl.dev/http/http2
|
86
|
+
# If this is a problem, send the below:
|
87
|
+
easy.http_request("www.example.com/get", :get, { http_version: :httpv2_prior_knowledge })
|
88
|
+
|
89
|
+
# To set the server to use http2 with https and http1 with http, send the following:
|
90
|
+
easy.http_request("www.example.com/get", :get, { http_version: :httpv2_tls }
|
91
|
+
|
92
|
+
multi.add(easy)
|
93
|
+
multi.perform
|
94
|
+
```
|
95
|
+
|
73
96
|
## LICENSE
|
74
97
|
|
75
98
|
(The MIT License)
|
data/lib/ethon/curls/classes.rb
CHANGED
@@ -32,8 +32,18 @@ module Ethon
|
|
32
32
|
|
33
33
|
def clear; self[:fd_count] = 0; end
|
34
34
|
else
|
35
|
-
#
|
36
|
-
FD_SETSIZE =
|
35
|
+
# https://github.com/typhoeus/ethon/issues/182
|
36
|
+
FD_SETSIZE = begin
|
37
|
+
# Allow to override the (new) default cap
|
38
|
+
if ENV['ETHON_FD_SIZE']
|
39
|
+
ENV['ETHON_FD_SIZE']
|
40
|
+
|
41
|
+
# auto-detect ulimit, but cap at 2^16
|
42
|
+
else
|
43
|
+
[::Ethon::Libc.getdtablesize, 65_536].min
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
37
47
|
layout :fds_bits, [:long, FD_SETSIZE / ::FFI::Type::LONG.size]
|
38
48
|
|
39
49
|
# :nodoc:
|
data/lib/ethon/curls/options.rb
CHANGED
@@ -307,6 +307,7 @@ module Ethon
|
|
307
307
|
option :easy, :port, :int, 3
|
308
308
|
option :easy, :tcp_nodelay, :bool, 121
|
309
309
|
option :easy, :address_scope, :int, 171
|
310
|
+
option :easy, :tcp_fastopen, :bool, 212
|
310
311
|
option :easy, :tcp_keepalive, :bool, 213
|
311
312
|
option :easy, :tcp_keepidle, :int, 214
|
312
313
|
option :easy, :tcp_keepintvl, :int, 215
|
@@ -352,7 +353,7 @@ module Ethon
|
|
352
353
|
option :easy, :cookiesession, :bool, 96
|
353
354
|
option :easy, :cookielist, :string, 135
|
354
355
|
option :easy, :httpget, :bool, 80
|
355
|
-
option :easy, :http_version, :enum, 84, [:none, :httpv1_0, :httpv1_1, :httpv2_0]
|
356
|
+
option :easy, :http_version, :enum, 84, [:none, :httpv1_0, :httpv1_1, :httpv2_0, :httpv2_tls, :httpv2_prior_knowledge]
|
356
357
|
option :easy, :ignore_content_length, :bool, 136
|
357
358
|
option :easy, :http_content_decoding, :bool, 158
|
358
359
|
option :easy, :http_transfer_decoding, :bool, 157
|
@@ -440,7 +441,7 @@ module Ethon
|
|
440
441
|
option_alias :easy, :keypasswd, :sslkeypasswd
|
441
442
|
option :easy, :sslengine, :string, 89
|
442
443
|
option :easy, :sslengine_default, :none, 90
|
443
|
-
option :easy, :sslversion, :enum, 32, [:default, :tlsv1, :sslv2, :sslv3, :tlsv1_0, :tlsv1_1, :tlsv1_2]
|
444
|
+
option :easy, :sslversion, :enum, 32, [:default, :tlsv1, :sslv2, :sslv3, :tlsv1_0, :tlsv1_1, :tlsv1_2, :tlsv1_3]
|
444
445
|
option :easy, :ssl_verifypeer, :bool, 64
|
445
446
|
option :easy, :cainfo, :string, 65
|
446
447
|
option :easy, :issuercert, :string, 170
|
@@ -463,7 +464,7 @@ module Ethon
|
|
463
464
|
option :easy, :proxy_capath, :string, 247
|
464
465
|
option :easy, :proxy_ssl_verifypeer, :bool, 248
|
465
466
|
option :easy, :proxy_ssl_verifyhost, :int, 249
|
466
|
-
option :easy, :proxy_sslversion, :enum, 250, [:default, :tlsv1, :sslv2, :sslv3, :tlsv1_0, :tlsv1_1, :tlsv1_2]
|
467
|
+
option :easy, :proxy_sslversion, :enum, 250, [:default, :tlsv1, :sslv2, :sslv3, :tlsv1_0, :tlsv1_1, :tlsv1_2, :tlsv1_3]
|
467
468
|
option :easy, :proxy_tlsauth_username, :string, 251
|
468
469
|
option :easy, :proxy_tlsauth_password, :string, 252
|
469
470
|
option :easy, :proxy_tlsauth_type, :enum, 253, [:none, :srp]
|
data/lib/ethon/easy/callbacks.rb
CHANGED
@@ -52,8 +52,9 @@ module Ethon
|
|
52
52
|
# @return [ Proc ] The callback.
|
53
53
|
def header_write_callback
|
54
54
|
@header_write_callback ||= proc {|stream, size, num, object|
|
55
|
+
result = headers
|
55
56
|
@response_headers << stream.read_string(size * num)
|
56
|
-
size * num
|
57
|
+
result != :abort ? size * num : -1
|
57
58
|
}
|
58
59
|
end
|
59
60
|
|
@@ -73,6 +73,9 @@ module Ethon
|
|
73
73
|
# actually followed.
|
74
74
|
:redirect_count => :long,
|
75
75
|
|
76
|
+
# URL a redirect would take you to, had you enabled redirects (Added in 7.18.2)
|
77
|
+
:redirect_url => :string,
|
78
|
+
|
76
79
|
# Return the bytes, the total amount of bytes that were uploaded
|
77
80
|
:size_upload => :double,
|
78
81
|
|
@@ -43,7 +43,12 @@ module Ethon
|
|
43
43
|
return if @headers_called
|
44
44
|
@headers_called = true
|
45
45
|
if defined?(@on_headers) and not @on_headers.nil?
|
46
|
-
|
46
|
+
result = nil
|
47
|
+
@on_headers.each do |callback|
|
48
|
+
result = callback.call(self)
|
49
|
+
break if result == :abort
|
50
|
+
end
|
51
|
+
result
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
data/lib/ethon/version.rb
CHANGED
@@ -56,4 +56,26 @@ describe Ethon::Easy::Callbacks do
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
59
|
+
|
60
|
+
describe "#header_write_callback" do
|
61
|
+
let(:header_write_callback) { easy.instance_variable_get(:@header_write_callback) }
|
62
|
+
let(:stream) { double(:read_string => "") }
|
63
|
+
context "when header returns not :abort" do
|
64
|
+
it "returns number bigger than 0" do
|
65
|
+
expect(header_write_callback.call(stream, 1, 1, nil) > 0).to be(true)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when header returns :abort" do
|
70
|
+
before do
|
71
|
+
easy.on_headers.clear
|
72
|
+
easy.on_headers { :abort }
|
73
|
+
end
|
74
|
+
let(:header_write_callback) { easy.instance_variable_get(:@header_write_callback) }
|
75
|
+
|
76
|
+
it "returns -1 to indicate abort to libcurl" do
|
77
|
+
expect(header_write_callback.call(stream, 1, 1, nil)).to eq(-1)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
59
81
|
end
|
@@ -81,6 +81,12 @@ describe Ethon::Easy::Informations do
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
+
describe "#redirect_url" do
|
85
|
+
it "returns nil as there is no redirect" do
|
86
|
+
expect(easy.redirect_url).to be(nil)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
84
90
|
describe "#request_size" do
|
85
91
|
it "returns 53" do
|
86
92
|
expect(easy.request_size).to eq(53)
|
@@ -11,7 +11,7 @@ describe Ethon::Easy::Mirror do
|
|
11
11
|
:total_time, :starttransfer_time, :appconnect_time,
|
12
12
|
:pretransfer_time, :connect_time, :namelookup_time, :redirect_time,
|
13
13
|
:size_upload, :size_download, :speed_upload, :speed_upload,
|
14
|
-
:effective_url, :primary_ip, :redirect_count, :debug_info
|
14
|
+
:effective_url, :primary_ip, :redirect_count, :redirect_url, :debug_info
|
15
15
|
].each do |name|
|
16
16
|
it "contains #{name}" do
|
17
17
|
expect(described_class::INFORMATIONS_TO_MIRROR).to include(name)
|
@@ -106,6 +106,7 @@ describe Ethon::Easy::Operations do
|
|
106
106
|
|
107
107
|
it "doesn't follow" do
|
108
108
|
expect(easy.response_code).to eq(302)
|
109
|
+
expect(easy.redirect_url).to eq("http://localhost:3001/")
|
109
110
|
end
|
110
111
|
end
|
111
112
|
|
@@ -115,6 +116,7 @@ describe Ethon::Easy::Operations do
|
|
115
116
|
|
116
117
|
it "follows" do
|
117
118
|
expect(easy.response_code).to eq(200)
|
119
|
+
expect(easy.redirect_url).to eq(nil)
|
118
120
|
end
|
119
121
|
|
120
122
|
context "when infinite redirect loop" do
|
@@ -124,6 +126,7 @@ describe Ethon::Easy::Operations do
|
|
124
126
|
context "when max redirect set" do
|
125
127
|
it "follows only x times" do
|
126
128
|
expect(easy.response_code).to eq(302)
|
129
|
+
expect(easy.redirect_url).to eq("http://localhost:3001/bad_redirect")
|
127
130
|
end
|
128
131
|
end
|
129
132
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ethon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hans Hasselberg
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -137,7 +137,7 @@ homepage: https://github.com/typhoeus/ethon
|
|
137
137
|
licenses:
|
138
138
|
- MIT
|
139
139
|
metadata: {}
|
140
|
-
post_install_message:
|
140
|
+
post_install_message:
|
141
141
|
rdoc_options: []
|
142
142
|
require_paths:
|
143
143
|
- lib
|
@@ -152,8 +152,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
- !ruby/object:Gem::Version
|
153
153
|
version: 1.3.6
|
154
154
|
requirements: []
|
155
|
-
rubygems_version: 3.
|
156
|
-
signing_key:
|
155
|
+
rubygems_version: 3.3.7
|
156
|
+
signing_key:
|
157
157
|
specification_version: 4
|
158
158
|
summary: Libcurl wrapper.
|
159
159
|
test_files:
|