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

Reading the body of a request #2078

Open
rogusdev opened this issue Dec 30, 2023 · 2 comments
Open

Reading the body of a request #2078

rogusdev opened this issue Dec 30, 2023 · 2 comments

Comments

@rogusdev
Copy link

rogusdev commented Dec 30, 2023

I want to be able to read the body of a (multipart) request I have built, for tests, but I cannot because there does not seem to be a public API for converting a Body (async nor blocking) into bytes. It has an as_bytes() method, but for Inner::Streaming it returns None (same for blocking's Kind::Reader) so there seems to be no way to publicly access that data when it needs to be streamed to turn into bytes. Am I missing something to do this? Or is this a missing feature?

To be clear, I see the tests: https://github.com/seanmonstar/reqwest/blob/master/tests/multipart.rs that compare against what was received by an actual http server. And the unit tests access private methods.

Thanks.

@seanmonstar
Copy link
Owner

Am I missing something to do this? Or is this a missing feature?

You're not missing anything. It so far was not publicly exposed. In #2059, there's a possibility of keeping the public impl HttpBody for Body, in which case you could use that.

the unit tests access private methods.

The integration tests (in the tests directory) all use public methods, they are compiled as separate from the library, they don't have any internal access.

@rogusdev
Copy link
Author

rogusdev commented Jan 1, 2024

possibility of keeping the public impl HttpBody for Body,

Sounds good, I would appreciate that, thanks :)

The integration tests (in the tests directory) all use public methods, they are compiled as separate from the library, they don't have any internal access.

Yes, that's why I mentioned the unit tests as separate, e.g.

let body = form.stream().into_stream();
which does exactly what I want -- but relies on private methods.

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

No branches or pull requests

2 participants