Skip to content

Commit e37a551

Browse files
committed
move mime behind an opt-in feature
1 parent 2447d15 commit e37a551

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ zlib-ng-compat = ["curl-sys/zlib-ng-compat", "static-curl"]
5454
upkeep_7_62_0 = ["curl-sys/upkeep_7_62_0"]
5555
poll_7_68_0 = ["curl-sys/poll_7_68_0"]
5656
ntlm = ["curl-sys/ntlm"]
57+
mime = ["curl-sys/mime"]
5758

5859
[[test]]
5960
name = "atexit"

curl-sys/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ zlib-ng-compat = ["libz-sys/zlib-ng", "static-curl"]
5858
upkeep_7_62_0 = []
5959
poll_7_68_0 = []
6060
ntlm = []
61+
mime = []

curl-sys/lib.rs

+22-12
Original file line numberDiff line numberDiff line change
@@ -1166,21 +1166,31 @@ extern "C" {
11661166
sockfd: curl_socket_t,
11671167
sockp: *mut c_void,
11681168
) -> CURLMcode;
1169+
}
11691170

1170-
pub fn curl_mime_init(easy_handle: *mut CURL) -> *mut curl_mime;
1171-
pub fn curl_mime_free(mime_handle: *mut curl_mime);
1172-
pub fn curl_mime_addpart(mime_handle: *mut curl_mime) -> *mut curl_mimepart;
1173-
pub fn curl_mime_data(
1174-
mimepart: *mut curl_mimepart,
1175-
data: *const c_char,
1176-
datasize: size_t,
1177-
) -> CURLcode;
1178-
pub fn curl_mime_name(part: *mut curl_mimepart, name: *const c_char) -> CURLcode;
1179-
pub fn curl_mime_filename(part: *mut curl_mimepart, filename: *const c_char) -> CURLcode;
1180-
pub fn curl_mime_type(part: *mut curl_mimepart, mimetype: *const c_char) -> CURLcode;
1181-
pub fn curl_mime_subparts(part: *mut curl_mimepart, subparts: *mut curl_mime) -> CURLcode;
1171+
#[cfg(feature = "mime")]
1172+
mod mime {
1173+
use super::*;
1174+
1175+
extern "C" {
1176+
pub fn curl_mime_init(easy_handle: *mut CURL) -> *mut curl_mime;
1177+
pub fn curl_mime_free(mime_handle: *mut curl_mime);
1178+
pub fn curl_mime_addpart(mime_handle: *mut curl_mime) -> *mut curl_mimepart;
1179+
pub fn curl_mime_data(
1180+
mimepart: *mut curl_mimepart,
1181+
data: *const c_char,
1182+
datasize: size_t,
1183+
) -> CURLcode;
1184+
pub fn curl_mime_name(part: *mut curl_mimepart, name: *const c_char) -> CURLcode;
1185+
pub fn curl_mime_filename(part: *mut curl_mimepart, filename: *const c_char) -> CURLcode;
1186+
pub fn curl_mime_type(part: *mut curl_mimepart, mimetype: *const c_char) -> CURLcode;
1187+
pub fn curl_mime_subparts(part: *mut curl_mimepart, subparts: *mut curl_mime) -> CURLcode;
1188+
}
11821189
}
11831190

1191+
#[cfg(feature = "mime")]
1192+
pub use mime::*;
1193+
11841194
pub fn rust_crate_version() -> &'static str {
11851195
env!("CARGO_PKG_VERSION")
11861196
}

src/easy/handle.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use libc::c_void;
1212
use crate::easy::handler::{self, InfoType, ReadError, SeekResult, WriteError};
1313
use crate::easy::handler::{Auth, NetRc, PostRedirections, ProxyType, SslOpt};
1414
use crate::easy::handler::{HttpVersion, IpResolve, SslVersion, TimeCondition};
15+
#[cfg(feature = "mime")]
1516
use crate::easy::mime::Mime;
1617
use crate::easy::{Easy2, Handler};
1718
use crate::easy::{Form, List};
@@ -1472,6 +1473,7 @@ impl Easy {
14721473
self.inner.take_error_buf()
14731474
}
14741475

1476+
#[cfg(feature = "mime")]
14751477
/// Same as [`Easy2::add_mime`](struct.Easy2.html#method.add_mime)
14761478
pub fn add_mime(&mut self) -> Mime<EasyData> {
14771479
self.inner.add_mime()

src/easy/handler.rs

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use socket2::Socket;
1515

1616
use crate::easy::form;
1717
use crate::easy::list;
18+
#[cfg(feature = "mime")]
1819
use crate::easy::mime::Mime;
1920
use crate::easy::windows;
2021
use crate::easy::{Form, List};
@@ -379,6 +380,7 @@ pub fn ssl_ctx(cx: *mut c_void) -> Result<(), Error> {
379380
/// ```
380381
pub struct Easy2<H> {
381382
inner: Box<Inner<H>>,
383+
#[cfg(feature = "mime")]
382384
/// Mime handles to free upon drop
383385
mimes: Vec<*mut curl_sys::curl_mime>,
384386
}
@@ -602,6 +604,7 @@ impl<H: Handler> Easy2<H> {
602604
error_buf: RefCell::new(vec![0; curl_sys::CURL_ERROR_SIZE]),
603605
handler,
604606
}),
607+
#[cfg(feature = "mime")]
605608
mimes: vec![],
606609
};
607610
ret.default_configure();
@@ -3513,7 +3516,10 @@ impl<H> Easy2<H> {
35133516
}
35143517
Err(err)
35153518
}
3519+
}
35163520

3521+
#[cfg(feature = "mime")]
3522+
impl<H> Easy2<H> {
35173523
/// Create a mime handle attached to this [Easy2] instance.
35183524
pub fn add_mime(&mut self) -> Mime<H> {
35193525
Mime::new(self)
@@ -3542,6 +3548,8 @@ impl<H> Drop for Easy2<H> {
35423548
fn drop(&mut self) {
35433549
unsafe {
35443550
curl_sys::curl_easy_cleanup(self.inner.handle);
3551+
3552+
#[cfg(feature = "mime")]
35453553
for &mime_handle in self.mimes.iter() {
35463554
curl_sys::curl_mime_free(mime_handle);
35473555
}

src/easy/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod form;
1111
mod handle;
1212
mod handler;
1313
mod list;
14+
#[cfg(feature = "mime")]
1415
mod mime;
1516
mod windows;
1617

0 commit comments

Comments
 (0)