Ring adapter(HTTP server) with async and websocket extenstion
The server uses an event-driven, non-blocking I/O model that makes it lightweight and scalable.
It's written to conform to the standard Clojure web server
Ring spec, with asynchronous and websocket extenstion.
HTTP Kit is (almost) drop-in replacement of ring-jetty-adapter
:port: which port listens incomming request, default to 8090
:thread: How many threads to compute response from request, default to 4
:worker-name-prefix: woker thread name prefix, default to worker-: worker-1worker-2....
:queue-size: max requests queued waiting for threadpool to compute response before reject, 503(Service Unavailable) is returned to client if queue is full, default to 20K
:max-body: length limit for request body in bytes, 413(Request Entity Too Large) is returned if exceeds this limit, default to 8388608(8M)
:max-line: length limit for HTTP inital line and per header,
414(Request-URI Too Long) will be returned if exceeds this limit, default to 4096(4K),
relevant discusstion on stackoverflow
Websocket extenstion
if-ws-request or when-ws-request: get the websocket connection, returns websocket handshake
on-mesg: register a fn to be called when there is string message from client
send-mesg: send string message to client. Clojure data can be converted to string using
JSON or edn
close-conn: close the websocket connection
on-close: register a fn to be called when the connecton is closed
For WebSocket Secure connection, one option is stud (self-signed certificate may not work with websocket)
Compojure Can be used to do the routing, based on uri and method
Recommended server deployment
http-kit runs alone happly, handy for development and quick deployment.
Use reverse proxy like Nginx,
Lighthttpd, etc in serious production is encouraged. They also add https support.
They are fast, heavily optimized for static content.
They can be configured to compress the content sent to browsers