Open
Description
When the server responds with no content, while using ring-response-format, a nil result is passed to :handler
instead of a map with :status
, :headers
, :body
keys. This happens when talking to a REST API with responses that return 204 no content.
Here is an example:
(defn test-code [code]
(ajax-request
{:method :get
:uri (str "https://httpbin.org/status/" code)
:format (ajax/text-request-format)
:response-format (ajax/ring-response-format
{:format (ajax/text-response-format)})
:handler (fn [result]
(println "Result:" result))}))
(test-code 204)
;; => Result: [true nil]
(test-code 201)
;; => Result: [true {:status 201, :headers {Date Sat, 24 Oct 2020 10:16:44 GMT, Content-Type text/html; charset=utf-8, Content-Length 0, Connection keep-alive, Server gunicorn/19.9.0, Access-Control-Allow-Origin *, Access-Control-Allow-Credentials true}, :body }]
The distinguishing factor seems to be that the server sends a "Content-Lengh: 0" for 201 and nothing for 204:
[joshua@pomelo:~]$ curl -v https://httpbin.org/status/204 2>&1 | grep content-length -i
[joshua@pomelo:~]$ curl -v https://httpbin.org/status/201 2>&1 | grep content-length -i
< content-length: 0
I think conceptually they should probably be treated the same giving a zero-length :body
for both.
Activity