Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add into_vec #652

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

add into_vec #652

wants to merge 1 commit into from

Conversation

dev-ardi
Copy link

@dev-ardi dev-ardi commented Aug 21, 2023

There's still some work to do but this would be the general idea

@algesten
Copy link
Owner

The idea is to use into_reader() for this.

    let mut bytes: Vec<u8> = Vec::with_capacity(len);
    resp.into_reader()
        .read_to_end(&mut bytes)?;

If that's unclear, we could look into making the doc better.

@dev-ardi
Copy link
Author

dev-ardi commented Sep 30, 2023

Isn't this the same code that I sent? This PR exists because it's pretty common to want the into_reader to actually be a Vec. This is just a helper method.

@@ -481,6 +481,17 @@ impl Response {
}
}

pub fn into_vec(self) -> Result<Vec<u8>, Error> {
let size = self
.header("Content-Type")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be "Content-Length"?
Also, what happens if e.g. "Transfer-Encoding: chunked" is used?
Using into_reader seems more convenient.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be "Content-Length"?

Oops it is :)

Also, what happens if e.g. "Transfer-Encoding: chunked" is used?

Well in that case more allocations will be made, this is just a small optimization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants