jaspervdj / websockets

A Haskell library for creating WebSocket-capable servers
http://jaspervdj.be/websockets
BSD 3-Clause "New" or "Revised" License
407 stars 113 forks source link

Is there a way to restrict message size received for server? #149

Closed Frefreak closed 7 years ago

Frefreak commented 7 years ago

I don't know much about websockets. Sorry if this is a noob question. What if a client send a large chunk of data to the server? It seems currently the server would try to parse the message anyways. Is there a way to configure it so that messages are discarded as soon as what the server received has already exceeds a certain limits, say 5MB?

jaspervdj commented 7 years ago

This is currently not supported, but it should not be extremely hard to add. The client must first send the length of the message, so it could be discarded at that point already, without parsing the 5MB of data.

Frefreak commented 7 years ago

Thank you for your answer! Looking forward to this.

lpeterse commented 7 years ago

I'll share my thoughts and insights on this:

jaspervdj commented 7 years ago

I'm in favor of doing the simplest thing that could work in this case, which is allowing people to set a maximum chunk and/or message size. If a message exceeds this limit, an exception is thrown and the connection is closed.

jaspervdj commented 7 years ago

@lpeterse @Frefreak I've created #152 to add these. I still need to add some tests but unless there's significant objections I think that is the API I will go with.

Frefreak commented 7 years ago

I haven't got time to try it but the API looks good to me. Let's wait for some time before closing this issue. Thanks for you work!

update: just tested it manually and it seems to work as expected.