Skip to content

Commit 1d9bca2

Browse files
committed
Always assert consistent ALPN config when SslContext is given
Given an SslContext object with a nil `applicationProtocolNegotiator` or nil `protocols`, we wouldn't have asserted the ALPN config to match the desired HTTP versions. In practice, this (currently) doesn't occur but let's be more obvious and future-proof. Also, break out the ssl-context = nil case for even more clarity!
1 parent 76ad767 commit 1d9bca2

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/aleph/http/common.clj

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
If `ssl-context` is nil, returns nil.
154154
155155
If `ssl-context` is an options map and it contains no `:application-protocol-config` key, a
156-
matching `:application-protocol-config` is added (based on `desired-http-versoins`)
156+
matching `:application-protocol-config` is added (based on `desired-http-versions`)
157157
158158
If `ssl-context` is an options map and it does contain an `:application-protocol-config` key, its
159159
supported protocols are validated to match `desired-http-versions`.
@@ -164,18 +164,26 @@
164164
(when-let [unsupported-http-versions (seq (remove supported-http-versions desired-http-versions))]
165165
(throw (ex-info "Unsupported desired HTTP versions"
166166
{:unsupported-http-versions unsupported-http-versions})))
167-
(if (map? ssl-context)
167+
(cond
168+
(map? ssl-context)
168169
(if-let [apc ^ApplicationProtocolConfig (:application-protocol-config ssl-context)]
169170
(do (assert-consistent-alpn-config! (.supportedProtocols apc) desired-http-versions)
170171
ssl-context)
171172
(assoc ssl-context
172173
:application-protocol-config
173174
(netty/application-protocol-config desired-http-versions)))
174-
(do (some-> ^SslContext ssl-context
175-
(.applicationProtocolNegotiator)
176-
(.protocols)
177-
(assert-consistent-alpn-config! desired-http-versions))
178-
ssl-context)))
175+
176+
(nil? ssl-context)
177+
nil
178+
179+
:else
180+
(do
181+
(assert-consistent-alpn-config!
182+
(some-> ^SslContext ssl-context
183+
(.applicationProtocolNegotiator)
184+
(.protocols))
185+
desired-http-versions)
186+
ssl-context)))
179187

180188
(defn validate-http1-pipeline-transform
181189
"Checks that :pipeline-transform is not being used with HTTP/2, since Netty

0 commit comments

Comments
 (0)