wreq 1.2.4 → 1.2.5

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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +3 -7
  3. data/Cargo.toml +6 -1
  4. data/crates/wreq-util/.github/FUNDING.yml +15 -0
  5. data/crates/wreq-util/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  6. data/crates/wreq-util/.github/ISSUE_TEMPLATE/custom.md +10 -0
  7. data/crates/wreq-util/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  8. data/crates/wreq-util/.github/dependabot.yml +22 -0
  9. data/crates/wreq-util/.github/workflows/ci.yml +82 -0
  10. data/crates/wreq-util/.github/workflows/release-plz.yml +52 -0
  11. data/crates/wreq-util/.gitignore +24 -0
  12. data/crates/wreq-util/CHANGELOG.md +74 -0
  13. data/crates/wreq-util/Cargo.toml +94 -0
  14. data/crates/wreq-util/LICENSE +201 -0
  15. data/crates/wreq-util/README.md +62 -0
  16. data/crates/wreq-util/examples/emulate.rs +39 -0
  17. data/crates/wreq-util/examples/tower_delay.rs +191 -0
  18. data/crates/wreq-util/release-plz.toml +2 -0
  19. data/crates/wreq-util/rustfmt.toml +5 -0
  20. data/crates/wreq-util/src/emulate/compress.rs +85 -0
  21. data/crates/wreq-util/src/emulate/macros.rs +370 -0
  22. data/crates/wreq-util/src/emulate/profile/chrome/header.rs +59 -0
  23. data/crates/wreq-util/src/emulate/profile/chrome/http2.rs +65 -0
  24. data/crates/wreq-util/src/emulate/profile/chrome/tls.rs +153 -0
  25. data/crates/wreq-util/src/emulate/profile/chrome.rs +2028 -0
  26. data/crates/wreq-util/src/emulate/profile/firefox/header.rs +21 -0
  27. data/crates/wreq-util/src/emulate/profile/firefox/http2.rs +113 -0
  28. data/crates/wreq-util/src/emulate/profile/firefox/tls.rs +253 -0
  29. data/crates/wreq-util/src/emulate/profile/firefox.rs +518 -0
  30. data/crates/wreq-util/src/emulate/profile/okhttp.rs +241 -0
  31. data/crates/wreq-util/src/emulate/profile/opera/header.rs +30 -0
  32. data/crates/wreq-util/src/emulate/profile/opera/http2.rs +50 -0
  33. data/crates/wreq-util/src/emulate/profile/opera/tls.rs +97 -0
  34. data/crates/wreq-util/src/emulate/profile/opera.rs +299 -0
  35. data/crates/wreq-util/src/emulate/profile/safari/header.rs +59 -0
  36. data/crates/wreq-util/src/emulate/profile/safari/http2.rs +116 -0
  37. data/crates/wreq-util/src/emulate/profile/safari/tls.rs +177 -0
  38. data/crates/wreq-util/src/emulate/profile/safari.rs +222 -0
  39. data/crates/wreq-util/src/emulate/profile.rs +47 -0
  40. data/crates/wreq-util/src/emulate.rs +369 -0
  41. data/crates/wreq-util/src/lib.rs +14 -0
  42. data/crates/wreq-util/src/rand.rs +24 -0
  43. data/crates/wreq-util/src/tower/delay/future.rs +43 -0
  44. data/crates/wreq-util/src/tower/delay/layer.rs +201 -0
  45. data/crates/wreq-util/src/tower/delay/service.rs +190 -0
  46. data/crates/wreq-util/src/tower/delay.rs +98 -0
  47. data/crates/wreq-util/src/tower.rs +7 -0
  48. data/crates/wreq-util/tests/client.rs +51 -0
  49. data/crates/wreq-util/tests/emulate_chrome.rs +270 -0
  50. data/crates/wreq-util/tests/emulate_firefox.rs +92 -0
  51. data/crates/wreq-util/tests/emulate_okhttp.rs +46 -0
  52. data/crates/wreq-util/tests/emulate_opera.rs +113 -0
  53. data/crates/wreq-util/tests/emulate_safari.rs +151 -0
  54. data/crates/wreq-util/tests/support/mod.rs +55 -0
  55. data/crates/wreq-util/tests/support/server.rs +232 -0
  56. data/examples/emulate_request.rb +1 -1
  57. data/lib/wreq.rb +20 -18
  58. data/lib/wreq_ruby/body.rb +3 -0
  59. data/lib/wreq_ruby/client.rb +18 -18
  60. data/lib/wreq_ruby/cookie.rb +2 -2
  61. data/lib/wreq_ruby/emulate.rb +3 -1
  62. data/lib/wreq_ruby/header.rb +205 -114
  63. data/lib/wreq_ruby/response.rb +28 -3
  64. data/src/emulate.rs +1 -0
  65. data/src/error.rs +2 -6
  66. data/src/header/helper.rs +112 -0
  67. data/src/header.rs +198 -133
  68. data/test/header_test.rb +228 -192
  69. data/test/stream_test.rb +36 -0
  70. metadata +54 -1
@@ -0,0 +1,55 @@
1
+ #![allow(dead_code)]
2
+ pub mod server;
3
+
4
+ use std::{sync::LazyLock, time::Duration};
5
+
6
+ use tokio::sync::Semaphore;
7
+ use wreq::Client;
8
+
9
+ // TODO: remove once done converting to new support server?
10
+ #[allow(unused)]
11
+ pub static DEFAULT_USER_AGENT: &str =
12
+ concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
13
+
14
+ pub static TEST_SEMAPHORE: LazyLock<Semaphore> = LazyLock::new(|| Semaphore::new(1));
15
+
16
+ pub static CLIENT: LazyLock<Client> = LazyLock::new(|| {
17
+ Client::builder()
18
+ .connect_timeout(Duration::from_secs(60))
19
+ .build()
20
+ .unwrap()
21
+ });
22
+
23
+ #[allow(unused_macros)]
24
+ macro_rules! test_emulation {
25
+ ($test_name:ident, $emulation:expr, $ja4:expr, $akamai_hash:expr) => {
26
+ #[tokio::test]
27
+ async fn $test_name() {
28
+ let _permit = crate::support::TEST_SEMAPHORE.acquire().await.unwrap();
29
+
30
+ let resp = crate::support::CLIENT
31
+ .get("https://tls.browserleaks.com/")
32
+ .emulation($emulation)
33
+ .send()
34
+ .await
35
+ .unwrap();
36
+
37
+ assert_eq!(resp.status(), wreq::StatusCode::OK);
38
+ let content = resp.text().await.unwrap();
39
+
40
+ let conditional = $ja4.iter().any(|&ja4| content.contains(ja4));
41
+ if !conditional {
42
+ println!("{}", content);
43
+ }
44
+ assert!(conditional);
45
+
46
+ let conditional = content.contains($akamai_hash);
47
+ if !conditional {
48
+ println!("{}", content);
49
+ }
50
+ assert!(conditional);
51
+
52
+ tokio::time::sleep(std::time::Duration::from_millis(1000)).await;
53
+ }
54
+ };
55
+ }
@@ -0,0 +1,232 @@
1
+ #![cfg(not(target_arch = "wasm32"))]
2
+ use std::{
3
+ convert::Infallible, future::Future, net, sync::mpsc as std_mpsc, thread, time::Duration,
4
+ };
5
+
6
+ use tokio::{io::AsyncReadExt, net::TcpStream, runtime, sync::oneshot};
7
+
8
+ pub struct Server {
9
+ addr: net::SocketAddr,
10
+ panic_rx: std_mpsc::Receiver<()>,
11
+ events_rx: std_mpsc::Receiver<Event>,
12
+ shutdown_tx: Option<oneshot::Sender<()>>,
13
+ }
14
+
15
+ #[non_exhaustive]
16
+ pub enum Event {
17
+ ConnectionClosed,
18
+ }
19
+
20
+ impl Server {
21
+ pub fn addr(&self) -> net::SocketAddr {
22
+ self.addr
23
+ }
24
+
25
+ #[allow(unused)]
26
+ pub fn events(&mut self) -> Vec<Event> {
27
+ let mut events = Vec::new();
28
+ while let Ok(event) = self.events_rx.try_recv() {
29
+ events.push(event);
30
+ }
31
+ events
32
+ }
33
+ }
34
+
35
+ impl Drop for Server {
36
+ fn drop(&mut self) {
37
+ if let Some(tx) = self.shutdown_tx.take() {
38
+ let _ = tx.send(());
39
+ }
40
+
41
+ if !::std::thread::panicking() {
42
+ self.panic_rx
43
+ .recv_timeout(Duration::from_secs(3))
44
+ .expect("test server should not panic");
45
+ }
46
+ }
47
+ }
48
+
49
+ pub fn http<F, Fut>(func: F) -> Server
50
+ where
51
+ F: Fn(http::Request<hyper::body::Incoming>) -> Fut + Clone + Send + 'static,
52
+ Fut: Future<Output = http::Response<wreq::Body>> + Send + 'static,
53
+ {
54
+ http_with_config(func, |_builder| {})
55
+ }
56
+
57
+ type Builder = hyper_util::server::conn::auto::Builder<hyper_util::rt::TokioExecutor>;
58
+
59
+ pub fn http_with_config<F1, Fut, F2, Bu>(func: F1, apply_config: F2) -> Server
60
+ where
61
+ F1: Fn(http::Request<hyper::body::Incoming>) -> Fut + Clone + Send + 'static,
62
+ Fut: Future<Output = http::Response<wreq::Body>> + Send + 'static,
63
+ F2: FnOnce(&mut Builder) -> Bu + Send + 'static,
64
+ {
65
+ // Spawn new runtime in thread to prevent reactor execution context conflict
66
+ let test_name = thread::current().name().unwrap_or("<unknown>").to_string();
67
+ thread::spawn(move || {
68
+ let rt = runtime::Builder::new_current_thread()
69
+ .enable_all()
70
+ .build()
71
+ .expect("new rt");
72
+ let listener = rt.block_on(async move {
73
+ tokio::net::TcpListener::bind(&std::net::SocketAddr::from(([127, 0, 0, 1], 0)))
74
+ .await
75
+ .unwrap()
76
+ });
77
+ let addr = listener.local_addr().unwrap();
78
+
79
+ let (shutdown_tx, mut shutdown_rx) = oneshot::channel();
80
+ let (panic_tx, panic_rx) = std_mpsc::channel();
81
+ let (events_tx, events_rx) = std_mpsc::channel();
82
+ let tname = format!(
83
+ "test({})-support-server",
84
+ test_name,
85
+ );
86
+ thread::Builder::new()
87
+ .name(tname)
88
+ .spawn(move || {
89
+ rt.block_on(async move {
90
+ let mut builder =
91
+ hyper_util::server::conn::auto::Builder::new(hyper_util::rt::TokioExecutor::new());
92
+ apply_config(&mut builder);
93
+
94
+ loop {
95
+ tokio::select! {
96
+ _ = &mut shutdown_rx => {
97
+ break;
98
+ }
99
+ accepted = listener.accept() => {
100
+ let (io, _) = accepted.expect("accepted");
101
+ let func = func.clone();
102
+ let svc = hyper::service::service_fn(move |req| {
103
+ let fut = func(req);
104
+ async move { Ok::<_, Infallible>(fut.await) }
105
+ });
106
+ let builder = builder.clone();
107
+ let events_tx = events_tx.clone();
108
+ tokio::spawn(async move {
109
+ let _ = builder.serve_connection_with_upgrades(hyper_util::rt::TokioIo::new(io), svc).await;
110
+ let _ = events_tx.send(Event::ConnectionClosed);
111
+ });
112
+ }
113
+ }
114
+ }
115
+ let _ = panic_tx.send(());
116
+ });
117
+ })
118
+ .expect("thread spawn");
119
+ Server {
120
+ addr,
121
+ panic_rx,
122
+ events_rx,
123
+ shutdown_tx: Some(shutdown_tx),
124
+ }
125
+ })
126
+ .join()
127
+ .unwrap()
128
+ }
129
+
130
+ #[allow(unused)]
131
+ pub fn low_level_with_response<F>(do_response: F) -> Server
132
+ where
133
+ for<'c> F: Fn(&'c [u8], &'c mut TcpStream) -> Box<dyn Future<Output = ()> + Send + 'c>
134
+ + Clone
135
+ + Send
136
+ + 'static,
137
+ {
138
+ // Spawn new runtime in thread to prevent reactor execution context conflict
139
+ let test_name = thread::current().name().unwrap_or("<unknown>").to_string();
140
+ thread::spawn(move || {
141
+ let rt = runtime::Builder::new_current_thread()
142
+ .enable_all()
143
+ .build()
144
+ .expect("new rt");
145
+ let listener = rt.block_on(async move {
146
+ tokio::net::TcpListener::bind(&std::net::SocketAddr::from(([127, 0, 0, 1], 0)))
147
+ .await
148
+ .unwrap()
149
+ });
150
+ let addr = listener.local_addr().unwrap();
151
+
152
+ let (shutdown_tx, mut shutdown_rx) = oneshot::channel();
153
+ let (panic_tx, panic_rx) = std_mpsc::channel();
154
+ let (events_tx, events_rx) = std_mpsc::channel();
155
+ let tname = format!("test({})-support-server", test_name,);
156
+ thread::Builder::new()
157
+ .name(tname)
158
+ .spawn(move || {
159
+ rt.block_on(async move {
160
+ loop {
161
+ tokio::select! {
162
+ _ = &mut shutdown_rx => {
163
+ break;
164
+ }
165
+ accepted = listener.accept() => {
166
+ let (io, _) = accepted.expect("accepted");
167
+ let do_response = do_response.clone();
168
+ let events_tx = events_tx.clone();
169
+ tokio::spawn(async move {
170
+ low_level_server_client(io, do_response).await;
171
+ let _ = events_tx.send(Event::ConnectionClosed);
172
+ });
173
+ }
174
+ }
175
+ }
176
+ let _ = panic_tx.send(());
177
+ });
178
+ })
179
+ .expect("thread spawn");
180
+ Server {
181
+ addr,
182
+ panic_rx,
183
+ events_rx,
184
+ shutdown_tx: Some(shutdown_tx),
185
+ }
186
+ })
187
+ .join()
188
+ .unwrap()
189
+ }
190
+
191
+ #[allow(unused)]
192
+ async fn low_level_server_client<F>(mut client_socket: TcpStream, do_response: F)
193
+ where
194
+ for<'c> F: Fn(&'c [u8], &'c mut TcpStream) -> Box<dyn Future<Output = ()> + Send + 'c>,
195
+ {
196
+ loop {
197
+ let request = low_level_read_http_request(&mut client_socket)
198
+ .await
199
+ .expect("read_http_request failed");
200
+ if request.is_empty() {
201
+ // connection closed by client
202
+ break;
203
+ }
204
+
205
+ Box::into_pin(do_response(&request, &mut client_socket)).await;
206
+ }
207
+ }
208
+
209
+ #[allow(unused)]
210
+ async fn low_level_read_http_request(
211
+ client_socket: &mut TcpStream,
212
+ ) -> core::result::Result<Vec<u8>, std::io::Error> {
213
+ let mut buf = Vec::new();
214
+
215
+ // Read until the delimiter "\r\n\r\n" is found
216
+ loop {
217
+ let mut temp_buffer = [0; 1024];
218
+ let n = client_socket.read(&mut temp_buffer).await?;
219
+
220
+ if n == 0 {
221
+ break;
222
+ }
223
+
224
+ buf.extend_from_slice(&temp_buffer[..n]);
225
+
226
+ if let Some(pos) = buf.windows(4).position(|window| window == b"\r\n\r\n") {
227
+ return Ok(buf.drain(..pos + 4).collect());
228
+ }
229
+ }
230
+
231
+ Ok(buf)
232
+ }
@@ -11,7 +11,7 @@ require_relative "../lib/wreq"
11
11
  # Set when creating the Wreq::Client instance.
12
12
  # All requests from this client will use the specified emulation unless overridden.
13
13
  client = Wreq::Client.new(emulation: Wreq::Emulation.new(
14
- profile: Wreq::Profile::Chrome149,
14
+ profile: Wreq::Profile::Chrome150,
15
15
  platform: Wreq::Platform::MacOS,
16
16
  http2: true,
17
17
  headers: true
data/lib/wreq.rb CHANGED
@@ -18,6 +18,8 @@ require_relative "wreq_ruby/cookie"
18
18
 
19
19
  unless defined?(Wreq)
20
20
  module Wreq
21
+ # Current wreq gem version.
22
+ # @return [String]
21
23
  VERSION = nil
22
24
 
23
25
  # Send an HTTP request.
@@ -26,7 +28,7 @@ unless defined?(Wreq)
26
28
  # @param url [String] Target URL
27
29
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
28
30
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
29
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
31
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
30
32
  # @param query [Hash, nil] URL query parameters
31
33
  # @param auth [String, nil] Authorization header value
32
34
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -47,7 +49,7 @@ unless defined?(Wreq)
47
49
  # @param version [Wreq::Version, nil] HTTP version to use
48
50
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
49
51
  # @param json [Object, nil] JSON body (will be serialized)
50
- # @param body [String, IO, nil] Raw request body (string or stream)
52
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
51
53
  # @return [Wreq::Response] HTTP response
52
54
  def self.request(method, url, **options)
53
55
  end
@@ -57,7 +59,7 @@ unless defined?(Wreq)
57
59
  # @param url [String] Target URL
58
60
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
59
61
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
60
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
62
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
61
63
  # @param query [Hash, nil] URL query parameters
62
64
  # @param auth [String, nil] Authorization header value
63
65
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -78,7 +80,7 @@ unless defined?(Wreq)
78
80
  # @param version [Wreq::Version, nil] HTTP version to use
79
81
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
80
82
  # @param json [Object, nil] JSON body (will be serialized)
81
- # @param body [String, IO, nil] Raw request body (string or stream)
83
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
82
84
  # @return [Wreq::Response] HTTP response
83
85
  def self.get(url, **options)
84
86
  end
@@ -88,7 +90,7 @@ unless defined?(Wreq)
88
90
  # @param url [String] Target URL
89
91
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
90
92
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
91
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
93
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
92
94
  # @param query [Hash, nil] URL query parameters
93
95
  # @param auth [String, nil] Authorization header value
94
96
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -109,7 +111,7 @@ unless defined?(Wreq)
109
111
  # @param version [Wreq::Version, nil] HTTP version to use
110
112
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
111
113
  # @param json [Object, nil] JSON body (will be serialized)
112
- # @param body [String, IO, nil] Raw request body (string or stream)
114
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
113
115
  # @return [Wreq::Response] HTTP response
114
116
  def self.head(url, **options)
115
117
  end
@@ -119,7 +121,7 @@ unless defined?(Wreq)
119
121
  # @param url [String] Target URL
120
122
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
121
123
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
122
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
124
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
123
125
  # @param query [Hash, nil] URL query parameters
124
126
  # @param auth [String, nil] Authorization header value
125
127
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -140,7 +142,7 @@ unless defined?(Wreq)
140
142
  # @param version [Wreq::Version, nil] HTTP version to use
141
143
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
142
144
  # @param json [Object, nil] JSON body (will be serialized)
143
- # @param body [String, IO, nil] Raw request body (string or stream)
145
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
144
146
  # @return [Wreq::Response] HTTP response
145
147
  def self.post(url, **options)
146
148
  end
@@ -150,7 +152,7 @@ unless defined?(Wreq)
150
152
  # @param url [String] Target URL
151
153
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
152
154
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
153
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
155
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
154
156
  # @param query [Hash, nil] URL query parameters
155
157
  # @param auth [String, nil] Authorization header value
156
158
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -171,7 +173,7 @@ unless defined?(Wreq)
171
173
  # @param version [Wreq::Version, nil] HTTP version to use
172
174
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
173
175
  # @param json [Object, nil] JSON body (will be serialized)
174
- # @param body [String, IO, nil] Raw request body (string or stream)
176
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
175
177
  # @return [Wreq::Response] HTTP response
176
178
  def self.put(url, **options)
177
179
  end
@@ -181,7 +183,7 @@ unless defined?(Wreq)
181
183
  # @param url [String] Target URL
182
184
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
183
185
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
184
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
186
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
185
187
  # @param query [Hash, nil] URL query parameters
186
188
  # @param auth [String, nil] Authorization header value
187
189
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -202,7 +204,7 @@ unless defined?(Wreq)
202
204
  # @param version [Wreq::Version, nil] HTTP version to use
203
205
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
204
206
  # @param json [Object, nil] JSON body (will be serialized)
205
- # @param body [String, IO, nil] Raw request body (string or stream)
207
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
206
208
  # @return [Wreq::Response] HTTP response
207
209
  def self.delete(url, **options)
208
210
  end
@@ -212,7 +214,7 @@ unless defined?(Wreq)
212
214
  # @param url [String] Target URL
213
215
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
214
216
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
215
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
217
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
216
218
  # @param query [Hash, nil] URL query parameters
217
219
  # @param auth [String, nil] Authorization header value
218
220
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -233,7 +235,7 @@ unless defined?(Wreq)
233
235
  # @param version [Wreq::Version, nil] HTTP version to use
234
236
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
235
237
  # @param json [Object, nil] JSON body (will be serialized)
236
- # @param body [String, IO, nil] Raw request body (string or stream)
238
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
237
239
  # @return [Wreq::Response] HTTP response
238
240
  def self.options(url, **options)
239
241
  end
@@ -243,7 +245,7 @@ unless defined?(Wreq)
243
245
  # @param url [String] Target URL
244
246
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
245
247
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
246
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
248
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
247
249
  # @param query [Hash, nil] URL query parameters
248
250
  # @param auth [String, nil] Authorization header value
249
251
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -264,7 +266,7 @@ unless defined?(Wreq)
264
266
  # @param version [Wreq::Version, nil] HTTP version to use
265
267
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
266
268
  # @param json [Object, nil] JSON body (will be serialized)
267
- # @param body [String, IO, nil] Raw request body (string or stream)
269
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
268
270
  # @return [Wreq::Response] HTTP response
269
271
  def self.trace(url, **options)
270
272
  end
@@ -274,7 +276,7 @@ unless defined?(Wreq)
274
276
  # @param url [String] Target URL
275
277
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
276
278
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
277
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
279
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
278
280
  # @param query [Hash, nil] URL query parameters
279
281
  # @param auth [String, nil] Authorization header value
280
282
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -295,7 +297,7 @@ unless defined?(Wreq)
295
297
  # @param version [Wreq::Version, nil] HTTP version to use
296
298
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
297
299
  # @param json [Object, nil] JSON body (will be serialized)
298
- # @param body [String, IO, nil] Raw request body (string or stream)
300
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
299
301
  # @return [Wreq::Response] HTTP response
300
302
  def self.patch(url, **options)
301
303
  end
@@ -21,14 +21,17 @@ unless defined?(Wreq)
21
21
  # after being consumed by a request, further push or reuse is not allowed.
22
22
  class BodySender
23
23
  # @param capacity [Integer] channel buffer size, default 8
24
+ # @return [Wreq::BodySender] A streaming request body sender
24
25
  def self.new(capacity = 8)
25
26
  end
26
27
 
27
28
  # @param data [String] binary chunk
29
+ # @return [void]
28
30
  def push(data)
29
31
  end
30
32
 
31
33
  # Close the sender, signaling end of data.
34
+ # @return [void]
32
35
  def close
33
36
  end
34
37
  end
@@ -240,7 +240,7 @@ unless defined?(Wreq)
240
240
  # @param url [String] Target URL
241
241
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
242
242
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
243
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
243
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
244
244
  # @param query [Hash, nil] URL query parameters
245
245
  # @param auth [String, nil] Authorization header value
246
246
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -261,7 +261,7 @@ unless defined?(Wreq)
261
261
  # @param version [Wreq::Version, nil] HTTP version to use
262
262
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
263
263
  # @param json [Object, nil] JSON body (will be serialized)
264
- # @param body [String, IO, nil] Raw request body (string or stream)
264
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
265
265
  # @return [Wreq::Response] HTTP response
266
266
  def request(method, url, **options)
267
267
  end
@@ -271,7 +271,7 @@ unless defined?(Wreq)
271
271
  # @param url [String] Target URL
272
272
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
273
273
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
274
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
274
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
275
275
  # @param query [Hash, nil] URL query parameters
276
276
  # @param auth [String, nil] Authorization header value
277
277
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -292,7 +292,7 @@ unless defined?(Wreq)
292
292
  # @param version [Wreq::Version, nil] HTTP version to use
293
293
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
294
294
  # @param json [Object, nil] JSON body (will be serialized)
295
- # @param body [String, IO, nil] Raw request body (string or stream)
295
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
296
296
  # @return [Wreq::Response] HTTP response
297
297
  def get(url, **options)
298
298
  end
@@ -302,7 +302,7 @@ unless defined?(Wreq)
302
302
  # @param url [String] Target URL
303
303
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
304
304
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
305
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
305
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
306
306
  # @param query [Hash, nil] URL query parameters
307
307
  # @param auth [String, nil] Authorization header value
308
308
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -323,7 +323,7 @@ unless defined?(Wreq)
323
323
  # @param version [Wreq::Version, nil] HTTP version to use
324
324
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
325
325
  # @param json [Object, nil] JSON body (will be serialized)
326
- # @param body [String, IO, nil] Raw request body (string or stream)
326
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
327
327
  # @return [Wreq::Response] HTTP response
328
328
  def head(url, **options)
329
329
  end
@@ -333,7 +333,7 @@ unless defined?(Wreq)
333
333
  # @param url [String] Target URL
334
334
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
335
335
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
336
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
336
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
337
337
  # @param query [Hash, nil] URL query parameters
338
338
  # @param auth [String, nil] Authorization header value
339
339
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -354,7 +354,7 @@ unless defined?(Wreq)
354
354
  # @param version [Wreq::Version, nil] HTTP version to use
355
355
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
356
356
  # @param json [Object, nil] JSON body (will be serialized)
357
- # @param body [String, IO, nil] Raw request body (string or stream)
357
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
358
358
  # @return [Wreq::Response] HTTP response
359
359
  def post(url, **options)
360
360
  end
@@ -364,7 +364,7 @@ unless defined?(Wreq)
364
364
  # @param url [String] Target URL
365
365
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
366
366
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
367
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
367
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
368
368
  # @param query [Hash, nil] URL query parameters
369
369
  # @param auth [String, nil] Authorization header value
370
370
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -385,7 +385,7 @@ unless defined?(Wreq)
385
385
  # @param version [Wreq::Version, nil] HTTP version to use
386
386
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
387
387
  # @param json [Object, nil] JSON body (will be serialized)
388
- # @param body [String, IO, nil] Raw request body (string or stream)
388
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
389
389
  # @return [Wreq::Response] HTTP response
390
390
  def put(url, **options)
391
391
  end
@@ -395,7 +395,7 @@ unless defined?(Wreq)
395
395
  # @param url [String] Target URL
396
396
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
397
397
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
398
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
398
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
399
399
  # @param query [Hash, nil] URL query parameters
400
400
  # @param auth [String, nil] Authorization header value
401
401
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -416,7 +416,7 @@ unless defined?(Wreq)
416
416
  # @param version [Wreq::Version, nil] HTTP version to use
417
417
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
418
418
  # @param json [Object, nil] JSON body (will be serialized)
419
- # @param body [String, IO, nil] Raw request body (string or stream)
419
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
420
420
  # @return [Wreq::Response] HTTP response
421
421
  def delete(url, **options)
422
422
  end
@@ -426,7 +426,7 @@ unless defined?(Wreq)
426
426
  # @param url [String] Target URL
427
427
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
428
428
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
429
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
429
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
430
430
  # @param query [Hash, nil] URL query parameters
431
431
  # @param auth [String, nil] Authorization header value
432
432
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -447,7 +447,7 @@ unless defined?(Wreq)
447
447
  # @param version [Wreq::Version, nil] HTTP version to use
448
448
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
449
449
  # @param json [Object, nil] JSON body (will be serialized)
450
- # @param body [String, IO, nil] Raw request body (string or stream)
450
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
451
451
  # @return [Wreq::Response] HTTP response
452
452
  def options(url, **options)
453
453
  end
@@ -457,7 +457,7 @@ unless defined?(Wreq)
457
457
  # @param url [String] Target URL
458
458
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
459
459
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
460
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
460
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
461
461
  # @param query [Hash, nil] URL query parameters
462
462
  # @param auth [String, nil] Authorization header value
463
463
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -478,7 +478,7 @@ unless defined?(Wreq)
478
478
  # @param version [Wreq::Version, nil] HTTP version to use
479
479
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
480
480
  # @param json [Object, nil] JSON body (will be serialized)
481
- # @param body [String, IO, nil] Raw request body (string or stream)
481
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
482
482
  # @return [Wreq::Response] HTTP response
483
483
  def trace(url, **options)
484
484
  end
@@ -488,7 +488,7 @@ unless defined?(Wreq)
488
488
  # @param url [String] Target URL
489
489
  # @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
490
490
  # @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
491
- # @param default_headers [Hash{String=>String}, nil] Default headers to merge
491
+ # @param default_headers [Boolean, nil] Whether to apply default emulation headers
492
492
  # @param query [Hash, nil] URL query parameters
493
493
  # @param auth [String, nil] Authorization header value
494
494
  # @param bearer_auth [String, nil] Bearer token for Authorization header
@@ -509,7 +509,7 @@ unless defined?(Wreq)
509
509
  # @param version [Wreq::Version, nil] HTTP version to use
510
510
  # @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
511
511
  # @param json [Object, nil] JSON body (will be serialized)
512
- # @param body [String, IO, nil] Raw request body (string or stream)
512
+ # @param body [String, Wreq::BodySender, nil] Request body bytes or streaming body sender
513
513
  # @return [Wreq::Response] HTTP response
514
514
  def patch(url, **options)
515
515
  end
@@ -4,9 +4,9 @@ unless defined?(Wreq)
4
4
  #
5
5
  # Values follow the Rust enum exposed by the native extension.
6
6
  class SameSite
7
- # Lax same-site policy.
8
- Strict = nil
9
7
  # Strict same-site policy.
8
+ Strict = nil
9
+ # Lax same-site policy.
10
10
  Lax = nil
11
11
  # None same-site policy.
12
12
  None = nil