Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/yada/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
(and (not (contains? data :body)) (:response custom-response))
(custom-error (:response custom-response) rep)

true set-content-length)
(not (= :head (:method ctx))) set-content-length)

(:error-interceptor-chain ctx)

Expand Down
5 changes: 2 additions & 3 deletions src/yada/methods.clj
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,10 @@
(request [this ctx]

(when-not (ctx/exists? ctx)
(d/error-deferred (ex-info "" {:status 404})))
(throw (ex-info "" {:status 404})))

(when-not (get-in ctx [:response :produces])
(d/error-deferred
(ex-info "" {:status 406})))
(throw (ex-info "" {:status 406})))

;; HEAD is implemented without delegating to the resource.

Expand Down
20 changes: 18 additions & 2 deletions test/yada/head_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(ns yada.head-test
(:require
[clojure.test :refer :all]
[ring.mock.request :refer [request]]
[ring.mock.request :as ring-mock]
[yada.handler :refer [handler]]
[yada.resource :refer [as-resource]]))

Expand All @@ -12,7 +12,7 @@
h (handler (merge (as-resource resource)
{:produces {:media-type "text/plain"
:charset "UTF-8"}}))
request (request :head "/")
request (ring-mock/request :head "/")
response @(h request)
headers (:headers response)]

Expand All @@ -22,3 +22,19 @@
(is (nil? (get headers "content-length"))) ; see rfc7231.html#section-3.3

(is (nil? (:body response)))))

(deftest head-content-type-not-unacceptable-test []
(let [h (handler (merge (as-resource "Hello World!")
{:produces {:media-type "text/plain"
:charset "UTF-8"}}))
request (-> (ring-mock/request :head "/")
(ring-mock/header :accept "text/foo"))
response @(h request)
headers (:headers response)]

(is (= 406 (:status response)))
(is (nil? (get headers "content-type")))

(is (nil? (get headers "content-length"))) ; see rfc7231.html#section-3.3

(is (nil? (:body response)))))