Skip to content

Raroh73/ring-http-exchange

 
 

Repository files navigation

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

Property Description Default value
host Host name 127.0.0.1
port Application port 8080
executor External Executor to be used, if none provided ThreadPoolExecutor shall be used nil
max-threads Max threads for ThreadPoolExecutor 50
min-threads Min threads for ThreadPoolExecutor 8
max-queued-requests Max number of requests for ThreadPoolExecutor 1024
thread-idle-timeout Thread idle timeout in milliseconds for ThreadPoolExecutor, after which thread will stop 60000
ssl-context Ssl context to be used in https configurator nil

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.

About

Ring adapter for com.sun.net.httpserver.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Clojure 100.0%