Le 01/03/2017 à 20:35, Amirouche a écrit :
Le 23/02/2016 à 17:57, Arne Babenhauserheide a écrit :
That said I have an issue with registration/login
stuff anything related with setting cookies I don't find a good abstraction,
for it.

I keep you posted.

So I found a solution that satisfy me. Here is it:

(define (pair->set-cookie item)
  `(Set-Cookie . ,(string-append (symbol->string (car item))
                                 "="
                                 (cadr item))))

(define (sxml->set-cookies sxml)
  (match sxml
    ((('doctype doctype)
      ('html ('@ . options) . rest))
      (map pair->set-cookie options))
     (_ '())))

(define (sxml->response sxml)
  (let ((set-cookies (sxml->set-cookies sxml)))
    (values `((content-type . (text/html)) ,@set-cookies)
              (lambda (port)
                (sxml->html sxml port)))))

;;; handler

(define (handler request body)
  (sxml->response `((doctype "html")
                    (html
                     (body "echo")))))

(format #t "Héllo! Go to http://localhost:8080\n";)
  (run-server handler))


amz3

Reply via email to