alexcrichton / curl-rust

Rust bindings to libcurl
MIT License
1.02k stars 233 forks source link

Websocket support in Easy APIs / curl-sys #579

Open frextrite opened 2 days ago

frextrite commented 2 days ago

I am exploring usage of websockes with curl-rust and looking for pointers on the same. Specifically I'm trying out the connect only model mentioned in libcurl documentation.

But from the looks of it curl::easy::connect_only(enable: bool) does not allow settings an integer value (specifically 2 in case of Websockets).

Since the high-level Easy2 APIs didn't support this, I explored the lower-level curl-sys ffi APIs which do support this even though it looks like I'm reinventing the wheel and using a lot of unsafe rust. On exploring further I wasn't able to find the core websockets functions - curl_ws_recv and curl_ws_send in curl-sys even though it is based on libcurl 8.10.1 which definitely supports these APIs.

Am I missing any configuration to enable the usage of curl_ws_recv and curl_ws_send functions or is it something that is currently not supported by the crate?

Edit: README mentions the bindings are developed using curl 7.24.0 but the latest package references libcurl 8.10.1. What gives?

sagebind commented 1 day ago

Am I missing any configuration to enable the usage of curl_ws_recv and curl_ws_send functions or is it something that is currently not supported by the crate?

curl-rust generally hasn't had the goal to be an exhaustive binding to the complete libcurl API, but rather only including things that people need. Nobody has asked for websocket support before which is why it is not currently implemented.

That said, if it were me, I would probably not seek out curl as my first choice of library for doing websockets in Rust, unless I was already using it in my project.

Edit: README mentions the bindings are developed using curl 7.24.0 but the latest package references libcurl 8.10.1. What gives?

curl-rust dynamically links to libcurl by default, which means in order to be backwards compatible with older versions of libcurl that may be present on older systems, by default curl-rust does not hard link to any libcurl functions which were introduced more recently. If curl-sys contained symbols only present in newer libcurl versions, then curl-sys would produce a linking error on systems that don't have the latest version of libcurl installed system-wide, which is probably a large number of systems.