pub struct Downloader { /* private fields */ }
Expand description
Represents a downloader that can be used to download resources over HTTP/HTTPS.
Implementations§
Source§impl Downloader
impl Downloader
Sourcepub fn use_uri(&mut self, uri: Uri) -> &mut Self
pub fn use_uri(&mut self, uri: Uri) -> &mut Self
Sets the URI to download from.
§Arguments
uri
- The URI to download from.
§Examples
extern crate tokio;
extern crate download_async;
#[tokio::main]
async fn main() {
let uri = download_async::http::Uri::from_static("https://www.example.com");
let mut downloader = download_async::Downloader::new();
downloader.use_uri(uri);
let mut buffer = vec![];
let response = downloader.download(download_async::Body::empty(), &mut buffer).await;
}
Sourcepub fn headers(&mut self) -> Option<&mut HeaderMap<HeaderValue>>
pub fn headers(&mut self) -> Option<&mut HeaderMap<HeaderValue>>
Gets a mutable reference to the headers map for the request.
Sourcepub fn use_sockets(&mut self, sockets: SocketAddrs) -> &mut Self
pub fn use_sockets(&mut self, sockets: SocketAddrs) -> &mut Self
Sets the SocketAddrs
to use for the request.
§Arguments
sockets
- TheSocketAddrs
to use for the request.
Sourcepub fn allow_http(&mut self) -> &mut Self
pub fn allow_http(&mut self) -> &mut Self
Allows HTTP requests in addition to HTTPS requests.
§Examples
extern crate tokio;
extern crate download_async;
#[tokio::main]
async fn main() {
let uri = download_async::http::Uri::from_static("https://www.example.com");
let mut downloader = download_async::Downloader::new();
downloader.use_uri(uri);
downloader.allow_http();
let mut buffer = vec![];
let response = downloader.download(download_async::Body::empty(), &mut buffer).await;
}
pub fn use_progress<T: Progress + Send + 'static>( &mut self, progress: T, ) -> &mut Self
Sourcepub fn disable_compression(&mut self) -> &mut Self
pub fn disable_compression(&mut self) -> &mut Self
Sends the server the appropriate headers to prevent response compression.
§Examples
extern crate tokio;
extern crate download_async;
#[tokio::main]
async fn main() {
let uri = download_async::http::Uri::from_static("https://www.example.com");
let mut downloader = download_async::Downloader::new();
downloader.use_uri(uri);
downloader.disable_compression();
let mut buffer = vec![];
let response = downloader.download(download_async::Body::empty(), &mut buffer).await;
}
Sourcepub async fn download<T: HttpBody + Send + 'static>(
self,
body: T,
to: &mut impl Write,
) -> Result<Parts, Error>
pub async fn download<T: HttpBody + Send + 'static>( self, body: T, to: &mut impl Write, ) -> Result<Parts, Error>
An async method to download a resource and write it to a writer
§Arguments
self
- TheDownloader
instance to use for the requestbody
- The request bodyto
- A mutable reference to the writer to write the downloaded data to
§Returns
A Result containing Parts
if successful, or an Error
if there was an issue with the download
§Generic Parameters
T
- The type ofHttpBody
to use for the request
§Constraints
T
must implementHttpBody
,Send
, and'static
T::Data
must implementSend
T::Error
must implementInto<BoxError>
§Examples
extern crate tokio;
extern crate download_async;
#[tokio::main]
async fn main() {
let uri = download_async::http::Uri::from_static("https://www.example.com");
let mut downloader = download_async::Downloader::new();
downloader.use_uri(uri);
downloader.allow_http();
let mut buffer = vec![];
let response = downloader.download(download_async::Body::empty(), &mut buffer).await;
}
Auto Trait Implementations§
impl !Freeze for Downloader
impl !RefUnwindSafe for Downloader
impl Send for Downloader
impl !Sync for Downloader
impl Unpin for Downloader
impl !UnwindSafe for Downloader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more