knutin / elli

Simple, robust and performant Erlang web server
MIT License
663 stars 79 forks source link

Add support for Upgrade to Elli (making web socket middleware possible) #71

Closed arobson closed 10 years ago

arobson commented 10 years ago

I only found out about the other branch after I had completed this one. With this approach, you have to specify {upgrade, true} as an option when setting up Elli.

If upgrading has been enabled, any middleware or callback module can return {upgrade, Callback} where Callback is a function that takes the request header list, the request body and the underlying socket. Elli will activate this callback and relinquish control of the Socket.

I've tried to add some (rather minimalistic) test coverage to show how an upgrade gets treated if it's not been enabled.

Take a look at http://github.com/arobson/elli_websockets to see how I'm currently using this. The websocket middleware presently only supports hybi. I plan to add support for SSL against the SSL branch for the middleware soon.

arobson commented 10 years ago

Going to close this one out. Now that Elli's handover is in master, I have re-worked elli_websockets to use that instead. I did notice that Elli will still send the request_closed and request_timeout events to the middleware module, but since it doesn't actually close the socket, I'm just ignoring the events. It's not clear what I would need to do to prevent this from happening, but as everything appears to be working, I won't worry about it for now. Thanks.