pub struct HttpControl { /* private fields */ }Expand description
Cancellation and progress shared with an in-flight request.
One control covers every request rather than only file downloads: a slow response is a slow response whether it is being written to disk or read into memory, and a screen that leaves is a screen that leaves.
Implementations§
Source§impl HttpControl
impl HttpControl
Sourcepub fn with_progress(
self,
progress: impl Fn(HttpProgress) + Send + Sync + 'static,
) -> Self
pub fn with_progress( self, progress: impl Fn(HttpProgress) + Send + Sync + 'static, ) -> Self
Reports transferred and, where the server says so, total bytes.
Called from whichever thread is doing the transfer, so the handler must be prepared for that — the framework’s own event stream is the ordinary way to get it back to composition.
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Requests cancellation.
A native transfer that waits for the response or the next chunk ends
with HttpError::Cancelled at once; other backends stop at the next
chunk boundary. A partial file left by a cancelled download stays on
disk, which is what makes the next attempt able to resume rather than
start again.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Whether cancellation was requested.
Sourcepub fn on_cancel(&self, transfer: Weak<dyn CancelTransfer>)
pub fn on_cancel(&self, transfer: Weak<dyn CancelTransfer>)
Cancels transfer when this control is cancelled, or now if it already
is. The control holds it weakly, so a transfer that ended is dropped
at the next registration; a backend keeps it alive while it runs.
Sourcepub fn report(&self, progress: HttpProgress)
pub fn report(&self, progress: HttpProgress)
Hands a progress reading to whatever with_progress
registered, and does nothing where nothing did.
Called by the backend doing the transfer - including an
HttpClient an application provides through local_http_client,
which is why this is part of the control’s public surface rather than
private to the backends shipped here.