Neaten up the blog site example
And fix some issues.
This commit is contained in:
parent
dd15e9306a
commit
0d1a31f4c7
4 changed files with 57 additions and 49 deletions
|
|
@ -11,6 +11,7 @@
|
|||
#:use-module (safsaf templating)
|
||||
#:use-module (safsaf utils)
|
||||
#:use-module (safsaf params)
|
||||
#:use-module (srfi srfi-71)
|
||||
#:use-module (web request)
|
||||
#:use-module (webutils multipart)
|
||||
#:export (make-blog-component))
|
||||
|
|
@ -420,19 +421,27 @@ PARTS and FORM are already-parsed multipart data."
|
|||
;;; to simulate PUT and DELETE.
|
||||
;;;
|
||||
|
||||
(define (request-content-type-is-multipart? request)
|
||||
"Return #t if REQUEST has a multipart/form-data content type."
|
||||
(let ((ct (request-content-type request)))
|
||||
(and ct (eq? (car ct) 'multipart/form-data))))
|
||||
|
||||
(define (post-actions request body-port)
|
||||
"Handle POST /posts/{id} — dispatches on _method form field.
|
||||
HTML forms cannot send PUT or DELETE directly, so they POST with a
|
||||
hidden _method field. This handler reads the body once, then delegates
|
||||
to the appropriate core operation. API clients should use PUT/DELETE
|
||||
directly instead."
|
||||
(let* ((parts (parse-multipart-body request body-port))
|
||||
(form (multipart-text-fields parts))
|
||||
(method (assoc-ref form "_method")))
|
||||
(cond
|
||||
((equal? method "PUT") (do-update-post request parts form))
|
||||
((equal? method "DELETE") (do-delete-post request))
|
||||
(else (bad-request-response)))))
|
||||
(let ((parts form (if (request-content-type-is-multipart? request)
|
||||
(let* ((parts (parse-multipart-body request body-port))
|
||||
(form (multipart-text-fields parts)))
|
||||
(values parts form))
|
||||
(values #f (parse-form-body request body-port)))))
|
||||
(let ((method (assoc-ref form "_method")))
|
||||
(cond
|
||||
((equal? method "PUT") (do-update-post request parts form))
|
||||
((equal? method "DELETE") (do-delete-post request))
|
||||
(else (bad-request-response))))))
|
||||
|
||||
;;;
|
||||
;;; Component constructor
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue