alexcrichton / curl-rust

Rust bindings to libcurl
MIT License
1k stars 234 forks source link

Stop curl at specific point #510

Closed Omicronlawful closed 12 months ago

Omicronlawful commented 12 months ago

Im interested if its possible to stop the curl when parts of it where fetched

let v:Arc<Mutex<String>> = Arc::new(Mutex::new(String::new()));
    let temp = v.clone();
    easy.write_function(move |data| {
        temp.lock().unwrap().push_str(std::str::from_utf8(data).unwrap());
        if temp.lock().unwrap().contains("var ...") {
            //TODO: stop the request
        }
        Ok(data.len())
    }).unwrap();
    easy.perform().unwrap();
sagebind commented 12 months ago

No, libcurl is not designed to be interrupted during a transfer when using the easy API; however, you can halt a transfer at any time when using the multi API. I recommend looking up some guides on using the curl multi API. The entrypoint to the multi API in the Rust bindings is the aptly-named Multi type.

Hope that helps!