Struct download_async::Downloader
source · 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>where
T::Data: Send,
T::Error: Into<Box<dyn Error + Send + Sync>>,
pub async fn download<T: HttpBody + Send + 'static>( self, body: T, to: &mut impl Write ) -> Result<Parts, Error>where T::Data: Send, T::Error: Into<Box<dyn Error + Send + Sync>>,
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;
}