Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #15 from twosigma/ssl-ports-fix
Browse files Browse the repository at this point in the history
 enables HTTP if ssl? is enabled and ssl-port is provided
  • Loading branch information
pschorf committed Mar 15, 2019
2 parents 0d6366e + 3e53036 commit 82b5e2a
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions src/clj/qbits/jet/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ supplied options:
join? true
parser-compliance HttpCompliance/LEGACY
input-buffer-size 8192}}]
(let [ssl? (some? (or ssl? ssl-port))
pool (doto (QueuedThreadPool. (int max-threads)
(let [pool (doto (QueuedThreadPool. (int max-threads)
(int min-threads))
(.setDaemon daemon?))
server (doto (Server. pool)
Expand All @@ -219,30 +218,32 @@ supplied options:
http-connection-factory (doto (HttpConnectionFactory. http-conf)
(.setHttpCompliance (any->parser-compliance parser-compliance))
(.setInputBufferSize (int input-buffer-size)))
ssl-enabled? (some? (or ssl? ssl-port))
connectors (cond-> []
;; use HTTP if ssl is disabled or ssl is enabled and ssl-port is explicitly provided
(or (not ssl?)
(not (and ssl? ssl-port)))
(conj (doto (ServerConnector.
^Server server
^"[Lorg.eclipse.jetty.server.ConnectionFactory;"
(into-array ConnectionFactory
(cond-> [http-connection-factory]
http2c? (conj (HTTP2CServerConnectionFactory. http-conf)))))
(.setPort (or port 80))
(.setHost host)
(.setIdleTimeout max-idle-time)))
ssl?
(conj (doto (ServerConnector.
^Server server
(ssl-context-factory options)
^"[Lorg.eclipse.jetty.server.ConnectionFactory;"
(into-array ConnectionFactory
(cond-> [http-connection-factory]
http2? (conj (HTTP2ServerConnectionFactory. http-conf)))))
(.setPort (or ssl-port port 443))
(.setHost host)
(.setIdleTimeout max-idle-time))))]
;; use HTTP if ssl is disabled or
;; ssl is explicitly enabled and ssl-port is explicitly provided
(or (not ssl-enabled?)
(and ssl? ssl-port))
(conj (doto (ServerConnector.
^Server server
^"[Lorg.eclipse.jetty.server.ConnectionFactory;"
(into-array ConnectionFactory
(cond-> [http-connection-factory]
http2c? (conj (HTTP2CServerConnectionFactory. http-conf)))))
(.setPort (or port 80))
(.setHost host)
(.setIdleTimeout max-idle-time)))
ssl-enabled?
(conj (doto (ServerConnector.
^Server server
(ssl-context-factory options)
^"[Lorg.eclipse.jetty.server.ConnectionFactory;"
(into-array ConnectionFactory
(cond-> [http-connection-factory]
http2? (conj (HTTP2ServerConnectionFactory. http-conf)))))
(.setPort (or ssl-port port 443))
(.setHost host)
(.setIdleTimeout max-idle-time))))]
(when (empty? connectors)
(throw (IllegalStateException. "No connectors found! HTTP port or SSL must be configured!")))
(.setConnectors server (into-array Connector connectors))
Expand Down

0 comments on commit 82b5e2a

Please sign in to comment.