Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Handle_websocket_request method in JsonRpc class #59

Open
Noor-Kalibbala opened this issue Oct 17, 2020 · 4 comments
Open

Handle_websocket_request method in JsonRpc class #59

Noor-Kalibbala opened this issue Oct 17, 2020 · 4 comments

Comments

@Noor-Kalibbala
Copy link

Incase the user have big json data, the future will just through timeout error instead
Of informing that user that actually the message size is exceeded, it would be
Nice if the Web socket response class can be supplied with max_msg_size incse the user wants to adjust that size.

@fscherf
Copy link
Contributor

fscherf commented Oct 19, 2020

Sounds reasonable. Do you have a patch for this?

@Noor-Kalibbala
Copy link
Author

@fscherf i overridden this function to something like this

class MyJsonRpc(JsonRpc):
    def __init__(self):
        super().__init__()

    async def handle_websocket_request(self, http_request):

        http_request.msg_id = 0
        http_request.pending = {}

        # prepare and register websocket
        ws = aiohttp.web_ws.WebSocketResponse(max_msg_size=int(1e+12))
        await ws.prepare(http_request)
        http_request.ws = ws
        self.clients.append(http_request)

        while not ws.closed:
            self.logger.debug('waiting for messages')
            raw_msg = await ws.receive()
            if not raw_msg.type == aiohttp.WSMsgType.TEXT:
                continue

            self.logger.debug('raw msg received: %s', raw_msg.data)
            self.loop.create_task(self._handle_rpc_msg(http_request, raw_msg))

        self.clients.remove(http_request)
        return ws

@fscherf
Copy link
Contributor

fscherf commented Oct 20, 2020

@Noor-Kalibbala
The only line that is changed is

ws = aiohttp.web_ws.WebSocketResponse(max_msg_size=int(1e+12))

right? Where does int(1e+12) come from?

@Noor-Kalibbala
Copy link
Author

Noor-Kalibbala commented Oct 20, 2020 via email

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

No branches or pull requests

2 participants