Skip to content

Commit 0319133

Browse files
authored
Merge pull request #409 from kachayev/fix-trace-body
A client MUST NOT send a message body in a TRACE request
2 parents 02dd416 + d269e55 commit 0319133

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/aleph/http/client.clj

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,22 @@
486486
(not (.get (.headers req') "Proxy-Connection")))
487487
(.set (.headers req') "Proxy-Connection" "Keep-Alive"))
488488

489-
(let [parts (:multipart req)
490-
[req' body] (if (nil? parts)
491-
[req' (:body req)]
489+
(let [body (:body req)
490+
parts (:multipart req)
491+
multipart? (some? parts)
492+
[req' body] (cond
493+
;; RFC #7231 4.3.8. TRACE
494+
;; A client MUST NOT send a message body...
495+
(= :trace (:request-method req))
496+
(do
497+
(when (or (some? body) multipart?)
498+
(log/warn "TRACE request body was omitted"))
499+
[req' nil])
500+
501+
(not multipart?)
502+
[req' body]
503+
504+
:else
492505
(multipart/encode-request req' parts))]
493506

494507
(when-let [save-message (get req :aleph/save-request-message)]

test/aleph/http_test.clj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,16 @@
343343
(let [rsp (http/get (str "http://localhost:" port) {:connection-pool pool})]
344344
(is (= http/default-response-executor (.executor rsp))))))))
345345

346+
(defn echo-handler [req]
347+
{:status 200
348+
:body (:body req)})
349+
350+
(deftest test-trace-request-omitted-body
351+
(with-handler echo-handler
352+
(is (= "" (-> @(http/trace (str "http://localhost:" port) {:body "REQUEST"})
353+
:body
354+
bs/to-string)))))
355+
346356
;;;
347357

348358
(defn get-netty-client-event-threads []

0 commit comments

Comments
 (0)