-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Share support #585
Comments
The Share API is pretty unsafe, as you have to bring your own mutexes and manually keep track of references to avoid use-after-free. It might be doable, but would be tricky I think. It would have to be implemented in a way that:
Given those constraints I don't see any reason why we wouldn't accept this to be added to the API, as it could be useful in some scenarios. For design, I messed with this API several years ago, though I never finished it. Probably the most realistic approach would be to use an Arc internally in our Share wrapper. The API we present looks like you add Easy handles to it, but under the hood you're really adding a clone of the Share reference to the Easy handle. So each Both If users want a lock-free Share for single-threaded use, it may be better to create a totally separate The docs are not clear whether it is safe to set As a user, I might expect using the API to perhaps look something like this: let share = Share::builder()
.dns()
.psl()
.build();
let easy1 = Easy::new();
let easy2 = Easy::new();
easy1.set_share(&share);
easy2.set_share(&share); Note that the docs do indicate that the following can not be used in a multi-threaded context, even if locking is configured:
I guess that does make me wonder if actually a |
Thanks for getting back to me so quickly, and for sharing your thoughts. The API design looks very similar to what I had in mind.
Yes - after opening this issue I came across this message which actually makes it sounds like offering Given this, let me first run some tests to see how much value this adds over the caching built into multi. Specifically I'm wondering if DNS and SSL contexts are cached by multi - the documentation isn't entirely clear on that if I remember correctly. |
Yes, certain elements are already shared between handles that are added to the same multi, which IMO also limits the usefulness of the Share API if Multi does some of the same things. The Everything Curl book says:
This does start to refresh my memory of the last time I interacted with this API, and decided it actually wasn't all that useful. |
As someone who is also interested in getting access to the Share interface, given I'm in the process of re-writing a C++ app which uses curl into Rust, the share interface also allows for curl to automatically share and handle cookies between multiple handles, which isn't possible otherwise... My particular use-case is having background worker threads download CSS/JS/Image files after the first initial perform() call on the first handle and HTML parsing from that, along with the initial main thread then assisting. That's what the C++ code was doing, as some of the subsequent HTTP requests need things like session cookies that were only set by the first main request response from the server to work, and the curl C share interface for Cookies worked perfectly for allowing that to happen, and curl would manage all the cookie processing and sharing itself. Currently, the only way I can see of doing it with curl-rust (at least using the Easy interface, I guess using the Multi interface might be another way) is saving out a cookie jar file in the first request, and then have subsequent requests try and use that output file as the cookie file, which at some point in the next month I'll prototype up to see how well it works, but I suspect it'll be a bit messy and not as nice as native Share support. I'd be happy to try and help out in this area if possible (I'm relatively new to Rust however). |
Hi, thanks for maintaining this package. I'd like to add support for the share interface - that is,
Would you accept a PR for this, and are you interested in discussing API design and implementation details?
The text was updated successfully, but these errors were encountered: