wreq-rb 0.6.1-aarch64-linux → 0.7.1-aarch64-linux

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a59b2a80bdaf1731f7face8b86de25398d321fc9e0a66c434869d3c79ce9156
4
- data.tar.gz: b95c12fbec41021bf3dce2013c1fb783f4babd0a930b54a395beccde0cc93e46
3
+ metadata.gz: 34a9ecff8b48e9d217dfa7564f0c23485bacb253ddd3ae02ca545eec7fbb4290
4
+ data.tar.gz: e3c1c8d95b539e08084cdb0fe1dc3d783d7cd64c6f46ab0c272851ab6e7543c1
5
5
  SHA512:
6
- metadata.gz: aa1d89143efd742c76ec4b7acb4c2df0012c8f9934541f95380cf8ff11be8536ced80fda0408b5ac4b8af8db44eb2f1ce47b23b5cc955ed3a44305b28a9575eb
7
- data.tar.gz: 01df00261a1bb432ae441694fb58dbe4662ac0230d30db31da62dba2339e4d81696c06deaf4f1117e0556ca05c9adc506ad1cfa2f2334a6cc5831e9657a5bd8b
6
+ metadata.gz: 0b42d68e9903704282e222ac1748c637e7968742b382acc489b8dc1371baa8eb3ff4c59ce57ccf4904a03f6f34044609c0e6089283c32aff33d6c60e292d6b69
7
+ data.tar.gz: 9dd5b73f3ec4e24a7846ffd5737267eb1764ad653561cf8f26089e71a8c6396cfded9a8594d080213ff6b7273cd999f3389d31b1e80e396a49331805aa45301c
data/README.md CHANGED
@@ -142,6 +142,33 @@ client.request_batch([
142
142
  - `cancel` and Ruby thread interrupts abort the whole batch, raising
143
143
  `Wreq::Error` with `"request interrupted"`.
144
144
 
145
+ ### Preconnecting
146
+
147
+ `Wreq::Client#preconnect` opens a connection to a URL's origin ahead of time —
148
+ DNS, TCP, proxy tunnel and TLS handshake — without sending a request. The
149
+ connection is kept idle in the client's pool, so the next request to the same
150
+ origin skips connection setup.
151
+
152
+ ```ruby
153
+ client = Wreq::Client.new
154
+
155
+ client.preconnect("https://api.example.com") # returns nil, raises Wreq::Error on failure
156
+ # ... later ...
157
+ client.get("https://api.example.com/data") # reuses the warm connection
158
+ ```
159
+
160
+ - Connection-level options must match the later request for the connection to
161
+ be reused. Pass `proxy:` and `emulation:` (plus `emulation_os:` etc.) the same
162
+ way you would to the request. `timeout:` bounds the preconnect. Other request
163
+ options are ignored.
164
+ - If an idle connection to the origin already exists, it's reused and no new
165
+ connection is opened. Preconnect several origins concurrently from separate
166
+ threads, because the GVL is released.
167
+ - The connection is subject to the pool's idle timeout (90 seconds) and may
168
+ also be closed by the server. If it's closed, the request falls back to a
169
+ fresh connection. Preconnecting has no effect with `pool_max_idle_per_host: 0`.
170
+ - `cancel` and Ruby thread interrupts abort a pending preconnect.
171
+
145
172
  ### Cancelling Requests
146
173
 
147
174
  Call `cancel` on a client to interrupt all in-flight requests immediately:
@@ -173,6 +200,7 @@ Pass an options hash as the second argument to any HTTP method:
173
200
  | `proxy` | String | Per-request proxy URL |
174
201
  | `emulation` | String/Boolean | Per-request emulation override |
175
202
  | `emulation_os` | String | OS emulation: `windows`, `macos`, `linux`, `android`, `ios` |
203
+ | `default_headers` | Boolean | `false` skips the client's default headers for this request (default: `true`) |
176
204
 
177
205
  ## Browser Emulation
178
206
 
@@ -198,6 +226,14 @@ client = Wreq::Client.new(emulation: "chrome_148", user_agent: "MyBot/1.0")
198
226
 
199
227
  # Per-request emulation override
200
228
  resp = client.get("https://example.com", emulation: "safari_26.2")
229
+
230
+ # Send only the request's headers: skips the client's emulation headers,
231
+ # user_agent and headers. A per-request emulation still adds its own.
232
+ # The emulation's TLS and HTTP/2 settings stay. The client's header_order
233
+ # setting still takes precedence over the request hash's order.
234
+ resp = client.get("https://example.com/script.js",
235
+ default_headers: false,
236
+ headers: { "User-Agent" => "...", "Accept" => "*/*", "Sec-Fetch-Dest" => "script" })
201
237
  ```
202
238
 
203
239
  ### Supported Browsers
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wreq
4
- VERSION = "0.6.1"
4
+ VERSION = "0.7.1"
5
5
  end
Binary file
Binary file
Binary file
@@ -0,0 +1,266 @@
1
+ diff --git a/src/client.rs b/src/client.rs
2
+ index c5eda4c6..629f1433 100644
3
+ --- a/src/client.rs
4
+ +++ b/src/client.rs
5
+ @@ -48,7 +48,9 @@ use self::{
6
+ config::{ConfigService, ConfigServiceLayer},
7
+ redirect::{FollowRedirect, FollowRedirectLayer},
8
+ retry::RetryPolicy,
9
+ - timeout::{Timeout, TimeoutLayer, TimeoutOptions, body::TimeoutBody},
10
+ + timeout::{
11
+ + Timeout, TimeoutLayer, TimeoutOptions, body::TimeoutBody, fetch_timeout_options,
12
+ + },
13
+ transfer_size::{CountingBody, TransferSizeLayer, TransferSizeService},
14
+ },
15
+ request::{Request, RequestBuilder},
16
+ @@ -60,6 +62,7 @@ use crate::cookie;
17
+ use crate::dns::hickory::HickoryDnsResolver;
18
+ use crate::{
19
+ IntoUri, Method, Proxy,
20
+ + config::RequestConfig,
21
+ conn::{
22
+ BoxedConnectorLayer, BoxedTransportConnector, Conn, Unnameable,
23
+ connector::{Connector, ConnectorBuilder},
24
+ @@ -68,6 +71,7 @@ use crate::{
25
+ },
26
+ dns::{DnsResolverWithOverrides, DynResolver, GaiResolver, IntoResolve, Resolve},
27
+ error::{self, Error},
28
+ + ext::UriExt,
29
+ header::OrigHeaderMap,
30
+ http1::Http1Options,
31
+ http2::Http2Options,
32
+ @@ -154,7 +158,23 @@ type BoxedClientServiceLayer = BoxCloneSyncServiceLayer<
33
+ ///
34
+ /// [`Rc`]: std::rc::Rc
35
+ #[derive(Clone)]
36
+ -pub struct Client(Arc<Either<ClientService, BoxedClientService>>);
37
+ +pub struct Client(Arc<ClientRef>);
38
+ +
39
+ +struct ClientRef {
40
+ + service: Either<ClientService, BoxedClientService>,
41
+ + preconnector: Preconnector,
42
+ +}
43
+ +
44
+ +/// Direct handle to the connection pool used by [`Client::preconnect`].
45
+ +///
46
+ +/// Preconnecting bypasses the request middleware stack, so the checks that
47
+ +/// stack would apply before a connection is opened are replicated here.
48
+ +struct Preconnector {
49
+ + http: HttpClient<Connector, Body>,
50
+ + https_only: bool,
51
+ + timer: Timer,
52
+ + timeout: RequestConfig<TimeoutOptions>,
53
+ +}
54
+
55
+ /// A [`ClientBuilder`] can be used to create a [`Client`] with custom configuration.
56
+ #[must_use]
57
+ @@ -430,7 +450,67 @@ impl Client {
58
+ let req = http::Request::<Body>::from(request);
59
+ Pending::Request {
60
+ uri: Some(req.uri().clone()),
61
+ - fut: Box::pin(Oneshot::new((*self.0).clone(), req)),
62
+ + fut: Box::pin(Oneshot::new(self.0.service.clone(), req)),
63
+ + }
64
+ + }
65
+ +
66
+ + /// Establishes a connection to the given URI ahead of time, without sending a request.
67
+ + ///
68
+ + /// The TCP connection (plus proxy tunnel and TLS handshake, where applicable) is
69
+ + /// completed and the connection is kept idle in the pool, so that a subsequent
70
+ + /// request to the same origin can reuse it and skip connection setup.
71
+ + ///
72
+ + /// If an idle connection to the origin already exists, it is reused and no new
73
+ + /// connection is opened. The connection is subject to the pool's idle timeout and
74
+ + /// has no effect if pooling is disabled.
75
+ + ///
76
+ + /// Use [`RequestBuilder::preconnect`] to preconnect with per-request options such as
77
+ + /// a proxy or emulation, which must match the options of the later request for the
78
+ + /// connection to be reused.
79
+ + ///
80
+ + /// # Errors
81
+ + ///
82
+ + /// This method fails if the URI is invalid or the connection cannot be established.
83
+ + #[inline]
84
+ + pub fn preconnect<U: IntoUri>(&self, uri: U) -> impl Future<Output = crate::Result<()>> {
85
+ + self.get(uri).preconnect()
86
+ + }
87
+ +
88
+ + pub(crate) fn execute_preconnect(
89
+ + &self,
90
+ + request: Request,
91
+ + ) -> impl Future<Output = crate::Result<()>> + Send + 'static + use<> {
92
+ + let req = http::Request::<Body>::from(request);
93
+ + let client = self.0.clone();
94
+ + async move {
95
+ + let preconnector = &client.preconnector;
96
+ + let uri = req.uri().clone();
97
+ +
98
+ + if !(uri.is_http() || uri.is_https()) || (preconnector.https_only && !uri.is_https()) {
99
+ + return Err(Error::uri_bad_scheme(uri));
100
+ + }
101
+ +
102
+ + let (total_timeout, _) = fetch_timeout_options(&preconnector.timeout, req.extensions());
103
+ + let connect = preconnector.http.preconnect(req);
104
+ + let res = match total_timeout {
105
+ + Some(timeout) => {
106
+ + let sleep = wreq_proto::rt::Timer::sleep(&preconnector.timer, timeout);
107
+ + match futures_util::future::select(connect, sleep).await {
108
+ + futures_util::future::Either::Left((res, _)) => res,
109
+ + futures_util::future::Either::Right(_) => {
110
+ + Err(Error::request(error::TimedOut).into())
111
+ + }
112
+ + }
113
+ + }
114
+ + None => connect.await,
115
+ + };
116
+ +
117
+ + res.map_err(|err| {
118
+ + let err = err
119
+ + .downcast::<Error>()
120
+ + .map_or_else(Error::request, |err| *err);
121
+ + if err.uri().is_none() { err.with_uri(uri) } else { err }
122
+ + })
123
+ }
124
+ }
125
+ }
126
+ @@ -588,6 +668,13 @@ impl ClientBuilder {
127
+ .build(connector)
128
+ };
129
+
130
+ + let preconnector = Preconnector {
131
+ + http: service.clone(),
132
+ + https_only: config.https_only,
133
+ + timer: config.timer.clone(),
134
+ + timeout: RequestConfig::new(Some(config.timeout_options)),
135
+ + };
136
+ +
137
+ // Configured client service with layers
138
+ let client = {
139
+ let service = ServiceBuilder::new()
140
+ @@ -645,7 +732,10 @@ impl ClientBuilder {
141
+ }
142
+ };
143
+
144
+ - Ok(Client(Arc::new(client)))
145
+ + Ok(Client(Arc::new(ClientRef {
146
+ + service: client,
147
+ + preconnector,
148
+ + })))
149
+ }
150
+
151
+ // Higher-level options
152
+ diff --git a/src/client/layer/client.rs b/src/client/layer/client.rs
153
+ index 8b000486..8e5177a2 100644
154
+ --- a/src/client/layer/client.rs
155
+ +++ b/src/client/layer/client.rs
156
+ @@ -145,32 +145,50 @@ where
157
+ B::Data: Send,
158
+ B::Error: Into<BoxError>,
159
+ {
160
+ - fn request(
161
+ - &self,
162
+ - mut req: Request<B>,
163
+ - ) -> BoxFuture<'static, Result<Response<Incoming>, BoxError>> {
164
+ + fn request(&self, mut req: Request<B>) -> BoxFuture<'static, Result<Response<Incoming>, BoxError>> {
165
+ + match self.prepare(&mut req) {
166
+ + Ok((this, descriptor)) => {
167
+ + Box::pin(this.send_request(req, descriptor).map_err(Into::into))
168
+ + }
169
+ + Err(err) => Box::pin(future::err(err.into())),
170
+ + }
171
+ + }
172
+ +
173
+ + /// Establishes (or reuses) a pooled connection for the request's destination
174
+ + /// without sending the request, leaving the connection idle in the pool.
175
+ + ///
176
+ + /// The request is only used to derive the connection descriptor, so per-request
177
+ + /// options (proxy, TLS/emulation, HTTP version, ...) produce the same pool key a
178
+ + /// subsequent real request would use.
179
+ + pub(crate) fn preconnect(&self, mut req: Request<B>) -> BoxFuture<'static, Result<(), BoxError>> {
180
+ + match self.prepare(&mut req) {
181
+ + Ok((this, descriptor)) => Box::pin(async move {
182
+ + // Dropping the pooled connection returns it to the pool as idle.
183
+ + this.connection_for(descriptor).await.map(drop).map_err(Into::into)
184
+ + }),
185
+ + Err(err) => Box::pin(future::err(err.into())),
186
+ + }
187
+ + }
188
+ +
189
+ + #[allow(clippy::result_large_err)]
190
+ + fn prepare(&self, req: &mut Request<B>) -> Result<(Self, ConnectionDescriptor), Error> {
191
+ let is_http_connect = req.method() == Method::CONNECT;
192
+ // Validate HTTP version early
193
+ match req.version() {
194
+ Version::HTTP_10 if is_http_connect => {
195
+ warn!("CONNECT is not allowed for HTTP/1.0");
196
+ - return Box::pin(future::err(e!(UserUnsupportedRequestMethod).into()));
197
+ + return Err(e!(UserUnsupportedRequestMethod));
198
+ }
199
+ Version::HTTP_10 | Version::HTTP_11 | Version::HTTP_2 => {}
200
+ // completely unsupported HTTP version (like HTTP/0.9)!
201
+ _unsupported => {
202
+ warn!("Request has unsupported version: {:?}", _unsupported);
203
+ - return Box::pin(future::err(e!(UserUnsupportedVersion).into()));
204
+ + return Err(e!(UserUnsupportedVersion));
205
+ }
206
+ };
207
+
208
+ // Extract and normalize URI
209
+ - let uri = match normalize_uri(&mut req, is_http_connect) {
210
+ - Ok(uri) => uri,
211
+ - Err(err) => {
212
+ - return Box::pin(future::err(e!(UserAbsoluteUriRequired, err).into()));
213
+ - }
214
+ - };
215
+ + let uri = normalize_uri(req, is_http_connect).map_err(|err| e!(UserAbsoluteUriRequired, err))?;
216
+
217
+ let mut this = self.clone();
218
+
219
+ @@ -196,7 +214,7 @@ where
220
+ ConnectionDescriptor::new(uri, group, proxy, version, tls_options, socket_bind_options)
221
+ };
222
+
223
+ - Box::pin(this.send_request(req, descriptor).map_err(Into::into))
224
+ + Ok((this, descriptor))
225
+ }
226
+
227
+ async fn send_request(
228
+ diff --git a/src/client/layer/timeout.rs b/src/client/layer/timeout.rs
229
+ index b978d75b..0d3f340c 100644
230
+ --- a/src/client/layer/timeout.rs
231
+ +++ b/src/client/layer/timeout.rs
232
+ @@ -105,7 +105,7 @@ where
233
+ }
234
+ }
235
+
236
+ -fn fetch_timeout_options(
237
+ +pub(crate) fn fetch_timeout_options(
238
+ opts: &RequestConfig<TimeoutOptions>,
239
+ extensions: &http::Extensions,
240
+ ) -> (Option<Duration>, Option<Duration>) {
241
+ diff --git a/src/client/request.rs b/src/client/request.rs
242
+ index fe02a938..6a76c3a4 100644
243
+ --- a/src/client/request.rs
244
+ +++ b/src/client/request.rs
245
+ @@ -847,6 +847,21 @@ impl RequestBuilder {
246
+ }
247
+ }
248
+
249
+ + /// Establishes a connection for this request ahead of time, without sending it.
250
+ + ///
251
+ + /// Only connection-level options (such as proxy, emulation/TLS options, HTTP
252
+ + /// version and timeout) are taken into account; the method, headers and body are
253
+ + /// ignored. See [`Client::preconnect`] for details.
254
+ + ///
255
+ + /// # Errors
256
+ + ///
257
+ + /// This method fails if the request is invalid or the connection cannot be
258
+ + /// established.
259
+ + pub fn preconnect(self) -> impl Future<Output = crate::Result<()>> + Send + 'static {
260
+ + let fut = self.request.map(|req| self.client.execute_preconnect(req));
261
+ + async move { fut?.await }
262
+ + }
263
+ +
264
+ /// Attempt to clone the RequestBuilder.
265
+ ///
266
+ /// `None` is returned if the RequestBuilder can not be cloned,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wreq-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.1
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Yicheng Zhou
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2026-08-28 00:00:00.000000000 Z
12
+ date: 2026-11-27 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: An ergonomic Ruby HTTP client powered by Rust's wreq library, featuring
15
15
  TLS fingerprint emulation (JA3/JA4), HTTP/2 support, cookie handling, proxy support,
@@ -25,10 +25,11 @@ files:
25
25
  - exe/wreq
26
26
  - lib/wreq-rb.rb
27
27
  - lib/wreq-rb/version.rb
28
- - lib/wreq_rb/2.7/wreq_rb.so
29
28
  - lib/wreq_rb/3.3/wreq_rb.so
30
29
  - lib/wreq_rb/3.4/wreq_rb.so
30
+ - lib/wreq_rb/4.0/wreq_rb.so
31
31
  - patches/0001-add-transfer-size-tracking.patch
32
+ - patches/0002-add-preconnect.patch
32
33
  - vendor/wreq/LICENSE
33
34
  - vendor/wreq/README.md
34
35
  homepage: https://github.com/serpapi/wreq-rb
@@ -43,10 +44,10 @@ required_ruby_version: !ruby/object:Gem::Requirement
43
44
  requirements:
44
45
  - - ">="
45
46
  - !ruby/object:Gem::Version
46
- version: '2.7'
47
+ version: '3.3'
47
48
  - - "<"
48
49
  - !ruby/object:Gem::Version
49
- version: 3.5.dev
50
+ version: 4.1.dev
50
51
  required_rubygems_version: !ruby/object:Gem::Requirement
51
52
  requirements:
52
53
  - - ">="
Binary file