Skip to content

Commit 20b9e14

Browse files
committed
Document and test default ALPN failure behavior config
1 parent 774fa17 commit 20b9e14

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/aleph/netty.clj

+10-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,16 @@
938938
"Creates a default config for Application-Layer Protocol Negotiation (ALPN),
939939
which TLS uses to negotiate which HTTP version to use during the handshake.
940940
941-
Takes a vector of HTTP versions, in order of preference. E.g., `[:http2 :http1]`"
941+
Takes a vector of HTTP versions, in order of preference. E.g., `[:http2 :http1]`
942+
943+
Note that the returned config uses `SelectorFailureBehavior.NO_ADVERTISE`[1] and
944+
`SelectedListenerFailureBehavior.ACCEPT`[2] since these are the only failure behaviors
945+
supported by all SSL providers. See their documentation for details. One important
946+
consequence of this is that it's not possible to completely opt out of HTTP/1.1 by way of
947+
only specifying `[:http2]`.
948+
949+
1: https://netty.io/4.1/api/io/netty/handler/ssl/ApplicationProtocolConfig.SelectorFailureBehavior.html#NO_ADVERTISE
950+
2: https://netty.io/4.1/api/io/netty/handler/ssl/ApplicationProtocolConfig.SelectedListenerFailureBehavior.html#ACCEPT"
942951
^ApplicationProtocolConfig
943952
[protocols]
944953
(ApplicationProtocolConfig.

test/aleph/http_test.clj

+21
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,27 @@
16191619
(is (instance? IllegalArgumentException result))
16201620
(is (= "force-h2c? may only be true when HTTP/2 is enabled." (ex-message result))))))))
16211621

1622+
(deftest http2-only-client-connecting-to-http1-only-server
1623+
(testing "No ALPN config, desiring only HTTP/2 but the server only allows HTTP/1"
1624+
(with-http1-server echo-handler http1-ssl-server-options
1625+
(with-redefs [*use-tls-requests* true]
1626+
(let [result (try-request-with-pool
1627+
{:connection-options
1628+
{:http-versions [:http2]
1629+
:ssl-context test-ssl/client-ssl-context-opts}})]
1630+
(is (= :success result) "succeeds due to the default failure behaviors (see docstring of `application-protocol-config`)"))))))
1631+
1632+
1633+
(deftest http1-only-client-connecting-to-http2-only-server
1634+
(testing "No ALPN config, desiring only HTTP/1.1 but the server only allows HTTP/2"
1635+
(with-http2-server echo-handler {}
1636+
(with-redefs [*use-tls-requests* true]
1637+
(let [result (try-request-with-pool
1638+
{:connection-options
1639+
{:http-versions [:http1]
1640+
:ssl-context test-ssl/client-ssl-context-opts}})]
1641+
(is (= :success result) "succeeds due to the default failure behaviors (see docstring of `application-protocol-config`)"))))))
1642+
16221643

16231644
(deftest test-in-flight-request-cancellation
16241645
(let [conn-established (promise)

0 commit comments

Comments
 (0)