javascript - how to limit the amount of data being sent by the client through websocket? -
i using ws
module , i'd limit amount of data being sent client on websocket 1mb. prevent malicious user sending huge amounts of data (in terms of gb) causing server run out of memory, cause denial of service errors every normal user.
example, example express allows specify max size of post request body so:
bodyparser.json({limit:'1mb'})
how similar ws
module?
i tried
var ws = require('ws').server var wsserver = new ws({port:8080, limit:'1mb'})
but of course doesn't work.
want transmission of data interrupted (after 1mb exceeded) , websocket connection closed. how can that?
there must way limit frames of data coming client...
that ability not (currently) exist in library.
poking around source code, appears place start processpacket()
method in https://github.com/websockets/ws/blob/master/lib/receiver.js .
once have packet header available, can see size of message being sent. if it's above threshold, there should way close connection before of bytes hitting network.
of course, nice thing fork repository, issue feature request, add in configuration option defaults not taking action if it's not set (don't break backwards compatibility), , submit pull request.
if it, they'll merge. if not, you'll still able merge future versions own repo , stay date without having re-do work each time submit new release.
Comments
Post a Comment