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

ASGI routes with body not extracted from the request #2101

Closed
ahopkins opened this issue Apr 6, 2021 · 1 comment · Fixed by #2117
Closed

ASGI routes with body not extracted from the request #2101

ahopkins opened this issue Apr 6, 2021 · 1 comment · Fixed by #2117
Labels

Comments

@ahopkins
Copy link
Member

ahopkins commented Apr 6, 2021

See source

This bug only applies to ASGI when sending.

When sending a body to a request on ASGI, the body is not making it through. I have not yet tested if this also applies with streaming requests.

The problem is here:

    async def read(self) -> Optional[bytes]:
        """
        Read and stream the body in chunks from an incoming ASGI message.
        """
        message = await self.transport.receive()
        if not message.get("more_body", False):
            self.request_body = False
            return None         # <<<< we are not returning the body
        return message.get("body", b"")

If a small message comes through that has not hit this read() more than once (again, I am assuming that a streaming request might actually work), the message will look like this:

message = await self.transport.receive()
# message={'type': 'http.request', 'body': b'{"foo": "bar"}', 'more_body': False}

Therefore, we need to return the body even if more_body is False (and also properly set self.request_body.

More testing is needed

@ahopkins ahopkins added the bug label Apr 6, 2021
@ashleysommer
Copy link
Member

Your analysis makes sense to me.

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

Successfully merging a pull request may close this issue.

2 participants