Skip to content

Commit

Permalink
Merge pull request #50 from 40ants/change-status-code
Browse files Browse the repository at this point in the history
Allow to change status code using REBLOCKS/RESPONE:STATUS-CODE function.
  • Loading branch information
svetlyak40wt authored Jan 13, 2024
2 parents 09563a9 + 84b7fd1 commit 29d04b2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/doc/changelog.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
"REBLOCKS/SESSION:INIT")
:external-links (("Ultralisp" . "https://ultralisp.org"))
:external-docs ("https://40ants.com/log4cl-extras/"))
(0.58.0 2024-01-13
"""
Added
=====
A new function REBLOCKS/RESPONSE:STATUS-CODE was added as a replacement to REBLOCKS/RESPONSE:GET-CODE.
The new function is setfable. Now you can change HTTP status code of the currently rendered page.
This is especially helpful when rendering \"Not found\" or error pages.
""")
(0.57.0 2024-01-08
"""
Added
Expand Down
11 changes: 8 additions & 3 deletions src/doc/response.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

(defsection @response (:title "Response"
:ignore-words ("URL"
"SETF"
"AJAX"
"HTTP"))
(@best-practice section)
Expand Down Expand Up @@ -47,10 +48,10 @@
(defsection @api (:title "API")
(reblocks/response:add-header function)
(reblocks/response:add-retpath-to function)
(reblocks/response:get-code function)

(reblocks/response:status-code function)
(reblocks/response:get-content function)
(reblocks/response:get-content-type function)
(reblocks/response:get-custom-headers function)
(reblocks/response:get-headers function)
(reblocks/response:set-cookie function)
(reblocks/response:cookies-to-set function)
Expand All @@ -60,4 +61,8 @@
(reblocks/response:immediate-response condition)
(reblocks/response:make-response function)
(reblocks/response:make-uri function)
(reblocks/response:send-script function))
(reblocks/response:send-script function)

"# Deprecated"
(reblocks/response:get-code function)
(reblocks/response:get-custom-headers function))
25 changes: 24 additions & 1 deletion src/response.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
#:get-content-type
#:add-retpath-to
#:set-cookie
#:cookies-to-set))
#:cookies-to-set
#:status-code))
(in-package #:reblocks/response)


Expand All @@ -62,15 +63,37 @@


(defun get-custom-headers (&optional (response *response*))
"Function GET-CUSTOM-HEADERS is deprecated. Use GET-HEADERS instead."
(check-type response lack.response:response)
;; TODO: remove this function after "2023-05-01"
(log:warn "Function GET-CUSTOM-HEADERS is deprecated. Use GET-HEADERS instead.")
(lack.response:response-headers response))


(defun get-code (&optional (response *response*))
"Function GET-CODE is deprecated. Use STATUS-CODE instead."
;; TODO: remove this function after "2023-05-01"
(log:warn "Function GET-CODE is deprecated. Use STATUS-CODE instead.")
(lack.response:response-status response))


(defun status-code (&optional (response *response*))
"Returns a status code to be returned in response to the current request.
You can use SETF to change the status code:
```lisp
(setf (reblocks/response:status-code)
404)
```"
(lack.response:response-status response))


(defun (setf status-code) (value &optional (response *response*))
(setf (lack.response:response-status response)
value))


(defun get-content (&optional (response *response*))
(lack.response:response-body response))

Expand Down

0 comments on commit 29d04b2

Please sign in to comment.