Skip to content

Commit d69f7ae

Browse files
committed
Only allow force-h2c? when :http2 is present in http-versions
1 parent a84a672 commit d69f7ae

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/aleph/http.clj

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,17 @@
208208
control-period 60000
209209
middleware middleware/wrap-request
210210
max-queue-size 65536}}]
211-
(when (and (false? (:keep-alive? connection-options))
212-
(pos? (:idle-timeout connection-options 0)))
213-
(throw
214-
(IllegalArgumentException.
211+
(let [{:keys [keep-alive?
212+
idle-timeout
213+
http-versions
214+
force-h2c?]
215+
:or {idle-timeout 0}} connection-options]
216+
(when (and (false? keep-alive?) (pos? idle-timeout))
217+
(throw
218+
(IllegalArgumentException.
215219
":idle-timeout option is not allowed when :keep-alive? is explicitly disabled")))
220+
(when (and force-h2c? (not-any? #{:http2} http-versions))
221+
(throw (IllegalArgumentException. "force-h2c? may only be true when HTTP/2 is enabled."))))
216222

217223
(let [log-activity (:log-activity connection-options)
218224
dns-options' (if-not (and (some? dns-options)

test/aleph/http_test.clj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,15 @@
16091609
{:connection-options
16101610
{:force-h2c? true
16111611
:http-versions [:http2]}})]
1612-
(is (= :success result)))))))
1612+
(is (= :success result))))
1613+
1614+
(testing "h2c without HTTP/2"
1615+
(let [result (try-request-with-pool
1616+
{:connection-options
1617+
{:force-h2c? true
1618+
:http-versions [:http1]}})]
1619+
(is (instance? IllegalArgumentException result))
1620+
(is (= "force-h2c? may only be true when HTTP/2 is enabled." (ex-message result))))))))
16131621

16141622

16151623
(deftest test-in-flight-request-cancellation

0 commit comments

Comments
 (0)