hunchensocket icon indicating copy to clipboard operation
hunchensocket copied to clipboard

Added a generic extension mechanism and support for RFC7692 (permessage-deflate)

Open antipodite opened this issue 3 years ago • 4 comments

Hi, I've been working on support for permessage-deflate in hunchensocket. I'm submitting this PR so you can comment on what I've done so far and see if you think anything needs to be done differently. I've tested on Chrome and Firefox, basic permessage-deflate works. I'm planning to add support for the other Sec-websocket-extension parameters in the RFC too e.g. max_window_bits. I've added 3 dependencies: the deoxybyte-gzip zlib cffi wrapper (I couldn't get flushing and sliding window maintenance to work with pure CL deflate implementations), trivial-garbage for implementation independent cleanup of the Zlib foreign data structures, and str because I'm lazy (this could be removed).

I tried to implement the extension framework in a generic way so it can support both non-standard extensions and user-defined extensions, like logging frames and messages in a human readable way.

A quick overview of how it works:

  • Extensions are defined as subclasses of WEBSOCKET-EXTENSION
  • The symbols of the extension classes along with any required headers and parameters to make-instance are passed to a websocket acceptor when it is created
  • Every time a client is created for a request the extensions passed to the acceptor are instantiated and passed into the client
  • There are 4 generics to do extension related processing dealing with ingoing and outcoming frames and messages. These are called in succession for each extension instance on the client, for incoming frames in handle-frame and outgoing frames/messages in the send-message function. So you specialise these for any extensions you define to carry out any processing that is needed on frames or messages.

I made a few changes to existing functions and methods to allow manipulation of frames etc, but all tests still pass, the existing behaviour has not changed in absence of extensions

This is my first time working on someone else's code so any feedback would be greatly appreciated

Chur

Isaac

antipodite avatar Oct 12 '20 00:10 antipodite