Cannot correctly return response with 204 status and persist connection
Opened this issue · 0 comments
OlegTheCat commented
(hunchentoot:define-easy-handler (return-empty-string :uri "/return-empty-string") ()
(setf (htt:return-code*) 204)
"")
(hunchentoot:define-easy-handler (return-nil :uri "/return-nil") ()
(setf (htt:return-code*) 204)
nil)
(hunchentoot:start (make-instance 'hunchentoot:easy-acceptor :port 4242))
The request to /return-empty-string
returns the following:
> (drakma:http-request
"http://localhost:4242/return-empty-string"
:method :GET
:keep-alive t :close nil)
NIL
204
((:CONTENT-LENGTH . "0") (:DATE . "Thu, 25 Oct 2018 14:46:51 GMT")
(:SERVER . "Hunchentoot 1.2.38") (:KEEP-ALIVE . "timeout=20")
(:CONNECTION . "Keep-Alive") (:CONTENT-TYPE . "text/html; charset=utf-8"))
#<PURI:URI http://localhost:4242/return-empty-string>
#<FLEXI-STREAMS:FLEXI-IO-STREAM {1001A7CE33}>
NIL
"No Content"
While it correctly returns NIL
as a response body and persists connection, it returns Content-Length
header, which violates the spec.
The request to /return-nil
returns the following:
> (drakma:http-request
"http://localhost:4242/return-nil"
:method :GET
:keep-alive t :close nil)
127.0.0.1 - [2018-10-25 14:49:59] "GET /return-nil HTTP/1.1" 204 - "-" "Drakma/2.0.4 (SBCL 1.4.6; Linux; 4.9.93-linuxkit-aufs; http://weitz.de/drakma/)"
""
204
((:DATE . "Thu, 25 Oct 2018 14:49:59 GMT") (:SERVER . "Hunchentoot 1.2.38")
(:CONNECTION . "Close") (:CONTENT-TYPE . "text/html"))
#<PURI:URI http://localhost:4242/return-nil>
#<FLEXI-STREAMS:FLEXI-IO-STREAM {1001AF29F3}>
T
"No Content"
It returns an empty string as a response body (which is kinda OK), also it correctly doesn't return Content-Length
header, but unfortunately closes the connection.
I'm not sure what's the correct way to achieve what I'm looking for, namely:
- the 204 response should not have
Content-Length
header - the server should persist the connection
- the body should be empty (either
NIL
or empty string)
Can you please advice?