aiohttp-json-rpc icon indicating copy to clipboard operation
aiohttp-json-rpc copied to clipboard

Handle_websocket_request method in JsonRpc class

Open Noor-Kalibbala opened this issue 5 years ago • 4 comments

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.

Noor-Kalibbala avatar Oct 17 '20 12:10 Noor-Kalibbala

Sounds reasonable. Do you have a patch for this?

fscherf avatar Oct 19 '20 10:10 fscherf

@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

Noor-Kalibbala avatar Oct 19 '20 11:10 Noor-Kalibbala

@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?

fscherf avatar Oct 20 '20 15:10 fscherf

@fscherf Actually its equivalent to one terabyte but I think u can set it to zero to ignore message size may be

On Tue, Oct 20, 2020, 6:09 PM Florian Scherf [email protected] wrote:

@Noor-Kalibbala https://github.com/Noor-Kalibbala The only line that is changed is

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

right? Where comes int(1e+12) from?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pengutronix/aiohttp-json-rpc/issues/59#issuecomment-712922929, or unsubscribe https://github.com/notifications/unsubscribe-auth/AM3YELKWCUBCHM2CNTRXQL3SLWR4LANCNFSM4SULAESA .

Noor-Kalibbala avatar Oct 20 '20 15:10 Noor-Kalibbala