Skip to content

Commit ecc8a2b

Browse files
darkprokobaAndrey Petrov
and
Andrey Petrov
authored
Exposed the CURLOPT_UPLOAD_BUFFERSIZE curl option. (#411)
* Exposed the CURLOPT_UPLOAD_BUFFERSIZE curl option. See also: https://curl.se/libcurl/c/CURLOPT_UPLOAD_BUFFERSIZE.html * [trivial] Fixed a typo. * [trivial] Only test the upload_buffer_size(...) API if the system's libcurl is 7.62.0 or later. * An attempt to fix CI by conditionally checking the constant CURLOPT_UPLOAD_BUFFERSIZE. Co-authored-by: Andrey Petrov <[email protected]>
1 parent b0b6c68 commit ecc8a2b

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

curl-sys/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,8 @@ pub const CURLOPT_PROXY_CAPATH: CURLoption = CURLOPTTYPE_OBJECTPOINT + 247;
595595
pub const CURLOPT_PROXY_SSLCERT: CURLoption = CURLOPTTYPE_OBJECTPOINT + 254;
596596
pub const CURLOPT_PROXY_SSLKEY: CURLoption = CURLOPTTYPE_OBJECTPOINT + 256;
597597

598+
pub const CURLOPT_UPLOAD_BUFFERSIZE: CURLoption = CURLOPTTYPE_LONG + 280;
599+
598600
pub const CURLOPT_MAXAGE_CONN: CURLoption = CURLOPTTYPE_LONG + 288;
599601

600602
pub const CURLOPT_SSLCERT_BLOB: CURLoption = CURLOPTTYPE_BLOB + 291;

src/easy/handle.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,11 @@ impl Easy {
653653
self.inner.buffer_size(size)
654654
}
655655

656+
/// Same as [`Easy2::upload_buffer_size`](struct.Easy2.html#method.upload_buffer_size)
657+
pub fn upload_buffer_size(&mut self, size: usize) -> Result<(), Error> {
658+
self.inner.upload_buffer_size(size)
659+
}
660+
656661
/// Same as [`Easy2::tcp_nodelay`](struct.Easy2.html#method.tcp_nodelay)
657662
pub fn tcp_nodelay(&mut self, enable: bool) -> Result<(), Error> {
658663
self.inner.tcp_nodelay(enable)

src/easy/handler.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,17 @@ impl<H> Easy2<H> {
10611061
self.setopt_long(curl_sys::CURLOPT_BUFFERSIZE, size as c_long)
10621062
}
10631063

1064+
/// Specify the preferred send buffer size, in bytes.
1065+
///
1066+
/// This is treated as a request, not an order, and the main point of this
1067+
/// is that the read callback may get called more often with smaller
1068+
/// chunks.
1069+
///
1070+
/// The upload buffer size is by default 64 kilobytes.
1071+
pub fn upload_buffer_size(&mut self, size: usize) -> Result<(), Error> {
1072+
self.setopt_long(curl_sys::CURLOPT_UPLOAD_BUFFERSIZE, size as c_long)
1073+
}
1074+
10641075
// /// Enable or disable TCP Fast Open
10651076
// ///
10661077
// /// By default this options defaults to `false` and corresponds to

systest/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ fn main() {
136136
_ => {}
137137
}
138138
}
139+
if version < 62 {
140+
match s {
141+
"CURLOPT_UPLOAD_BUFFERSIZE" => return true,
142+
_ => {}
143+
}
144+
}
139145
if version < 61 {
140146
match s {
141147
"CURLOPT_PIPEWAIT" => return true,

tests/easy.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ macro_rules! t {
1414
}
1515

1616
use curl::easy::{Easy, List, ReadError, Transfer, WriteError};
17+
use curl::Version;
1718

1819
use crate::server::Server;
1920
mod server;
@@ -300,6 +301,12 @@ fn misc() {
300301
// t!(h.tcp_keepidle(Duration::new(3, 0)));
301302
// t!(h.tcp_keepintvl(Duration::new(3, 0)));
302303
t!(h.buffer_size(10));
304+
305+
if Version::get().version_num() >= 0x073e00 {
306+
// only available on curl 7.62.0 or later:
307+
t!(h.upload_buffer_size(10));
308+
}
309+
303310
t!(h.dns_cache_timeout(Duration::new(1, 0)));
304311
}
305312

0 commit comments

Comments
 (0)