コード例 #1
0
    async def finalize_asgi(self, response: Response, send: ASGISend,
                            scope: ASGIScope):
        if response.exc_info is not None:
            if self.debug or scope.get('raise_exceptions', False):
                exc_info = response.exc_info
                raise exc_info[0].with_traceback(exc_info[1], exc_info[2])

        await send({
            'type':
            'http.response.start',
            'status':
            response.status_code,
            'headers':
            [[key.encode(), value.encode()] for key, value in response.headers]
        })
        if hasattr(response.content, "read"):
            body = await self.read(response)
            while body:
                await send({
                    'type': 'http.response.body',
                    'body': body,
                    "more_body": True,
                })
                body = await self.read(response)
        else:
            body = response.content
        await send({'type': 'http.response.body', 'body': body})
コード例 #2
0
ファイル: app.py プロジェクト: hiway/apistar
    async def finalize_asgi(self, response: Response, send: ASGISend,
                            scope: ASGIScope):
        if response.exc_info is not None:
            if self.debug or scope.get('raise_exceptions', False):
                exc_info = response.exc_info
                raise exc_info[0].with_traceback(exc_info[1], exc_info[2])

        await send({
            'type':
            'http.response.start',
            'status':
            response.status_code,
            'headers':
            [[key.encode(), value.encode()] for key, value in response.headers]
        })
        await send({'type': 'http.response.body', 'body': response.content})
コード例 #3
0
    async def finalize_asgi(self, response: Response, send: ASGISend,
                            scope: ASGIScope):
        if response.exc_info is not None:
            if self.debug or scope.get("raise_exceptions", False):
                exc_info = response.exc_info
                raise exc_info[0].with_traceback(exc_info[1], exc_info[2])

        await send({
            "type":
            "http.response.start",
            "status":
            response.status_code,
            "headers": [[key.encode(), value.encode()]
                        for key, value in response.headers],
        })
        await send({"type": "http.response.body", "body": response.content})