No matching definitions.

httpd/server

src/httpd/server.tur

start and stop HTTP servers.

Since: H6 (pool dispatch added in H7; runs on stdlib httpd since

defstruct

ServerOpts

(defstruct ServerOpts [])

configuration for server-start-opts / server-start-conn-opts.

Since: tourist-on-stdlib-httpd H2

defn

default-server-opts

(default-server-opts :)

the settings server-start uses.

ServerOpts

(server-start-opts 8080 my-handler
    (make-struct ServerOpts 16 1048576 2000))

Since: tourist-on-stdlib-httpd H2

defn

take-conn-response

(take-conn-response [hc ptr<void>] :)

move what a stdlib helper wrote on the conn into a

hcthe stdlib httpd conn of the current request (request-conn)

Response -- owned by the caller, like any handler's Response.

(if (httpd-static-serve! hc "./public" path)
    (take-conn-response hc)
    (not-found))

Since: tourist-on-stdlib-httpd H5

defn

serve-httpd-request

(serve-httpd-request [hc ptr<void> handler : (c-fn [int])

internal: serve one stdlib httpd request with a

Since: tourist-on-stdlib-httpd H2

defn

serve-httpd-request-conn

(serve-httpd-request-conn [hc ptr<void> handler : (c-fn [int int])

internal: serve one stdlib httpd request with a

Since: tourist-on-stdlib-httpd H2

defn

server-launch

(server-launch [h ptr<void>] :)

internal: run a stdlib httpd server on a background

ha stdlib httpd pool server handle, or NULL

:ptr<void> -- the server handle for server-stop, or NULL.

Since: tourist-on-stdlib-httpd H2

defn

server-tls-ctx

(server-tls-ctx [s ptr<void>] :)

internal: the TLS context recorded on a server handle.

defn

server-set-tls-ctx!

(server-set-tls-ctx! [s ptr<void> ctx : int] :)

internal: record the TLS context httpd/tls frees.

defn

server-start

(server-start [port : int handler : (c-fn [int])

bind a TCP listener on `port` and dispatch requests to

portTCP port to bind on (0 = kernel-assigned; see server-port).
127.0.0.1 unless the program called httpd-set-bind-any! or
httpd-set-bind-addr!.
handlercaptureless `(c-fn [int] int)` request handler. Define
it as a top-level defn of type `[req : int] : int`
returning a Response handle, and pass the defn name.
The handler is invoked from a worker thread; it must be
Send-safe. The server takes ownership of the Response
it returns (it is freed after the response is written).

:ptr<void> -- opaque server handle. Pass to server-stop to shut down, or NULL if the listening socket could not be created.

(defn my-handler [req :int] :int
    (resp-ok "text/plain" "Hello"))

  (let [srv (server-start 8080 my-handler)]
    ;; ... handle SIGINT, etc. ...
    (server-stop srv))

Since: H6 (pool default added in H7)

defn

server-start-pool

(server-start-pool [port : int handler : (c-fn [int])

like server-start but with an explicit pool size.

portTCP port to bind on
handler(c-fn [int] int) request handler (see server-start)
sizenumber of worker threads in the pool (clamped to >= 1)

:ptr<void> -- opaque server handle, or NULL on failure.

(def srv (server-start-pool 8080 my-handler 32))

Since: H7

defn

server-start-opts

(server-start-opts [port : int handler : (c-fn [int])

like server-start, configured by a ServerOpts.

portTCP port to bind on
handler(c-fn [int] int) request handler (see server-start)
optsServerOpts (pool size, body cap, read timeout)

:ptr<void> -- opaque server handle, or NULL on failure.

(server-start-opts 8080 my-handler (make-struct ServerOpts 8 65536 1000))

Since: tourist-on-stdlib-httpd H2

defn

server-start-conn

(server-start-conn [port : int handler : (c-fn [int int])

like server-start, but the handler receives a Conn

portTCP port to bind on
handlercaptureless `(c-fn [int int] int)`. Define it as a top-level
`(defn h [conn : Conn req : Request] : Response ...)` and pass
the name.

:ptr<void> -- opaque server handle, or NULL on failure.

Since: WS0

defn

server-start-pool-conn

(server-start-pool-conn [port : int handler : (c-fn [int int])

like server-start-conn but with an explicit pool

portTCP port to bind on
handler(c-fn [int int] int) (Conn, Request) -> Response handler
sizenumber of worker threads (clamped to >= 1)

:ptr<void> -- opaque server handle, or NULL on failure.

Since: WS0

defn

server-start-conn-opts

(server-start-conn-opts [port : int handler : (c-fn [int int])

like server-start-conn, configured by a ServerOpts.

portTCP port to bind on
handler(c-fn [int int] int) (Conn, Request) -> Response handler
optsServerOpts (pool size, body cap, read timeout)

:ptr<void> -- opaque server handle, or NULL on failure.

Since: tourist-on-stdlib-httpd H2

defopaque

ServerWrap

(ServerWrap)

a function that puts stdlib middleware around a server's

Since: tourist-on-stdlib-httpd H4

defn

server-wrap

(server-wrap [^fat f : (fn [ptr<void>] ptr<void>)])

package a wrap function for server-start-wrapped.

f(fn [ptr<void>] ptr<void>), called once when the server starts

ServerWrap -- pass to exactly one server-start-wrapped call

(server-wrap (fn [inner : ptr<void>] : ptr<void>
                 (compose-middleware inner mw-recover mw-log)))

Since: tourist-on-stdlib-httpd H4

defn

server-start-wrapped

(server-start-wrapped [port : int handler : (c-fn [int])

server-start-opts with stdlib middleware around

portTCP port to bind on
handler(c-fn [int] int) request handler (see server-start)
optsServerOpts (pool size, body cap, read timeout)
wrapServerWrap from server-wrap; called once and released, so
build one per server

:ptr<void> -- opaque server handle, or NULL on failure.

(server-start-wrapped 8080 my-handler (default-server-opts)
    (server-wrap (fn [inner : ptr<void>] : ptr<void>
                   (compose-middleware inner mw-recover mw-log))))

Since: tourist-on-stdlib-httpd H4

defn

server-start-conn-wrapped

(server-start-conn-wrapped [port : int handler : (c-fn [int int])

server-start-conn-opts with stdlib middleware

portTCP port to bind on
handler(c-fn [int int] int) (Conn, Request) -> Response handler
optsServerOpts (pool size, body cap, read timeout)
wrapServerWrap from server-wrap; called once and released

:ptr<void> -- opaque server handle, or NULL on failure.

Since: tourist-on-stdlib-httpd H4

defn

server-start-spawn

(server-start-spawn [port : int handler : (c-fn [int])

compatibility entry point: a pool of 64 workers.

portTCP port to bind on
handler(c-fn [int] int) request handler (see server-start)

:ptr<void> -- opaque server handle, or NULL on failure.

(def srv (server-start-spawn 8080 my-handler))

Since: H7

defn

server-port

(server-port [s ptr<void>] :)

the TCP port a server is listening on.

sserver handle from a server-start* function

:int -- the port, or -1 for a NULL handle.

(let [srv (server-start 0 my-handler)]
    (println (server-port srv)))

Since: tourist-on-stdlib-httpd H2

defn

server-stop

(server-stop [s ptr<void>] :)

stop the server and release it.

s:ptr<void> server handle returned by server-start (or NULL: no-op).

:void

(server-stop srv)

Since: H6 (pool join added in H7)

Internal definitions
srv-call-handler
srv-call-handler-conn
srv-send-response
srv-null?
srv-serve-view
srv-serve-view-conn
srv-null-ptr
srv-run-loop
srv-state-h
srv-state-join
srv-state-free
srv-spawn
srv-clamp-pool
srv-apply-opts
srv-default-pool-size
srv-wrap-apply