-
Notifications
You must be signed in to change notification settings - Fork 517
/
head.clj
32 lines (28 loc) · 879 Bytes
/
head.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(ns ring.middleware.head
"Middleware to simplify replying to HEAD requests.
A response to a HEAD request should be identical to a GET request, with the
exception that a response to a HEAD request should have an empty body.")
(defn head-request
"Turns a HEAD request into a GET."
{:added "1.2"}
[request]
(if (= :head (:request-method request))
(assoc request :request-method :get)
request))
(defn head-response
"Returns a nil body if original request was a HEAD."
{:added "1.2"}
[response request]
(if (and response (= :head (:request-method request)))
(assoc response :body nil)
response))
(defn wrap-head
"Middleware that turns any HEAD request into a GET, and then sets the response
body to nil."
{:added "1.1"}
[handler]
(fn [request]
(-> request
head-request
handler
(head-response request))))