wreq-rb 0.5.0 → 0.5.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/Cargo.lock +1922 -397
- data/LICENSE +203 -0
- data/README.md +19 -15
- data/ext/wreq_rb/Cargo.toml +4 -6
- data/ext/wreq_rb/src/client.rs +41 -48
- data/lib/wreq-rb/version.rb +1 -1
- data/patches/0001-add-transfer-size-tracking.patch +76 -67
- data/vendor/wreq/Cargo.toml +119 -71
- data/vendor/wreq/README.md +25 -20
- data/vendor/wreq/bench/http1.rs +25 -0
- data/vendor/wreq/bench/http1_over_tls.rs +25 -0
- data/vendor/wreq/bench/http2.rs +25 -0
- data/vendor/wreq/bench/http2_over_tls.rs +25 -0
- data/vendor/wreq/bench/support/bench.rs +91 -0
- data/vendor/wreq/bench/support/client.rs +217 -0
- data/vendor/wreq/bench/support/server.rs +188 -0
- data/vendor/wreq/bench/support.rs +56 -0
- data/vendor/wreq/examples/cert_store.rs +4 -4
- data/vendor/wreq/examples/{emulation.rs → emulate.rs} +2 -2
- data/vendor/wreq/examples/http2_websocket.rs +2 -2
- data/vendor/wreq/examples/keylog.rs +3 -3
- data/vendor/wreq/examples/{request_with_emulation.rs → request_with_emulate.rs} +2 -2
- data/vendor/wreq/examples/rt.rs +23 -0
- data/vendor/wreq/src/client/body.rs +23 -61
- data/vendor/wreq/src/client/emulate.rs +119 -0
- data/vendor/wreq/src/client/{http/future.rs → future.rs} +11 -32
- data/vendor/wreq/src/client/{http → layer}/client/pool.rs +66 -61
- data/vendor/wreq/src/client/{http → layer}/client.rs +416 -270
- data/vendor/wreq/src/client/layer/config.rs +27 -6
- data/vendor/wreq/src/client/layer/decoder.rs +9 -4
- data/vendor/wreq/src/client/layer/redirect/future.rs +6 -3
- data/vendor/wreq/src/client/layer/redirect.rs +4 -5
- data/vendor/wreq/src/client/layer/retry.rs +8 -5
- data/vendor/wreq/src/client/layer/timeout/body.rs +15 -6
- data/vendor/wreq/src/client/layer/timeout/future.rs +23 -18
- data/vendor/wreq/src/client/layer/timeout.rs +24 -74
- data/vendor/wreq/src/client/layer.rs +1 -2
- data/vendor/wreq/src/client/multipart.rs +137 -154
- data/vendor/wreq/src/client/request.rs +202 -118
- data/vendor/wreq/src/client/response.rs +46 -45
- data/vendor/wreq/src/client/upgrade.rs +15 -0
- data/vendor/wreq/src/client/ws.rs +73 -25
- data/vendor/wreq/src/client.rs +1655 -17
- data/vendor/wreq/src/config.rs +11 -11
- data/vendor/wreq/src/{client/conn → conn}/connector.rs +139 -137
- data/vendor/wreq/src/conn/descriptor.rs +143 -0
- data/vendor/wreq/src/conn/http.rs +484 -0
- data/vendor/wreq/src/conn/net/io.rs +75 -0
- data/vendor/wreq/src/conn/net/tcp/compio.rs +71 -0
- data/vendor/wreq/src/conn/net/tcp/tokio.rs +57 -0
- data/vendor/wreq/src/conn/net/tcp.rs +561 -0
- data/vendor/wreq/src/conn/net/uds/compio.rs +60 -0
- data/vendor/wreq/src/{client/conn/uds.rs → conn/net/uds/tokio.rs} +18 -12
- data/vendor/wreq/src/conn/net/uds.rs +11 -0
- data/vendor/wreq/src/conn/net.rs +130 -0
- data/vendor/wreq/src/{client/conn → conn}/proxy/socks.rs +2 -9
- data/vendor/wreq/src/{client/conn → conn}/proxy/tunnel.rs +21 -56
- data/vendor/wreq/src/conn/tls_info.rs +47 -0
- data/vendor/wreq/src/{client/conn.rs → conn.rs} +202 -54
- data/vendor/wreq/src/cookie.rs +302 -142
- data/vendor/wreq/src/dns/gai/compio.rs +77 -0
- data/vendor/wreq/src/dns/gai/tokio.rs +90 -0
- data/vendor/wreq/src/dns/gai.rs +14 -164
- data/vendor/wreq/src/dns/hickory.rs +16 -23
- data/vendor/wreq/src/dns/resolve.rs +7 -41
- data/vendor/wreq/src/dns.rs +90 -7
- data/vendor/wreq/src/error.rs +57 -31
- data/vendor/wreq/src/ext.rs +25 -0
- data/vendor/wreq/src/group.rs +211 -0
- data/vendor/wreq/src/header.rs +100 -112
- data/vendor/wreq/src/lib.rs +124 -73
- data/vendor/wreq/src/proxy.rs +6 -20
- data/vendor/wreq/src/redirect.rs +1 -1
- data/vendor/wreq/src/rt.rs +208 -0
- data/vendor/wreq/src/sync.rs +97 -98
- data/vendor/wreq/src/tls/compress.rs +124 -0
- data/vendor/wreq/src/tls/conn/ext.rs +54 -45
- data/vendor/wreq/src/tls/conn/service.rs +14 -18
- data/vendor/wreq/src/tls/conn.rs +169 -241
- data/vendor/wreq/src/tls/keylog.rs +68 -5
- data/vendor/wreq/src/tls/session.rs +205 -0
- data/vendor/wreq/src/tls/{x509 → trust}/identity.rs +4 -21
- data/vendor/wreq/src/tls/{x509/parser.rs → trust/parse.rs} +1 -1
- data/vendor/wreq/src/tls/{x509 → trust}/store.rs +42 -81
- data/vendor/wreq/src/tls/{x509.rs → trust.rs} +8 -2
- data/vendor/wreq/src/tls.rs +489 -25
- data/vendor/wreq/src/trace.rs +0 -12
- data/vendor/wreq/src/util.rs +1 -1
- data/vendor/wreq/tests/badssl.rs +10 -10
- data/vendor/wreq/tests/client.rs +3 -9
- data/vendor/wreq/tests/cookie.rs +6 -8
- data/vendor/wreq/tests/{emulation.rs → emulate.rs} +130 -22
- data/vendor/wreq/tests/multipart.rs +43 -1
- data/vendor/wreq/tests/proxy.rs +1 -1
- data/vendor/wreq/tests/support/layer.rs +1 -0
- metadata +49 -71
- data/patches/0002-add-cancel-connections.patch +0 -181
- data/vendor/wreq/src/client/conn/conn.rs +0 -231
- data/vendor/wreq/src/client/conn/http.rs +0 -1023
- data/vendor/wreq/src/client/conn/tls_info.rs +0 -98
- data/vendor/wreq/src/client/core/body/incoming.rs +0 -485
- data/vendor/wreq/src/client/core/body/length.rs +0 -118
- data/vendor/wreq/src/client/core/body.rs +0 -34
- data/vendor/wreq/src/client/core/common/buf.rs +0 -149
- data/vendor/wreq/src/client/core/common/rewind.rs +0 -141
- data/vendor/wreq/src/client/core/common/watch.rs +0 -76
- data/vendor/wreq/src/client/core/common.rs +0 -3
- data/vendor/wreq/src/client/core/conn/http1.rs +0 -342
- data/vendor/wreq/src/client/core/conn/http2.rs +0 -307
- data/vendor/wreq/src/client/core/conn.rs +0 -11
- data/vendor/wreq/src/client/core/dispatch.rs +0 -299
- data/vendor/wreq/src/client/core/error.rs +0 -435
- data/vendor/wreq/src/client/core/ext.rs +0 -201
- data/vendor/wreq/src/client/core/http1.rs +0 -178
- data/vendor/wreq/src/client/core/http2.rs +0 -483
- data/vendor/wreq/src/client/core/proto/h1/conn.rs +0 -988
- data/vendor/wreq/src/client/core/proto/h1/decode.rs +0 -1170
- data/vendor/wreq/src/client/core/proto/h1/dispatch.rs +0 -684
- data/vendor/wreq/src/client/core/proto/h1/encode.rs +0 -580
- data/vendor/wreq/src/client/core/proto/h1/io.rs +0 -879
- data/vendor/wreq/src/client/core/proto/h1/role.rs +0 -694
- data/vendor/wreq/src/client/core/proto/h1.rs +0 -104
- data/vendor/wreq/src/client/core/proto/h2/client.rs +0 -650
- data/vendor/wreq/src/client/core/proto/h2/ping.rs +0 -539
- data/vendor/wreq/src/client/core/proto/h2.rs +0 -379
- data/vendor/wreq/src/client/core/proto/headers.rs +0 -138
- data/vendor/wreq/src/client/core/proto.rs +0 -58
- data/vendor/wreq/src/client/core/rt/bounds.rs +0 -57
- data/vendor/wreq/src/client/core/rt/timer.rs +0 -150
- data/vendor/wreq/src/client/core/rt/tokio.rs +0 -99
- data/vendor/wreq/src/client/core/rt.rs +0 -25
- data/vendor/wreq/src/client/core/upgrade.rs +0 -267
- data/vendor/wreq/src/client/core.rs +0 -16
- data/vendor/wreq/src/client/emulation.rs +0 -161
- data/vendor/wreq/src/client/http/client/error.rs +0 -142
- data/vendor/wreq/src/client/http/client/exec.rs +0 -29
- data/vendor/wreq/src/client/http/client/extra.rs +0 -77
- data/vendor/wreq/src/client/http/client/util.rs +0 -104
- data/vendor/wreq/src/client/http.rs +0 -1629
- data/vendor/wreq/src/client/layer/config/options.rs +0 -156
- data/vendor/wreq/src/client/layer/cookie.rs +0 -161
- data/vendor/wreq/src/hash.rs +0 -143
- data/vendor/wreq/src/tls/conn/cache.rs +0 -123
- data/vendor/wreq/src/tls/conn/cert_compression.rs +0 -125
- data/vendor/wreq/src/tls/keylog/handle.rs +0 -64
- data/vendor/wreq/src/tls/options.rs +0 -464
- /data/vendor/wreq/src/client/{http → layer}/client/lazy.rs +0 -0
- /data/vendor/wreq/src/{client/conn → conn}/proxy.rs +0 -0
- /data/vendor/wreq/src/{client/conn → conn}/verbose.rs +0 -0
data/LICENSE
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Yicheng Zhou
|
|
191
|
+
Copyright 2026 Illia Zub
|
|
192
|
+
|
|
193
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
194
|
+
you may not use this file except in compliance with the License.
|
|
195
|
+
You may obtain a copy of the License at
|
|
196
|
+
|
|
197
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
198
|
+
|
|
199
|
+
Unless required by applicable law or agreed to in writing, software
|
|
200
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
201
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
202
|
+
See the License for the specific language governing permissions and
|
|
203
|
+
limitations under the License.
|
data/README.md
CHANGED
|
@@ -47,7 +47,7 @@ resp = Wreq.get("https://httpbin.org/bearer", bearer: "my-token")
|
|
|
47
47
|
resp = Wreq.get("https://httpbin.org/basic-auth/user/pass", basic: ["user", "pass"])
|
|
48
48
|
|
|
49
49
|
# Browser emulation (enabled by default)
|
|
50
|
-
resp = Wreq.get("https://tls.peet.ws/api/all", emulation: "
|
|
50
|
+
resp = Wreq.get("https://tls.peet.ws/api/all", emulation: "chrome_148")
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
## Using a Client
|
|
@@ -116,7 +116,7 @@ All methods are available on both `Wreq` (module-level) and `Wreq::Client` (inst
|
|
|
116
116
|
|
|
117
117
|
### Cancelling Requests
|
|
118
118
|
|
|
119
|
-
Call `cancel` on a client to
|
|
119
|
+
Call `cancel` on a client to interrupt all in-flight requests immediately:
|
|
120
120
|
|
|
121
121
|
```ruby
|
|
122
122
|
client = Wreq::Client.new
|
|
@@ -124,7 +124,7 @@ client = Wreq::Client.new
|
|
|
124
124
|
# From another thread:
|
|
125
125
|
t = Thread.new { client.get("https://slow.example.com/big-download") }
|
|
126
126
|
sleep 1
|
|
127
|
-
client.cancel # all in-flight requests
|
|
127
|
+
client.cancel # all in-flight requests raise Wreq::Error with "request interrupted"
|
|
128
128
|
```
|
|
129
129
|
|
|
130
130
|
### Per-Request Options
|
|
@@ -148,25 +148,25 @@ Pass an options hash as the second argument to any HTTP method:
|
|
|
148
148
|
|
|
149
149
|
## Browser Emulation
|
|
150
150
|
|
|
151
|
-
wreq-rb emulates real browser TLS fingerprints, HTTP/2 settings, and headers by default. **The
|
|
151
|
+
wreq-rb emulates real browser TLS fingerprints, HTTP/2 settings, and headers by default. **The latest supported Chrome is used when no emulation is specified.**
|
|
152
152
|
|
|
153
153
|
```ruby
|
|
154
154
|
resp = Wreq.get("https://tls.peet.ws/api/all")
|
|
155
155
|
|
|
156
156
|
# Explicit browser emulation
|
|
157
|
-
client = Wreq::Client.new(emulation: "
|
|
157
|
+
client = Wreq::Client.new(emulation: "firefox_151")
|
|
158
158
|
client = Wreq::Client.new(emulation: "safari_18.5")
|
|
159
|
-
client = Wreq::Client.new(emulation: "
|
|
159
|
+
client = Wreq::Client.new(emulation: "edge_148")
|
|
160
160
|
|
|
161
161
|
# Disable emulation entirely
|
|
162
162
|
client = Wreq::Client.new(emulation: false)
|
|
163
163
|
|
|
164
164
|
# Emulate a specific OS (default is macOS)
|
|
165
|
-
client = Wreq::Client.new(emulation: "
|
|
166
|
-
client = Wreq::Client.new(emulation: "
|
|
165
|
+
client = Wreq::Client.new(emulation: "chrome_148", emulation_os: "windows")
|
|
166
|
+
client = Wreq::Client.new(emulation: "chrome_148", emulation_os: "linux")
|
|
167
167
|
|
|
168
168
|
# Emulation + custom user-agent (user_agent overrides emulation's UA)
|
|
169
|
-
client = Wreq::Client.new(emulation: "
|
|
169
|
+
client = Wreq::Client.new(emulation: "chrome_148", user_agent: "MyBot/1.0")
|
|
170
170
|
|
|
171
171
|
# Per-request emulation override
|
|
172
172
|
resp = client.get("https://example.com", emulation: "safari_26.2")
|
|
@@ -176,12 +176,12 @@ resp = client.get("https://example.com", emulation: "safari_26.2")
|
|
|
176
176
|
|
|
177
177
|
| Browser | Example values |
|
|
178
178
|
|---------|---------------|
|
|
179
|
-
| Chrome | `chrome_100` .. `
|
|
180
|
-
| Firefox | `firefox_109` .. `
|
|
181
|
-
| Safari | `safari_15.3` .. `safari_26.
|
|
182
|
-
| Edge | `edge_101` .. `
|
|
183
|
-
| Opera | `opera_116` .. `
|
|
184
|
-
| OkHttp | `
|
|
179
|
+
| Chrome | `chrome_100` .. `chrome_148` |
|
|
180
|
+
| Firefox | `firefox_109` .. `firefox_151`, `firefox_private_135` |
|
|
181
|
+
| Safari | `safari_15.3` .. `safari_26.4`, `safari_ios_26`, `safari_ipad_18` |
|
|
182
|
+
| Edge | `edge_101` .. `edge_148` |
|
|
183
|
+
| Opera | `opera_116` .. `opera_131` |
|
|
184
|
+
| OkHttp | `okhttp_3.9` .. `okhttp_5` |
|
|
185
185
|
|
|
186
186
|
## Response
|
|
187
187
|
|
|
@@ -210,3 +210,7 @@ bundle install
|
|
|
210
210
|
bundle exec rake compile
|
|
211
211
|
bundle exec rake test
|
|
212
212
|
```
|
|
213
|
+
|
|
214
|
+
## License
|
|
215
|
+
|
|
216
|
+
wreq-rb is released under the [Apache License, Version 2.0](LICENSE).
|
data/ext/wreq_rb/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "wreq_rb"
|
|
3
|
-
version = "0.5.
|
|
3
|
+
version = "0.5.1"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
publish = false
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ crate-type = ["cdylib"]
|
|
|
10
10
|
[dependencies]
|
|
11
11
|
magnus = { version = "0.8", features = ["rb-sys"] }
|
|
12
12
|
rb-sys = "0.9"
|
|
13
|
-
wreq = { path = "../../vendor/wreq", features = [
|
|
13
|
+
wreq = { path = "../../vendor/wreq", version = "=6.0.0-rc.29", features = [
|
|
14
14
|
"cookies",
|
|
15
15
|
"json",
|
|
16
16
|
"gzip",
|
|
@@ -24,7 +24,7 @@ wreq = { path = "../../vendor/wreq", features = [
|
|
|
24
24
|
"query",
|
|
25
25
|
"form",
|
|
26
26
|
] }
|
|
27
|
-
wreq-util = { version = "=3.0.0-rc.
|
|
27
|
+
wreq-util = { version = "=3.0.0-rc.12", features = ["emulation", "emulation-serde", "emulation-compression"] }
|
|
28
28
|
tokio = { version = "1", features = ["full"] }
|
|
29
29
|
tokio-util = "0.7"
|
|
30
30
|
serde_json = "1.0"
|
|
@@ -32,8 +32,6 @@ bytes = "1"
|
|
|
32
32
|
http = "1"
|
|
33
33
|
|
|
34
34
|
[target.'cfg(target_os = "linux")'.dependencies]
|
|
35
|
-
wreq = { path = "../../vendor/wreq", features = [
|
|
35
|
+
wreq = { path = "../../vendor/wreq", version = "=6.0.0-rc.29", features = [
|
|
36
36
|
"prefix-symbols",
|
|
37
37
|
] }
|
|
38
|
-
|
|
39
|
-
|
data/ext/wreq_rb/src/client.rs
CHANGED
|
@@ -13,7 +13,7 @@ use tokio_util::sync::CancellationToken;
|
|
|
13
13
|
use std::net::IpAddr;
|
|
14
14
|
use wreq::header::{HeaderMap, HeaderName, HeaderValue, OrigHeaderMap};
|
|
15
15
|
use wreq::tls::TlsVersion;
|
|
16
|
-
use wreq_util::{Emulation as BrowserEmulation,
|
|
16
|
+
use wreq_util::{Emulation as BrowserEmulation, Platform as EmulationPlatform, Profile as BrowserProfile};
|
|
17
17
|
|
|
18
18
|
use crate::error::{generic_error, to_magnus_error};
|
|
19
19
|
use crate::response::Response;
|
|
@@ -141,35 +141,35 @@ async fn execute_request(req: wreq::RequestBuilder) -> Result<ResponseData, wreq
|
|
|
141
141
|
// Emulation helpers
|
|
142
142
|
// --------------------------------------------------------------------------
|
|
143
143
|
|
|
144
|
-
/// The default
|
|
145
|
-
const DEFAULT_EMULATION:
|
|
144
|
+
/// The default browser profile to apply when none is specified.
|
|
145
|
+
const DEFAULT_EMULATION: BrowserProfile = BrowserProfile::Chrome148;
|
|
146
146
|
|
|
147
|
-
/// Parse a Ruby string like "chrome_143" into a
|
|
148
|
-
fn parse_emulation(name: &str) -> Result<
|
|
147
|
+
/// Parse a Ruby string like "chrome_143" into a BrowserProfile variant.
|
|
148
|
+
fn parse_emulation(name: &str) -> Result<BrowserProfile, magnus::Error> {
|
|
149
149
|
let json_val = serde_json::Value::String(name.to_string());
|
|
150
|
-
serde_json::from_value::<
|
|
151
|
-
.map_err(|_| generic_error(format!("unknown emulation: '{}'. Use names like '
|
|
150
|
+
serde_json::from_value::<BrowserProfile>(json_val)
|
|
151
|
+
.map_err(|_| generic_error(format!("unknown emulation: '{}'. Use names like 'chrome_148', 'firefox_151', 'safari_18.5', etc.", name)))
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
/// Parse a Ruby string like "windows" into an
|
|
155
|
-
fn parse_emulation_os(name: &str) -> Result<
|
|
154
|
+
/// Parse a Ruby string like "windows" into an EmulationPlatform variant.
|
|
155
|
+
fn parse_emulation_os(name: &str) -> Result<EmulationPlatform, magnus::Error> {
|
|
156
156
|
let json_val = serde_json::Value::String(name.to_string());
|
|
157
|
-
serde_json::from_value::<
|
|
157
|
+
serde_json::from_value::<EmulationPlatform>(json_val)
|
|
158
158
|
.map_err(|_| generic_error("unknown emulation_os. Use: 'windows', 'macos', 'linux', 'android', 'ios'"))
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
/// Build
|
|
161
|
+
/// Build a BrowserEmulation from a profile and an optional platform from the opts hash.
|
|
162
162
|
fn build_emulation_option(
|
|
163
|
-
|
|
163
|
+
profile: BrowserProfile,
|
|
164
164
|
opts: &RHash,
|
|
165
|
-
) -> Result<
|
|
166
|
-
let
|
|
167
|
-
Some(
|
|
168
|
-
None =>
|
|
165
|
+
) -> Result<BrowserEmulation, magnus::Error> {
|
|
166
|
+
let platform = match hash_get_string(opts, "emulation_os")? {
|
|
167
|
+
Some(platform_name) => parse_emulation_os(&platform_name)?,
|
|
168
|
+
None => EmulationPlatform::default(),
|
|
169
169
|
};
|
|
170
|
-
Ok(
|
|
171
|
-
.
|
|
172
|
-
.
|
|
170
|
+
Ok(BrowserEmulation::builder()
|
|
171
|
+
.profile(profile)
|
|
172
|
+
.platform(platform)
|
|
173
173
|
.build())
|
|
174
174
|
}
|
|
175
175
|
|
|
@@ -192,7 +192,8 @@ impl Client {
|
|
|
192
192
|
Some(RHash::try_convert(args[0])?)
|
|
193
193
|
};
|
|
194
194
|
|
|
195
|
-
let mut builder = wreq::Client::builder()
|
|
195
|
+
let mut builder = wreq::Client::builder()
|
|
196
|
+
.retry(wreq::retry::Policy::never());
|
|
196
197
|
|
|
197
198
|
if let Some(opts) = opts {
|
|
198
199
|
// Apply header_order BEFORE emulation so the user's ordering takes precedence
|
|
@@ -276,11 +277,11 @@ impl Client {
|
|
|
276
277
|
}
|
|
277
278
|
|
|
278
279
|
if let Some(v) = hash_get_bool(&opts, "verify_host")? {
|
|
279
|
-
builder = builder.
|
|
280
|
+
builder = builder.tls_verify_hostname(v);
|
|
280
281
|
}
|
|
281
282
|
|
|
282
283
|
if let Some(v) = hash_get_bool(&opts, "verify_cert")? {
|
|
283
|
-
builder = builder.
|
|
284
|
+
builder = builder.tls_cert_verification(v);
|
|
284
285
|
}
|
|
285
286
|
|
|
286
287
|
if let Some(true) = hash_get_bool(&opts, "http1_only")? {
|
|
@@ -311,7 +312,7 @@ impl Client {
|
|
|
311
312
|
builder = builder.pool_max_idle_per_host(n);
|
|
312
313
|
}
|
|
313
314
|
|
|
314
|
-
if let Some(n) =
|
|
315
|
+
if let Some(n) = hash_get_usize(&opts, "pool_max_size")? {
|
|
315
316
|
builder = builder.pool_max_size(n);
|
|
316
317
|
}
|
|
317
318
|
|
|
@@ -334,11 +335,11 @@ impl Client {
|
|
|
334
335
|
}
|
|
335
336
|
|
|
336
337
|
if let Some(s) = hash_get_string(&opts, "min_tls_version")? {
|
|
337
|
-
builder = builder.
|
|
338
|
+
builder = builder.tls_min_version(parse_tls_version(&s)?);
|
|
338
339
|
}
|
|
339
340
|
|
|
340
341
|
if let Some(s) = hash_get_string(&opts, "max_tls_version")? {
|
|
341
|
-
builder = builder.
|
|
342
|
+
builder = builder.tls_max_version(parse_tls_version(&s)?);
|
|
342
343
|
}
|
|
343
344
|
} else {
|
|
344
345
|
builder = builder.emulation(DEFAULT_EMULATION);
|
|
@@ -387,7 +388,6 @@ impl Client {
|
|
|
387
388
|
old
|
|
388
389
|
};
|
|
389
390
|
old_token.cancel();
|
|
390
|
-
self.inner.cancel_connections();
|
|
391
391
|
}
|
|
392
392
|
|
|
393
393
|
fn execute_method(&self, method_str: &str, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
@@ -445,6 +445,21 @@ fn apply_request_options(
|
|
|
445
445
|
mut req: wreq::RequestBuilder,
|
|
446
446
|
opts: &RHash,
|
|
447
447
|
) -> Result<wreq::RequestBuilder, magnus::Error> {
|
|
448
|
+
if let Some(val) = hash_get_value(opts, "emulation")? {
|
|
449
|
+
let ruby = unsafe { Ruby::get_unchecked() };
|
|
450
|
+
if val.is_kind_of(ruby.class_false_class()) {
|
|
451
|
+
// emulation: false — no per-request emulation override
|
|
452
|
+
} else if val.is_kind_of(ruby.class_true_class()) {
|
|
453
|
+
let opt = build_emulation_option(DEFAULT_EMULATION, opts)?;
|
|
454
|
+
req = req.emulation(opt);
|
|
455
|
+
} else {
|
|
456
|
+
let name: String = TryConvert::try_convert(val)?;
|
|
457
|
+
let emu = parse_emulation(&name)?;
|
|
458
|
+
let opt = build_emulation_option(emu, opts)?;
|
|
459
|
+
req = req.emulation(opt);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
448
463
|
if let Some(hdr_hash) = hash_get_hash(opts, "headers")? {
|
|
449
464
|
let hmap = hash_to_header_map(&hdr_hash)?;
|
|
450
465
|
req = req.headers(hmap);
|
|
@@ -499,21 +514,6 @@ fn apply_request_options(
|
|
|
499
514
|
req = req.proxy(proxy);
|
|
500
515
|
}
|
|
501
516
|
|
|
502
|
-
if let Some(val) = hash_get_value(opts, "emulation")? {
|
|
503
|
-
let ruby = unsafe { Ruby::get_unchecked() };
|
|
504
|
-
if val.is_kind_of(ruby.class_false_class()) {
|
|
505
|
-
// emulation: false — no per-request emulation override
|
|
506
|
-
} else if val.is_kind_of(ruby.class_true_class()) {
|
|
507
|
-
let opt = build_emulation_option(DEFAULT_EMULATION, opts)?;
|
|
508
|
-
req = req.emulation(opt);
|
|
509
|
-
} else {
|
|
510
|
-
let name: String = TryConvert::try_convert(val)?;
|
|
511
|
-
let emu = parse_emulation(&name)?;
|
|
512
|
-
let opt = build_emulation_option(emu, opts)?;
|
|
513
|
-
req = req.emulation(opt);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
517
|
Ok(req)
|
|
518
518
|
}
|
|
519
519
|
|
|
@@ -599,13 +599,6 @@ fn hash_get_usize(hash: &RHash, key: &str) -> Result<Option<usize>, magnus::Erro
|
|
|
599
599
|
}
|
|
600
600
|
}
|
|
601
601
|
|
|
602
|
-
fn hash_get_u32(hash: &RHash, key: &str) -> Result<Option<u32>, magnus::Error> {
|
|
603
|
-
match hash_get_value(hash, key)? {
|
|
604
|
-
Some(v) => Ok(Some(TryConvert::try_convert(v)?)),
|
|
605
|
-
None => Ok(None),
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
|
|
609
602
|
fn parse_tls_version(s: &str) -> Result<TlsVersion, magnus::Error> {
|
|
610
603
|
match s {
|
|
611
604
|
"tls1.0" | "tls_1_0" | "1.0" => Ok(TlsVersion::TLS_1_0),
|
data/lib/wreq-rb/version.rb
CHANGED