http-rs / http-rs/surf

Callback for download requests

Open
#216 4 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Rust
Stars
1.5k
Forks
128
PR merge metrics
No merged PRs in 30d

Description

So I want to download a very big file, but with the current API I can only store it in memory and then write to a file, that is a HUGE problem, also I want to show a progress bar or something like that, so I figure out a manner to make this possible:
```rust
struct Manager;

impl Manager {
pub fn new() -> Manager {
Manager {}
}
}

impl surf::DownloadManager for Manager {
async fn process_headers(&self, headers: HEADERS) {
// Process content-length, content-disposition, etc
}

async fn process_chunk(&self, chunk: &[u8]) {
// Write chunk to disk and report download progress...
}
}

async fn get() -> Result<(), surf::Exception> {
let mngr = Manager::new();
let mut res = surf::callback_request::get("https://httpbin.org/get", mngr).await?;
Ok(())
}
```
What do you think?
for now, I am using curl directly

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.