Skip to content

Commit 241a44b

Browse files
committed
Fail when attempting to enable h2c without enabling HTTP/2
1 parent 25355f8 commit 241a44b

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/aleph/http/server.clj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,10 +759,12 @@
759759
:http1-pipeline-transform http1-pipeline-transform
760760
:continue-executor continue-executor))]
761761

762-
(when (and (not ssl-context)
763-
(not use-h2c?)
764-
(some #{:http2} http-versions))
765-
(throw (IllegalArgumentException. "HTTP/2 requires ssl-context to be given or use-h2c? to be true.")))
762+
(if (some #{:http2} http-versions)
763+
(when (and (not ssl-context)
764+
(not use-h2c?))
765+
(throw (IllegalArgumentException. "HTTP/2 requires ssl-context to be given or use-h2c? to be true.")))
766+
(when use-h2c?
767+
(throw (IllegalArgumentException. "use-h2c? may only be true when HTTP/2 is enabled."))))
766768

767769
(when (and ssl-context
768770
use-h2c?)

test/aleph/http_test.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,4 +1416,10 @@
14161416
:http-versions [:http2]
14171417
:ssl-context test-ssl/server-ssl-context-opts})]
14181418
(is (instance? IllegalArgumentException result))
1419-
(is (= "use-h2c? must not be true when ssl-context is given." (ex-message result))))))
1419+
(is (= "use-h2c? must not be true when ssl-context is given." (ex-message result)))))
1420+
(testing "h2c without HTTP/2"
1421+
(let [result (try-start-server
1422+
{:use-h2c? true
1423+
:http-versions [:http1]})]
1424+
(is (instance? IllegalArgumentException result))
1425+
(is (= "use-h2c? may only be true when HTTP/2 is enabled." (ex-message result))))))

0 commit comments

Comments
 (0)