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 body of request is not guaranteed to read entire body #31

Closed
dpgeorge opened this issue Oct 20, 2021 · 2 comments
Closed

Reading body of request is not guaranteed to read entire body #31

dpgeorge opened this issue Oct 20, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@dpgeorge
Copy link
Contributor

The code used to read the body of the request is:

        # body
        body = await client_stream.read(content_length) if content_length and \
            content_length <= Request.max_content_length else b''

But asyncio.Stream.read(n) is not guaranteed to read exactly n bytes, it may return a shorter read than that. In such a case only part of the body is read.

Is this expected behaviour of microdot (to not always read the whole body), or is it a bug, which can be fixed by using readexactly?

@miguelgrinberg
Copy link
Owner

Thanks. Using readexactly seems better, I'll change it.

@miguelgrinberg miguelgrinberg added the bug Something isn't working label Oct 20, 2021
@miguelgrinberg miguelgrinberg self-assigned this Oct 20, 2021
@dpgeorge
Copy link
Contributor Author

Using readexactly seems better, I'll change it.

Great!

I didn't check the standard (non-asyncio) code. It may also need fixing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants