diff --git a/src/s_exp/hirundo/http/response.clj b/src/s_exp/hirundo/http/response.clj index 4735d26..e9d3824 100644 --- a/src/s_exp/hirundo/http/response.clj +++ b/src/s_exp/hirundo/http/response.clj @@ -33,4 +33,12 @@ [^ServerResponse server-response {:as response :keys [body headers status]}] (set-headers! server-response headers) (set-status! server-response status) - (write-body! server-response response body)) + (if body + (write-body! server-response response body) + (.send server-response))) + +(defn set-head-response! + [^ServerResponse server-response {:keys [headers status]}] + (set-headers! server-response headers) + (set-status! server-response status) + (.send server-response)) diff --git a/src/s_exp/hirundo/http/routing.clj b/src/s_exp/hirundo/http/routing.clj index 4ea13a2..66496c8 100644 --- a/src/s_exp/hirundo/http/routing.clj +++ b/src/s_exp/hirundo/http/routing.clj @@ -19,10 +19,12 @@ (into-array Handler [(reify Handler (handle [_ server-request server-response] - (let [response (handler (request/ring-request server-request server-response))] + (let [response (handler (request/ring-request server-request server-response)) + head? (= (.method (.prologue server-request)) io.helidon.http.Method/HEAD)] (cond->> response (map? response) - (response/set-response! server-response)))))])))))) + ((if head? response/set-head-response! response/set-response!) + server-response)))))])))))) (defmethod options/set-server-option! :http-handler [^WebServerConfig$Builder builder _ handler options] diff --git a/test/s_exp/hirundo_test.clj b/test/s_exp/hirundo_test.clj index a26159c..b19df66 100644 --- a/test/s_exp/hirundo_test.clj +++ b/test/s_exp/hirundo_test.clj @@ -85,7 +85,10 @@ (is (-> (client/get *endpoint*) :body (= "yes")))) (with-server {:http-handler (fn [req] {:body (java.io.ByteArrayInputStream. (.getBytes "yes"))})} - (is (-> (client/get *endpoint*) :body (= "yes"))))) + (is (-> (client/get *endpoint*) :body (= "yes")))) + + (with-server {:http-handler (fn [req] {:body (java.io.ByteArrayInputStream. (.getBytes "yes"))})} + (is (-> (client/head *endpoint*) :body nil?)))) (deftest resp-map-decoding (with-server {:http-handler (fn [req]