add mime support (form api is deprecated according to libcurl)#537
add mime support (form api is deprecated according to libcurl)#537tsnoam wants to merge 4 commits intoalexcrichton:mainfrom
Conversation
e0229d7 to
3d95543
Compare
ubuntu:16.04 version of libcurl doesn't have the mime feature compiled in
|
We support linking against libcurl versions older than 7.56.0 (when the mime API was added) so this will need to be behind an opt-in feature to avoid breaking compatibility with those older versions. |
| mod handle; | ||
| mod handler; | ||
| mod list; | ||
| mod mime; |
There was a problem hiding this comment.
mime is kinda its own API that isn't specific to the easy API, so I would make mime a top-level module.
There was a problem hiding this comment.
I can see what you're saying about "kinda its own API".
However, mime API doesn't have a meaning without the easy API, quite similar to the form API. So basically, I've put the mime module in the same level as the form module.
I don't mind extracting it, just thought it is worth double checking this before doing so.
Your call though, I'll do what you ask :)
| pub struct Easy2<H> { | ||
| inner: Box<Inner<H>>, | ||
| /// Mime handles to free upon drop | ||
| mimes: Vec<*mut curl_sys::curl_mime>, |
There was a problem hiding this comment.
Only one mime object should be attached to an easy handle at a time since CURLOPT_MIMEPOST replaces any previously assigned mime, so this doesn't seem like it needs to be a Vec.
This should also probably go inside Inner like everything else.
I would also prefer to avoid a raw pointer here since that requires multiple implementations handling the calling of curl_mime_free in multiple places. I wonder if there is a way of keeping the drop code in the Mime struct?
- The raw mime handle is now wrapped by a rust struct which will call curl_mime_free() upon Drop - Easy2 now keeps the MimeHandle as an Option instead of Vec - The above Option is kept inside Inner instead of directly under Easy2
Ok. Done. |
|
@sagebind |
|
Hi @sagebind is there anything else blocking this PR? |
libcurl considers the form api deprecated.
in
curl_formadd(3)one of the first lines says:This pull requests implements a safe wrapper of the mime api, keeping simplicity in mind. Usage is quite straight forward.
The following example is a bit simplified (lot of unwraps, usage of
&strwhere possible.