Ring adapter backed by a zero-dependency Java core: blocking I/O on virtual threads, one virtual thread per connection.
Ring adapter backed by a zero-dependency Java core: blocking I/O on virtual threads, one virtual thread per connection.
(flush! w)Emits any pending bytes as a chunk and forces them onto the wire.
Emits any pending bytes as a chunk and forces them onto the wire.
(port server)Actual listening port of server.
Actual listening port of `server`.
(run-server handler)(run-server handler {:keys [error-handler] :as opts})Starts an HTTP server calling handler with Ring request maps.
Returns the server, stop it with stop.
Network options:
:port - listen port, 0 picks an ephemeral port (default 8080):host - bind address (default "0.0.0.0"):backlog - accept queue length (default 1024)Timeouts:
:idle-timeout - per-read socket timeout in ms, 0 disables (default 30000):request-timeout - wall-clock deadline for reading a full request in ms,
0 disables (default 30000). Slowloris protection.:shutdown-timeout - graceful shutdown wait for in-flight requests in ms
(default 10000). Idle keep-alive connections close immediately.TLS:
:ssl-context - javax.net.ssl.SSLContext. When set, listens as TLS with
the context's keystore/truststore/protocols. Falls back to a user-space
file transfer for File response bodies (no zero-copy on TLS).:ssl-need-client-auth - require a valid client certificate (default false):ssl-want-client-auth - request but not require a client cert (default false)Error handling:
:error-handler - (fn [request throwable]) returning a Ring response map.
Invoked when the main handler throws or returns nil. If the error handler
itself throws or returns nil, a fallback 500 text response is sent.Buffers / limits (tune only if you know why):
:request-buffer-size - initial request parse buffer size (default 16384).
Grown up to :max-header-bytes as headers arrive.:max-header-bytes - hard cap for request headers, 431 above (default 65536).
Also caps how large the parse buffer may grow.:max-inline-body - response bodies at or below this size are inlined into
the header write buffer for one-syscall dispatch (default 16384). Larger
values reduce syscalls for big responses at the cost of more short-term
heap during pipelined bursts.:coalesce-high-water - pending response bytes at which a pipelined batch
is force-flushed (default 32768). Should be a small multiple of
:max-inline-body — batches beyond this cost more in memory than they
save in syscalls.:chunk-buffer-size - read chunk size when streaming response bodies with
Transfer-Encoding: chunked (default 8192). Reused across pipelined
responses on the same connection.:max-drain-bytes - largest ignored request body size drained before the
connection is closed instead of reused (default 65536). If the handler
ignores a POST body larger than this, keep-alive is dropped.:max-request-body-bytes - cap for the incoming request body in bytes,
0 disables (default 10 MiB). Content-Length above the cap → 413 upfront;
chunked bodies get 413 mid-stream once the cap is exceeded. Also caps
WebSocket frame payload size (uses same limit).Interaction notes:
:request-buffer-size and :max-header-bytes should typically be equal
or request-buffer-size <= max-header-bytes. Otherwise the initial buffer
caps at max-header-bytes and pipelined batches larger than that get
fragmented reads.:max-inline-body <= :coalesce-high-water — otherwise a single large
response triggers a flush before the next pipelined request can be
coalesced, defeating the batching.:request-timeout interacts with :idle-timeout: the per-read timeout is
min(idle, remaining-request-budget). Set both to sensible values.Errors are routed through java.util.logging under the loggers
com.s_exp.enso.HttpConnection and com.s_exp.enso.EnsoServer. Wire a
handler / SLF4J bridge in your application to redirect them.
Starts an HTTP server calling `handler` with Ring request maps. Returns the server, stop it with [[stop]]. Network options: - `:port` - listen port, 0 picks an ephemeral port (default 8080) - `:host` - bind address (default "0.0.0.0") - `:backlog` - accept queue length (default 1024) Timeouts: - `:idle-timeout` - per-read socket timeout in ms, 0 disables (default 30000) - `:request-timeout` - wall-clock deadline for reading a full request in ms, 0 disables (default 30000). Slowloris protection. - `:shutdown-timeout` - graceful shutdown wait for in-flight requests in ms (default 10000). Idle keep-alive connections close immediately. TLS: - `:ssl-context` - `javax.net.ssl.SSLContext`. When set, listens as TLS with the context's keystore/truststore/protocols. Falls back to a user-space file transfer for File response bodies (no zero-copy on TLS). - `:ssl-need-client-auth` - require a valid client certificate (default false) - `:ssl-want-client-auth` - request but not require a client cert (default false) Error handling: - `:error-handler` - `(fn [request throwable])` returning a Ring response map. Invoked when the main handler throws or returns nil. If the error handler itself throws or returns nil, a fallback 500 text response is sent. Buffers / limits (tune only if you know why): - `:request-buffer-size` - initial request parse buffer size (default 16384). Grown up to `:max-header-bytes` as headers arrive. - `:max-header-bytes` - hard cap for request headers, 431 above (default 65536). Also caps how large the parse buffer may grow. - `:max-inline-body` - response bodies at or below this size are inlined into the header write buffer for one-syscall dispatch (default 16384). Larger values reduce syscalls for big responses at the cost of more short-term heap during pipelined bursts. - `:coalesce-high-water` - pending response bytes at which a pipelined batch is force-flushed (default 32768). Should be a small multiple of `:max-inline-body` — batches beyond this cost more in memory than they save in syscalls. - `:chunk-buffer-size` - read chunk size when streaming response bodies with Transfer-Encoding: chunked (default 8192). Reused across pipelined responses on the same connection. - `:max-drain-bytes` - largest ignored request body size drained before the connection is closed instead of reused (default 65536). If the handler ignores a POST body larger than this, keep-alive is dropped. - `:max-request-body-bytes` - cap for the incoming request body in bytes, 0 disables (default 10 MiB). Content-Length above the cap → 413 upfront; chunked bodies get 413 mid-stream once the cap is exceeded. Also caps WebSocket frame payload size (uses same limit). Interaction notes: - `:request-buffer-size` and `:max-header-bytes` should typically be equal or `request-buffer-size <= max-header-bytes`. Otherwise the initial buffer caps at `max-header-bytes` and pipelined batches larger than that get fragmented reads. - `:max-inline-body <= :coalesce-high-water` — otherwise a single large response triggers a flush before the next pipelined request can be coalesced, defeating the batching. - `:request-timeout` interacts with `:idle-timeout`: the per-read timeout is `min(idle, remaining-request-budget)`. Set both to sensible values. Errors are routed through `java.util.logging` under the loggers `com.s_exp.enso.HttpConnection` and `com.s_exp.enso.EnsoServer`. Wire a handler / SLF4J bridge in your application to redirect them.
(stop server)Stops server. In-flight requests complete, open connections close.
Stops `server`. In-flight requests complete, open connections close.
(write! w data)Buffers bytes into the pending chunk. String is UTF-8 encoded.
Buffers bytes into the pending chunk. String is UTF-8 encoded.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |