NanoHttpd / nanohttpd

Tiny, easily embeddable HTTP server in Java.

Home Page:http://nanohttpd.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

permessage-deflate for WebSockets

stefan-reich opened this issue · comments

WebSocket compression (permessage-deflate) is now well-supported in browsers.

Has anyone attempted to add it to NanoHTTPD?

(For context: For very interactive pages I have moved to a mode where the whole page is delivered through a websocket as this simplifies dynamic page updates a lot, so at that moment I have lost the automatic GZIP compression for HTML content. Example page with a lot of WebSocket activity served directly from NanoHTTPD.)

I would strongly consider using Java-WebSocket over NanoHTTPD. It has compression support IIRC, and has generally seemed significantly more reliable to me. I had a lot of weird issues with WebSockets in NanoHTTPD when I tried it.

You'll have to have WebSocket traffic be on a different port, but that's not the end of the world.

Yes there were issues at some point with NanoHTTPD's websockets. Not sure which version it was or when, but NanoHTTPD added spurious null bytes at the end of WebSocket messages. Since I fixed that, everything is running smoothly.

If I switch to a completely different library, I will have to change a lot of infrastructure. As it is now, I can parse request parameters, headers etc. exactly the same way between a HTTP request and a WebSocket. And NGL, having the same port for http and websockets is pretty nice too.

I may actually add the compression myself, I think it's doable (although the RFC makes it a little more complicated than one might expect). Websites completely built on NanoHTTPD are my ticket to fame, lol.