Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For 204 response the body should be empty... #321

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 13 additions & 1 deletion src/aleph/http/client_middleware.clj
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,17 @@
(-> (client req)
(d/chain' #(assoc % :request-time (- (System/currentTimeMillis) start)))))))

(defn wrap-204-empty-body
"Middleware which removes a body from a 204 request when the body is actually not there.
If the 204 response erroneously has a body with data, the body will be preserved."
[client]
(fn [req]
(-> (client req)
(d/chain' (fn [resp]
(if (and (= 204 (:status resp)) (= 0 (.available ^InputStream (:body resp))))
(dissoc resp :body)
resp))))))

(defn parse-content-type
"Parse `s` as an RFC 2616 media type."
[s]
Expand Down Expand Up @@ -637,7 +648,8 @@
[client]
(let [client' (-> client
wrap-exceptions
wrap-request-timing)]
wrap-request-timing
wrap-204-empty-body)]
(fn [req]
(let [executor (ex/executor)]
(if (:aleph.http.client/close req)
Expand Down