|
2 | 2 | "A Ring adapter that uses the Jetty 9 embedded web server.
|
3 | 3 |
|
4 | 4 | Adapters are used to convert Ring handlers into running web servers."
|
5 |
| - (:require [ring.util.jakarta.servlet :as servlet] |
| 5 | + (:require [clojure.java.io :as io] |
| 6 | + [ring.util.jakarta.servlet :as servlet] |
6 | 7 | [ring.websocket :as ws]
|
7 | 8 | [ring.websocket.protocols :as wsp])
|
8 | 9 | (:import [java.nio ByteBuffer]
|
|
15 | 16 | HttpConnectionFactory
|
16 | 17 | SslConnectionFactory
|
17 | 18 | SecureRequestCustomizer]
|
| 19 | + [org.eclipse.jetty.unixdomain.server UnixDomainServerConnector] |
18 | 20 | [org.eclipse.jetty.servlet ServletContextHandler ServletHandler]
|
19 | 21 | [org.eclipse.jetty.util BlockingArrayQueue]
|
20 | 22 | [org.eclipse.jetty.util.thread ThreadPool QueuedThreadPool]
|
|
161 | 163 | (ServerConnector. server #^"[Lorg.eclipse.jetty.server.ConnectionFactory;"
|
162 | 164 | (into-array ConnectionFactory factories)))
|
163 | 165 |
|
| 166 | +(defn- unix-domain-server-connector ^UnixDomainServerConnector [^Server server & factories] |
| 167 | + (UnixDomainServerConnector. server #^"[Lorg.eclipse.jetty.server.ConnectionFactory;" |
| 168 | + (into-array ConnectionFactory factories))) |
| 169 | + |
164 | 170 | (defn- http-config ^HttpConfiguration [options]
|
165 | 171 | (doto (HttpConfiguration.)
|
166 | 172 | (.setSendDateHeader (:send-date-header? options true))
|
|
229 | 235 | (.setHost (options :host))
|
230 | 236 | (.setIdleTimeout (options :max-idle-time 200000)))))
|
231 | 237 |
|
| 238 | +(defn- unix-socket-connector ^ServerConnector [server options] |
| 239 | + (let [http-factory (HttpConnectionFactory. (http-config options)) |
| 240 | + socket (io/file (options :unix-socket))] |
| 241 | + (.deleteOnExit socket) |
| 242 | + (doto (unix-domain-server-connector server http-factory) |
| 243 | + (.setUnixDomainPath (.toPath socket)) |
| 244 | + (.setIdleTimeout (options :max-idle-time 200000))))) |
| 245 | + |
232 | 246 | (defn- create-threadpool [options]
|
233 | 247 | (let [min-threads (options :min-threads 8)
|
234 | 248 | max-threads (options :max-threads 50)
|
|
253 | 267 | (.addConnector server (http-connector server options)))
|
254 | 268 | (when (or (options :ssl?) (options :ssl-port))
|
255 | 269 | (.addConnector server (ssl-connector server options)))
|
| 270 | + (when (options :unix-socket) |
| 271 | + (.addConnector server (unix-socket-connector server options))) |
256 | 272 | server))
|
257 | 273 |
|
258 | 274 | (defn run-jetty
|
|
266 | 282 | :async-timeout-handler - an async handler to handle an async context timeout
|
267 | 283 | :port - the port to listen on (defaults to 80)
|
268 | 284 | :host - the hostname to listen on
|
| 285 | + :unix-socket - the unix domain socket path to listen on |
269 | 286 | :join? - blocks the thread until server ends
|
270 | 287 | (defaults to true)
|
271 | 288 | :daemon? - use daemon threads (defaults to false)
|
|
0 commit comments