Skip to content

Commit 5a52883

Browse files
Don't discard body for HEAD requests. (#615)
Fixes #614
1 parent c960a6a commit 5a52883

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/clj_http/core.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@
391391
(getMethod [] (.toUpperCase (name method) Locale/ROOT)))
392392
(.setURI (URI. url)))))
393393

394+
(def proxy-head-with-body (make-proxy-method-with-body :head))
394395
(def proxy-delete-with-body (make-proxy-method-with-body :delete))
395396
(def proxy-get-with-body (make-proxy-method-with-body :get))
396397
(def proxy-copy-with-body (make-proxy-method-with-body :copy))
@@ -413,7 +414,9 @@
413414
:get (if body
414415
(proxy-get-with-body http-url)
415416
(HttpGet. http-url))
416-
:head (HttpHead. http-url)
417+
:head (if body
418+
(proxy-head-with-body http-url)
419+
(HttpHead. http-url))
417420
:put (HttpPut. http-url)
418421
:post (HttpPost. http-url)
419422
:options (HttpOptions. http-url)

test/clj_http/test/core_test.clj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@
104104
{:status 200 :body "delete-with-body"}
105105
[:post "/multipart"]
106106
{:status 200 :body (:body req)}
107+
[:head "/head-with-body"]
108+
{:status 200 :headers {"body" (slurp (:body req))}}
107109
[:get "/get-with-body"]
108110
{:status 200 :body (:body req)}
109111
[:options "/options"]
@@ -412,8 +414,10 @@
412414

413415
(deftest ^:integration head-with-body
414416
(run-server)
415-
(let [resp (request {:request-method :head :uri "/head" :body "foo"})]
416-
(is (= 200 (:status resp)))))
417+
(let [resp (request {:request-method :head :uri "/head-with-body"
418+
:body (.getBytes "foo")})]
419+
(is (= 200 (:status resp)))
420+
(is (= "foo" (get-in resp [:headers "body"])))))
417421

418422
(deftest ^:integration t-clojure-output-coercion
419423
(run-server)

0 commit comments

Comments
 (0)