(run-server handler & [{:keys [ip port thread queue-size max-body max-ws max-line proxy-protocol worker-name-prefix], :or {max-ws 4194304, max-body 8388608, max-line 4096, ip "0.0.0.0", queue-size 20480, proxy-protocol :disable, port 8090, thread 4, worker-name-prefix "worker-"}}])
Starts HTTP server and returns
(fn [& {:keys [timeout] ; Timeout (msecs) to wait on existing reqs to complete
:or {timeout 100}}])
Server is mostly Ring compatible, see http://http-kit.org/migration.html
for differences.
Options:
:ip ; Which ip (if has many ips) to bind
:port ; Which port listen incomming request
:thread ; Http worker thread count
:queue-size ; Max job queued before reject to project self
:max-body ; Max http body: 8m
:max-ws ; Max websocket message size
:max-line ; Max http inital line length
:proxy-protocol ; Proxy protocol e/o #{:disable :enable :optional}
:worker-name-prefix ; Woker thread name prefix
Source
(defn run-server
"Starts HTTP server and returns
(fn [& {:keys [timeout] ; Timeout (msecs) to wait on existing reqs to complete
:or {timeout 100}}])
Server is mostly Ring compatible, see http://http-kit.org/migration.html
for differences.
Options:
:ip ; Which ip (if has many ips) to bind
:port ; Which port listen incomming request
:thread ; Http worker thread count
:queue-size ; Max job queued before reject to project self
:max-body ; Max http body: 8m
:max-ws ; Max websocket message size
:max-line ; Max http inital line length
:proxy-protocol ; Proxy protocol e/o #{:disable :enable :optional}
:worker-name-prefix ; Woker thread name prefix"
[handler
& [{:keys [ip port thread queue-size max-body max-ws max-line
proxy-protocol worker-name-prefix]
:or {ip "0.0.0.0"
port 8090
thread 4
queue-size 20480
max-body 8388608
max-ws 4194304
max-line 4096
proxy-protocol :disable
worker-name-prefix "worker-"}}]]
(let [h (RingHandler. thread handler worker-name-prefix queue-size)
proxy-enum (case proxy-protocol
:enable ProxyProtocolOption/ENABLED
:disable ProxyProtocolOption/DISABLED
:optional ProxyProtocolOption/OPTIONAL)
s (HttpServer. ip port h max-body max-line max-ws proxy-enum)]
(.start s)
(with-meta
(fn stop-server [& {:keys [timeout] :or {timeout 100}}]
;; graceful shutdown:
;; 1. server stop accept new request
;; 2. wait for existing requests to finish
;; 3. close the server
(.stop s timeout))
{:local-port (.getPort s)
:server s})))