Liking cljdoc? Tell your friends :D

ring-http-exchange

Clojure ring adapter for com.sun.net.httpserver.HttpServer which is included in the JDK.

The main motivation for this is to support starting a small HTTP server inside an application which itself isn't necessary primarily a web app, while avoiding adding any new dependencies on the classpath (apart from ring-core).

Usage

(:require [ring-http-exchange.core :as server])
(server/run-http-server
  (fn [_]
    {:status 200
     :headers {"Content-Type" "text/html; charset=utf-8"}
     :body "hello world"})
  {:port 8080
   :ssl-context (ssl/keystore->ssl-context 
                                      (io/resource "keystore.jks") "keystore-password"
                                      (io/resource "truststore.jks") "truststore-password")
   :executor (Executors/newVirtualThreadPerTaskExecutor)})

Supported response body types

Response Body Type
java.lang.String
java.io.InputStream
java.io.File
byte[]
ring.core.protocols/StreamableResponseBody
nil

Server configuration

PropertyDescriptionDefault value
hostHost name127.0.0.1
portApplication port8080
executorExternal Executor to be used, if none provided ThreadPoolExecutor shall be usednil
max-threadsMax threads for ThreadPoolExecutor50
min-threadsMin threads for ThreadPoolExecutor8
max-queued-requestsMax number of requests for ThreadPoolExecutor1024
thread-idle-timeoutThread idle timeout in milliseconds for ThreadPoolExecutor, after which thread will stop60000
ssl-contextSsl context to be used in https configuratornil

Limitations

  • Transfer-Encoding header will be set to chunked, if it is not possible to get length of the body.

License

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

Can you improve this documentation? These fine people already did:
Jj & Håkan Råberg
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close