wreq-rb 0.4.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 +47 -16
- data/exe/wreq +211 -0
- data/ext/wreq_rb/Cargo.toml +4 -6
- data/ext/wreq_rb/src/client.rs +145 -41
- 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 +53 -72
- 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
|
|
@@ -77,9 +77,23 @@ client = Wreq::Client.new(
|
|
|
77
77
|
zstd: true, # enable zstd decompression
|
|
78
78
|
emulation: "chrome_143", # browser emulation (enabled by default)
|
|
79
79
|
emulation_os: "windows", # OS emulation: windows, macos (default), linux, android, ios
|
|
80
|
+
header_order: [ # wire order of headers (names only, case-sensitive)
|
|
81
|
+
"host", # listed headers appear first in the given order, remaining
|
|
82
|
+
"user-agent", # emulation headers follow.
|
|
83
|
+
"accept",
|
|
84
|
+
],
|
|
80
85
|
headers: { # default headers for all requests
|
|
81
86
|
"Accept" => "application/json"
|
|
82
|
-
}
|
|
87
|
+
},
|
|
88
|
+
referer: true, # auto-set Referer header on redirects (default: true)
|
|
89
|
+
pool_max_idle_per_host: 10, # max idle connections per host
|
|
90
|
+
pool_max_size: 100, # max total connections in the pool
|
|
91
|
+
tcp_nodelay: true, # disable Nagle algorithm (default: true)
|
|
92
|
+
tcp_keepalive: 15, # SO_KEEPALIVE interval in seconds (default: 15)
|
|
93
|
+
local_address: "1.2.3.4", # bind outgoing connections to this source IP
|
|
94
|
+
tls_sni: true, # send SNI in TLS handshake (default: true)
|
|
95
|
+
min_tls_version: "tls1.2", # minimum TLS version: tls1.0, tls1.1, tls1.2, tls1.3
|
|
96
|
+
max_tls_version: "tls1.3", # maximum TLS version
|
|
83
97
|
)
|
|
84
98
|
|
|
85
99
|
resp = client.get("https://api.example.com/data")
|
|
@@ -100,6 +114,19 @@ All methods are available on both `Wreq` (module-level) and `Wreq::Client` (inst
|
|
|
100
114
|
| `head(url, **opts)` | HEAD request |
|
|
101
115
|
| `options(url, **opts)` | OPTIONS request |
|
|
102
116
|
|
|
117
|
+
### Cancelling Requests
|
|
118
|
+
|
|
119
|
+
Call `cancel` on a client to interrupt all in-flight requests immediately:
|
|
120
|
+
|
|
121
|
+
```ruby
|
|
122
|
+
client = Wreq::Client.new
|
|
123
|
+
|
|
124
|
+
# From another thread:
|
|
125
|
+
t = Thread.new { client.get("https://slow.example.com/big-download") }
|
|
126
|
+
sleep 1
|
|
127
|
+
client.cancel # all in-flight requests raise Wreq::Error with "request interrupted"
|
|
128
|
+
```
|
|
129
|
+
|
|
103
130
|
### Per-Request Options
|
|
104
131
|
|
|
105
132
|
Pass an options hash as the second argument to any HTTP method:
|
|
@@ -121,40 +148,40 @@ Pass an options hash as the second argument to any HTTP method:
|
|
|
121
148
|
|
|
122
149
|
## Browser Emulation
|
|
123
150
|
|
|
124
|
-
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.**
|
|
125
152
|
|
|
126
153
|
```ruby
|
|
127
154
|
resp = Wreq.get("https://tls.peet.ws/api/all")
|
|
128
155
|
|
|
129
156
|
# Explicit browser emulation
|
|
130
|
-
client = Wreq::Client.new(emulation: "
|
|
131
|
-
client = Wreq::Client.new(emulation: "
|
|
132
|
-
client = Wreq::Client.new(emulation: "
|
|
157
|
+
client = Wreq::Client.new(emulation: "firefox_151")
|
|
158
|
+
client = Wreq::Client.new(emulation: "safari_18.5")
|
|
159
|
+
client = Wreq::Client.new(emulation: "edge_148")
|
|
133
160
|
|
|
134
161
|
# Disable emulation entirely
|
|
135
162
|
client = Wreq::Client.new(emulation: false)
|
|
136
163
|
|
|
137
164
|
# Emulate a specific OS (default is macOS)
|
|
138
|
-
client = Wreq::Client.new(emulation: "
|
|
139
|
-
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")
|
|
140
167
|
|
|
141
168
|
# Emulation + custom user-agent (user_agent overrides emulation's UA)
|
|
142
|
-
client = Wreq::Client.new(emulation: "
|
|
169
|
+
client = Wreq::Client.new(emulation: "chrome_148", user_agent: "MyBot/1.0")
|
|
143
170
|
|
|
144
171
|
# Per-request emulation override
|
|
145
|
-
resp = client.get("https://example.com", emulation: "
|
|
172
|
+
resp = client.get("https://example.com", emulation: "safari_26.2")
|
|
146
173
|
```
|
|
147
174
|
|
|
148
175
|
### Supported Browsers
|
|
149
176
|
|
|
150
177
|
| Browser | Example values |
|
|
151
178
|
|---------|---------------|
|
|
152
|
-
| Chrome | `chrome_100` .. `
|
|
153
|
-
| Firefox | `firefox_109` .. `
|
|
154
|
-
| Safari | `safari_15.3` .. `safari_26.
|
|
155
|
-
| Edge | `edge_101` .. `
|
|
156
|
-
| Opera | `opera_116` .. `
|
|
157
|
-
| 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` |
|
|
158
185
|
|
|
159
186
|
## Response
|
|
160
187
|
|
|
@@ -183,3 +210,7 @@ bundle install
|
|
|
183
210
|
bundle exec rake compile
|
|
184
211
|
bundle exec rake test
|
|
185
212
|
```
|
|
213
|
+
|
|
214
|
+
## License
|
|
215
|
+
|
|
216
|
+
wreq-rb is released under the [Apache License, Version 2.0](LICENSE).
|
data/exe/wreq
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "optparse"
|
|
5
|
+
require "json"
|
|
6
|
+
require "wreq-rb"
|
|
7
|
+
|
|
8
|
+
cfg = {
|
|
9
|
+
method: nil,
|
|
10
|
+
headers: {},
|
|
11
|
+
include: false,
|
|
12
|
+
silent: false,
|
|
13
|
+
redirect: 10,
|
|
14
|
+
verify_cert: true,
|
|
15
|
+
verify_host: true,
|
|
16
|
+
pretty: false,
|
|
17
|
+
}
|
|
18
|
+
req = {}
|
|
19
|
+
|
|
20
|
+
parser = OptionParser.new do |o|
|
|
21
|
+
o.banner = "Usage: wreq [METHOD] URL [options]"
|
|
22
|
+
|
|
23
|
+
o.separator ""
|
|
24
|
+
o.separator "Request:"
|
|
25
|
+
|
|
26
|
+
o.on("-X", "--request METHOD", "HTTP method (default: GET)") { |m| cfg[:method] = m.upcase }
|
|
27
|
+
|
|
28
|
+
o.on("-H", "--header LINE", 'Request header, e.g. "Accept: application/json" (repeatable)') do |h|
|
|
29
|
+
name, _, value = h.partition(":")
|
|
30
|
+
cfg[:headers][name.strip] = value.strip
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
o.on("-d", "--data DATA",
|
|
34
|
+
"Request body. Prefix with @ to read from file, e.g. @body.json") do |d|
|
|
35
|
+
cfg[:method] ||= "POST"
|
|
36
|
+
if d.start_with?("@")
|
|
37
|
+
path = d[1..]
|
|
38
|
+
abort "wreq: cannot read '#{path}': file not found" unless File.exist?(path)
|
|
39
|
+
req[:body] = File.binread(path)
|
|
40
|
+
else
|
|
41
|
+
req[:body] = d
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
o.on("--json DATA",
|
|
46
|
+
"JSON body (sets Content-Type: application/json). Prefix with @ for file.") do |d|
|
|
47
|
+
cfg[:method] ||= "POST"
|
|
48
|
+
raw = d.start_with?("@") ? File.read(d[1..]) : d
|
|
49
|
+
begin
|
|
50
|
+
req[:json] = JSON.parse(raw)
|
|
51
|
+
rescue JSON::ParserError => e
|
|
52
|
+
abort "wreq: invalid JSON: #{e.message}"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
o.on("--form PAIR", "Form field as key=value (repeatable)") do |f|
|
|
57
|
+
cfg[:method] ||= "POST"
|
|
58
|
+
key, _, val = f.partition("=")
|
|
59
|
+
(req[:form] ||= {})[key] = val
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
o.on("-q", "--query PAIR", "Query parameter as key=value (repeatable)") do |q|
|
|
63
|
+
key, _, val = q.partition("=")
|
|
64
|
+
(req[:query] ||= {})[key] = val
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
o.separator ""
|
|
68
|
+
o.separator "Auth:"
|
|
69
|
+
|
|
70
|
+
o.on("-u", "--user USER[:PASS]", "Basic auth credentials") do |u|
|
|
71
|
+
user, _, pass = u.partition(":")
|
|
72
|
+
req[:basic] = [user, pass]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
o.on("--bearer TOKEN", "Bearer token auth") { |t| req[:bearer] = t }
|
|
76
|
+
|
|
77
|
+
o.separator ""
|
|
78
|
+
o.separator "Output:"
|
|
79
|
+
|
|
80
|
+
o.on("-i", "--include", "Include response headers in stdout before the body") do
|
|
81
|
+
cfg[:include] = true
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
o.on("-s", "--silent", "Suppress body output") { cfg[:silent] = true }
|
|
85
|
+
|
|
86
|
+
o.on("-o", "--output FILE", "Write body to FILE") { |f| cfg[:output] = f }
|
|
87
|
+
|
|
88
|
+
o.on("--pretty", "Pretty-print JSON response bodies") { cfg[:pretty] = true }
|
|
89
|
+
|
|
90
|
+
o.separator ""
|
|
91
|
+
o.separator "Connection:"
|
|
92
|
+
|
|
93
|
+
o.on("-L", "--location", "Follow redirects (default: on, max 10)") { cfg[:redirect] = 10 }
|
|
94
|
+
o.on("--no-location", "Do not follow redirects") { cfg[:redirect] = false }
|
|
95
|
+
o.on("--max-redirects N", Integer, "Max redirects (default: 10)") { |n| cfg[:redirect] = n }
|
|
96
|
+
|
|
97
|
+
o.on("-k", "--insecure", "Skip TLS certificate verification") do
|
|
98
|
+
cfg[:verify_cert] = false
|
|
99
|
+
cfg[:verify_host] = false
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
o.on("-x", "--proxy URL", "Proxy URL (e.g. http://host:port)") { |p| cfg[:proxy] = p }
|
|
103
|
+
|
|
104
|
+
o.on("--local-address IP", "Bind outgoing connections to this source IP address") do |ip|
|
|
105
|
+
cfg[:local_address] = ip
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
o.on("--timeout SECS", Float, "Total timeout in seconds") { |t| cfg[:timeout] = t }
|
|
109
|
+
o.on("--connect-timeout SECS", Float, "Connection timeout in seconds") { |t| cfg[:connect_timeout] = t }
|
|
110
|
+
|
|
111
|
+
o.on("--http1", "Force HTTP/1.1") { cfg[:http1_only] = true }
|
|
112
|
+
o.on("--http2", "Force HTTP/2") { cfg[:http2_only] = true }
|
|
113
|
+
|
|
114
|
+
o.separator ""
|
|
115
|
+
o.separator "Emulation:"
|
|
116
|
+
|
|
117
|
+
o.on("--emulation PROFILE",
|
|
118
|
+
"Browser emulation profile (e.g. chrome_145, firefox_147, safari_26.2)") do |e|
|
|
119
|
+
cfg[:emulation] = e
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
o.on("--emulation-os OS",
|
|
123
|
+
"Emulation OS override: windows, macos, linux, android, ios") do |os|
|
|
124
|
+
cfg[:emulation_os] = os
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
o.on("--no-emulation", "Disable browser emulation entirely") { cfg[:emulation] = false }
|
|
128
|
+
|
|
129
|
+
o.on("-A", "--user-agent UA", "Override User-Agent header") { |ua| cfg[:user_agent] = ua }
|
|
130
|
+
|
|
131
|
+
o.on("--cookie-store", "Enable persistent cookie jar for this request") { cfg[:cookie_store] = true }
|
|
132
|
+
|
|
133
|
+
o.separator ""
|
|
134
|
+
|
|
135
|
+
o.on("-V", "--version", "Print version and exit") { puts "wreq #{Wreq::VERSION}"; exit 0 }
|
|
136
|
+
o.on_tail("-h", "--help", "Show this help") { puts o; exit 0 }
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
args = ARGV.dup
|
|
140
|
+
|
|
141
|
+
# Allow bare method as first positional arg: `wreq POST https://...`
|
|
142
|
+
if args.first =~ /\A[A-Z]+\z/
|
|
143
|
+
cfg[:method] = args.shift
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
begin
|
|
147
|
+
parser.parse!(args)
|
|
148
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
|
|
149
|
+
abort "wreq: #{e.message}\nRun 'wreq --help' for usage."
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
url = args.shift
|
|
153
|
+
unless url
|
|
154
|
+
$stderr.puts parser
|
|
155
|
+
exit 1
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
cfg[:method] ||= "GET"
|
|
159
|
+
|
|
160
|
+
# Build Wreq::Client options (connection/emulation settings only)
|
|
161
|
+
CLIENT_KEYS = %i[emulation emulation_os user_agent proxy local_address timeout connect_timeout
|
|
162
|
+
http1_only http2_only cookie_store https_only].freeze
|
|
163
|
+
client_opts = cfg.slice(*CLIENT_KEYS).reject { |_, v| v.nil? }
|
|
164
|
+
client_opts[:redirect] = cfg[:redirect]
|
|
165
|
+
client_opts[:verify_cert] = cfg[:verify_cert]
|
|
166
|
+
client_opts[:verify_host] = cfg[:verify_host]
|
|
167
|
+
|
|
168
|
+
client = Wreq::Client.new(**client_opts)
|
|
169
|
+
|
|
170
|
+
# Per-request headers
|
|
171
|
+
req[:headers] = cfg[:headers] unless cfg[:headers].empty?
|
|
172
|
+
|
|
173
|
+
# Execute request
|
|
174
|
+
begin
|
|
175
|
+
response = client.public_send(cfg[:method].downcase, url, **req)
|
|
176
|
+
rescue NoMethodError
|
|
177
|
+
abort "wreq: unsupported HTTP method '#{cfg[:method]}'"
|
|
178
|
+
rescue => e
|
|
179
|
+
abort "wreq: #{e.message}"
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# -i: print response status + headers to stdout before body
|
|
183
|
+
if cfg[:include]
|
|
184
|
+
puts "#{response.version} #{response.status}"
|
|
185
|
+
response.headers.each do |k, values|
|
|
186
|
+
Array(values).each { |v| puts "#{k}: #{v}" }
|
|
187
|
+
end
|
|
188
|
+
puts ""
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
# Output body
|
|
192
|
+
unless cfg[:silent] || cfg[:method] == "HEAD"
|
|
193
|
+
if cfg[:output]
|
|
194
|
+
bytes = response.body_bytes.pack("C*")
|
|
195
|
+
File.binwrite(cfg[:output], bytes)
|
|
196
|
+
warn "Saved #{bytes.bytesize} bytes to #{cfg[:output]}"
|
|
197
|
+
else
|
|
198
|
+
body = response.body
|
|
199
|
+
if cfg[:pretty] && !body.nil? && !body.empty?
|
|
200
|
+
body = begin
|
|
201
|
+
JSON.pretty_generate(JSON.parse(body))
|
|
202
|
+
rescue JSON::ParserError
|
|
203
|
+
body
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
print body unless body.nil?
|
|
207
|
+
$stdout.puts if body && !body.empty? && !body.end_with?("\n")
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
exit response.success? ? 0 : 1
|
data/ext/wreq_rb/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "wreq_rb"
|
|
3
|
-
version = "0.
|
|
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
|
-
|