Skip to content

Commit 307c975

Browse files
Lift ssl-context coercion to connection-pool fn
As suggested by @DerGuteMoritz in clj-commons#728. This fixes the issue and makes the test added in the previous commit pass. Keeping the `client-ssl-context` call in `http-connection` as is, even though it might seem superfluous considering the code path taken in the test, but `http-connection` is a public API, so we have to keep the call (which for us is a no-op, if we ignore the repeated ALPN check) even for our case when the protocol is https and `ssl-context` is supplied. NOTE: This highlights a difference we are introducing here. Previously, if we specified ssl-context, but the protocol wasn't https, we would just ignore the ssl-context. Currently, we are coercing it ahead-of-time, before knowing the request protocol. This could be alleviated by wrapping the coercion in a `delay`, so it won't happen until needed. However, given how unlikely this scenario seems, I have doubts whether it'd be worth it. I slightly dislike the repetition of `[:http1]` default value, but since it server as a documentation in `http-connection`, I decided to keep it as is rather than to extract it out. Also, I slightly dislike the repetition of a pattern to call `ensure-consistent-alpn-config` and then `coerce-ssl-client-context` but it's only now in 2 places, which I think is a better alternative than adding yet another ssl-coercion layer/wrapping function. Obviously, we cannot just move `ensure-consistent-alpn-config` to `ssl-client-context`, since ALPN is only for HTTP.
1 parent 3e6fda1 commit 307c975

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/aleph/http.clj

+11-2
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@
228228
(when (and force-h2c? (not-any? #{:http2} http-versions))
229229
(throw (IllegalArgumentException. "force-h2c? may only be true when HTTP/2 is enabled."))))
230230

231-
(let [log-activity (:log-activity connection-options)
231+
(let [{:keys [log-activity
232+
ssl-context
233+
http-versions]
234+
:or {http-versions [:http1]}} connection-options
232235
dns-options' (if-not (and (some? dns-options)
233236
(not (or (contains? dns-options :transport)
234237
(contains? dns-options :epoll?))))
@@ -241,7 +244,13 @@
241244
(assoc :name-resolver (netty/dns-resolver-group dns-options'))
242245

243246
(some? log-activity)
244-
(assoc :log-activity (netty/activity-logger "aleph-client" log-activity)))
247+
(assoc :log-activity (netty/activity-logger "aleph-client" log-activity))
248+
249+
(some? ssl-context)
250+
(update :ssl-context
251+
#(-> %
252+
(common/ensure-consistent-alpn-config http-versions)
253+
(netty/coerce-ssl-client-context))))
245254
p (promise)
246255
create-pool-fn (or pool-builder-fn
247256
flow/instrumented-pool)

0 commit comments

Comments
 (0)