wreq-rb 0.4.0-aarch64-linux → 0.5.0-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: f120dd910385609c611944ca7d93171058bba1ea8ba4a16e95dd1d77a5f5e9e3
4
- data.tar.gz: 040bf96d8addb498772fce92f7267233f03d87aeabaf60723efd8f01dfb714f4
3
+ metadata.gz: ece22ccedbf255b890a3a7999ad5eed2ab4a7a8574b533e2b71cf2164bfd89e1
4
+ data.tar.gz: 736c338202b6fa4ff0dfaee437348941f841e2903182da23d621ddefa3681b61
5
5
  SHA512:
6
- metadata.gz: 7fe68f42eeef23d296f15492036b2e13ae9f2c05c107f2a8d208da1e576bb35c79d0f048f41c81037505fb098816b5b1e4656d70621ca3349a588d1b75149784
7
- data.tar.gz: dd6d4cbf5c65c03f7835431414d0c933a6fa0ab356951e5f59c1b288abe5b6058c4f2f3ec05fb66a9ad008bf77d406a64a52428221921c39c0309bd31e9a1fed
6
+ metadata.gz: 7c1f15b01a70a35c7f35d0b1219111471e066ece8f894c1e522741c97af2447f11416bebf59f6fa34932b8b8033d2635ccc783951bb527d4526c7d65f860310d
7
+ data.tar.gz: bd845b5191cb8b68564bab0c1dff30c47c62ec521cb271fd8c7ca922a6c6368634c6b1781a277ec37b9d7a0a4634ad2dc022ad557e6442f8852efc7aaeb0232c
data/README.md CHANGED
@@ -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 abort all in-flight requests and close their underlying connections 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 return with "request interrupted" error
128
+ ```
129
+
103
130
  ### Per-Request Options
104
131
 
105
132
  Pass an options hash as the second argument to any HTTP method:
@@ -128,7 +155,7 @@ resp = Wreq.get("https://tls.peet.ws/api/all")
128
155
 
129
156
  # Explicit browser emulation
130
157
  client = Wreq::Client.new(emulation: "firefox_146")
131
- client = Wreq::Client.new(emulation: "safari_18_5")
158
+ client = Wreq::Client.new(emulation: "safari_18.5")
132
159
  client = Wreq::Client.new(emulation: "edge_142")
133
160
 
134
161
  # Disable emulation entirely
@@ -142,7 +169,7 @@ client = Wreq::Client.new(emulation: "chrome_145", emulation_os: "linux")
142
169
  client = Wreq::Client.new(emulation: "chrome_143", user_agent: "MyBot/1.0")
143
170
 
144
171
  # Per-request emulation override
145
- resp = client.get("https://example.com", emulation: "safari_26_2")
172
+ resp = client.get("https://example.com", emulation: "safari_26.2")
146
173
  ```
147
174
 
148
175
  ### Supported Browsers
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wreq
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
Binary file
Binary file
Binary file
@@ -0,0 +1,181 @@
1
+ diff --git a/src/client/http.rs b/src/client/http.rs
2
+ index 462c77d0..6231e700 100644
3
+ --- a/src/client/http.rs
4
+ +++ b/src/client/http.rs
5
+ @@ -171,6 +171,7 @@ type ClientRef = Either<ClientService, BoxedClientService>;
6
+ #[derive(Clone)]
7
+ pub struct Client {
8
+ inner: Arc<ClientRef>,
9
+ + cancel_connections: Arc<dyn Fn() + Send + Sync>,
10
+ }
11
+
12
+ /// A [`ClientBuilder`] can be used to create a [`Client`] with custom configuration.
13
+ @@ -439,6 +440,14 @@ impl Client {
14
+ let fut = Oneshot::new(self.inner.as_ref().clone(), req);
15
+ Pending::request(uri, fut)
16
+ }
17
+ +
18
+ + /// Cancel all background connection tasks immediately.
19
+ + ///
20
+ + /// This force-drops every tracked H1/H2 connection task, causing the
21
+ + /// underlying TCP socket to close abruptly.
22
+ + pub fn cancel_connections(&self) {
23
+ + (self.cancel_connections)()
24
+ + }
25
+ }
26
+
27
+ impl tower::Service<Request> for Client {
28
+ @@ -495,7 +504,7 @@ impl ClientBuilder {
29
+ }
30
+
31
+ // Create base client service
32
+ - let service = {
33
+ + let (service, cancel_connections) = {
34
+ let (tls_options, http1_options, http2_options) = config.transport_options.into();
35
+
36
+ let resolver = {
37
+ @@ -555,7 +564,7 @@ impl ClientBuilder {
38
+ .build(config.connector_layers)?;
39
+
40
+ // Build client
41
+ - HttpClient::builder(TokioExecutor::new())
42
+ + let http_client = HttpClient::builder(TokioExecutor::new())
43
+ .http1_options(http1_options)
44
+ .http2_options(http2_options)
45
+ .http2_only(matches!(config.http_version_pref, HttpVersionPref::Http2))
46
+ @@ -564,8 +573,10 @@ impl ClientBuilder {
47
+ .pool_idle_timeout(config.pool_idle_timeout)
48
+ .pool_max_idle_per_host(config.pool_max_idle_per_host)
49
+ .pool_max_size(config.pool_max_size)
50
+ - .build(connector)
51
+ - .map_err(Into::into as _)
52
+ + .build(connector);
53
+ + // Capture abort fn before tower layers consume the client
54
+ + let cancel_connections = http_client.cancel_connections_fn();
55
+ + (http_client.map_err(Into::into as _), cancel_connections)
56
+ };
57
+
58
+ // Configured client service with layers
59
+ @@ -633,6 +644,7 @@ impl ClientBuilder {
60
+
61
+ Ok(Client {
62
+ inner: Arc::new(client),
63
+ + cancel_connections,
64
+ })
65
+ }
66
+
67
+ diff --git a/src/client/http/client.rs b/src/client/http/client.rs
68
+ index a29c52dd..7f6ce68f 100644
69
+ --- a/src/client/http/client.rs
70
+ +++ b/src/client/http/client.rs
71
+ @@ -10,7 +10,7 @@ use std::{
72
+ future::Future,
73
+ num::NonZeroU32,
74
+ pin::Pin,
75
+ - sync::Arc,
76
+ + sync::{Arc, Mutex},
77
+ task::{self, Poll},
78
+ time::Duration,
79
+ };
80
+ @@ -119,6 +119,7 @@ pub struct HttpClient<C, B> {
81
+ h1_builder: conn::http1::Builder,
82
+ h2_builder: conn::http2::Builder<Exec>,
83
+ pool: pool::Pool<PoolClient<B>, ConnectIdentity>,
84
+ + conn_abort_handles: Arc<Mutex<Vec<tokio::task::AbortHandle>>>,
85
+ }
86
+
87
+ #[derive(Clone, Copy)]
88
+ @@ -452,8 +453,8 @@ where
89
+ + Send
90
+ + Unpin
91
+ + 'static {
92
+ - let executor = self.exec.clone();
93
+ let pool = self.pool.clone();
94
+ + let conn_abort_handles = self.conn_abort_handles.clone();
95
+
96
+ let h1_builder = self.h1_builder.clone();
97
+ let h2_builder = self.h2_builder.clone();
98
+ @@ -513,10 +514,17 @@ where
99
+ trace!(
100
+ "http2 handshake complete, spawning background dispatcher task"
101
+ );
102
+ - executor.execute(
103
+ - conn.map_err(|_e| debug!("client connection error: {}", _e))
104
+ - .map(|_| ()),
105
+ - );
106
+ + let h2_conn_future = conn
107
+ + .map_err(|_e| debug!("client connection error: {}", _e))
108
+ + .map(|_| ());
109
+ + let abort_handle = tokio::spawn(h2_conn_future).abort_handle();
110
+ + {
111
+ + let mut handles = conn_abort_handles.lock().unwrap_or_else(|e| e.into_inner());
112
+ + if handles.len() >= 64 {
113
+ + handles.retain(|h| !h.is_finished());
114
+ + }
115
+ + handles.push(abort_handle);
116
+ + }
117
+
118
+ // Wait for 'conn' to ready up before we
119
+ // declare this tx as usable
120
+ @@ -544,8 +552,7 @@ where
121
+ // Spawn the connection task in the background using the executor.
122
+ // The task manages the HTTP/1.1 connection, including upgrades (e.g., WebSocket).
123
+ // Errors are sent via err_tx to ensure they can be checked if the sender (tx) fails.
124
+ - executor.execute(
125
+ - conn.with_upgrades()
126
+ + let h1_conn_future = conn.with_upgrades()
127
+ .map_err(|e| {
128
+ // Log the connection error at debug level for diagnostic purposes.
129
+ debug!("client connection error: {:?}", e);
130
+ @@ -555,8 +562,15 @@ where
131
+ // (e.g., if the receiver is dropped, which is handled later).
132
+ let _ = err_tx.send(e);
133
+ })
134
+ - .map(|_| ()),
135
+ - );
136
+ + .map(|_| ());
137
+ + let abort_handle = tokio::spawn(h1_conn_future).abort_handle();
138
+ + {
139
+ + let mut handles = conn_abort_handles.lock().unwrap_or_else(|e| e.into_inner());
140
+ + if handles.len() >= 64 {
141
+ + handles.retain(|h| !h.is_finished());
142
+ + }
143
+ + handles.push(abort_handle);
144
+ + }
145
+
146
+ // Log that the client is waiting for the connection to be ready.
147
+ // Readiness indicates the sender (tx) can accept a request without blocking. More actions
148
+ @@ -682,10 +696,25 @@ impl<C: Clone, B> Clone for HttpClient<C, B> {
149
+ h2_builder: self.h2_builder.clone(),
150
+ connector: self.connector.clone(),
151
+ pool: self.pool.clone(),
152
+ + conn_abort_handles: self.conn_abort_handles.clone(),
153
+ }
154
+ }
155
+ }
156
+
157
+ +impl<C, B> HttpClient<C, B> {
158
+ + /// Returns a closure that cancels all tracked connection tasks when called.
159
+ + /// Each call drains the handle list and aborts every stored task.
160
+ + pub fn cancel_connections_fn(&self) -> Arc<dyn Fn() + Send + Sync + 'static> {
161
+ + let handles = self.conn_abort_handles.clone();
162
+ + Arc::new(move || {
163
+ + let mut guard = handles.lock().unwrap_or_else(|e| e.into_inner());
164
+ + for handle in guard.drain(..) {
165
+ + handle.abort();
166
+ + }
167
+ + })
168
+ + }
169
+ +}
170
+ +
171
+ /// A pooled HTTP connection that can send requests
172
+ struct PoolClient<B> {
173
+ conn_info: Connected,
174
+ @@ -998,6 +1027,7 @@ impl Builder {
175
+ h2_builder: self.h2_builder,
176
+ connector,
177
+ pool: pool::Pool::new(self.pool_config, exec, timer),
178
+ + conn_abort_handles: Arc::new(Mutex::new(Vec::new())),
179
+ }
180
+ }
181
+ }
metadata CHANGED
@@ -1,31 +1,34 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wreq-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Yicheng Zhou
8
8
  - Illia Zub
9
9
  autorequire:
10
- bindir: bin
10
+ bindir: exe
11
11
  cert_chain: []
12
- date: 2026-03-02 00:00:00.000000000 Z
12
+ date: 2026-03-17 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,
16
16
  and redirect policies.
17
17
  email:
18
- executables: []
18
+ executables:
19
+ - wreq
19
20
  extensions: []
20
21
  extra_rdoc_files: []
21
22
  files:
22
23
  - README.md
24
+ - exe/wreq
23
25
  - lib/wreq-rb.rb
24
26
  - lib/wreq-rb/version.rb
25
27
  - lib/wreq_rb/2.7/wreq_rb.so
26
28
  - lib/wreq_rb/3.3/wreq_rb.so
27
29
  - lib/wreq_rb/3.4/wreq_rb.so
28
30
  - patches/0001-add-transfer-size-tracking.patch
31
+ - patches/0002-add-cancel-connections.patch
29
32
  - vendor/wreq/LICENSE
30
33
  - vendor/wreq/README.md
31
34
  homepage: https://github.com/serpapi/wreq-rb