Hi,
The initialization script for a postgres sessions table does not work for me. I need to remove the "engine=InnoDB" to create the table. Once created it will populate with session ids. I create a sessiontest.html.tpl file that looks like:
<html><head><title><%= (current-appname) %></title></head>
<body>
<h1>test#sessiontest</h1>
<p>Rendered from app/views/test/sessiontest.html.tpl.</p>
<%= check-value %>
</body>
</html>
where I will use the variable "check-value" to monitor session information. My controller test.scm:
(get "/sessiontest" #:session #t
(lambda (rc)
"<h1>This is test#sessiontest</h1><p>Find me in app/views/test/sessiontest.html.tpl</p>"
;; TODO: add controller method `sessiontest'
;; uncomment this line if you want to render view from template
(let* ((dummy (:session rc 'spawn))
(check-value "manual"))
(view-render "sessiontest" (the-environment) ))))
If I navigate to
http://127.0.0.1:3000/test/sessiontest I create the sid which is visible in the browser cookies console and in the database:
lndb=> select * from Sessions;
sid | data | expires | client | valid
----------------------------------+------+-------------------------------+-----------+-------
2f4836f4e7931ac27cc2396c6dad45ff | () | Sun, 01 Nov 2020 14:51:47 GMT | 127.0.0.1 | 1
(1 row)
The check-value text on the HTML page is "manual".
If I redefine sessiontest, attempts at retrieving the sid using cookies fail:
(get "/sessiontest" #:cookies '(names sid)
(lambda (rc)
"<h1>This is test#sessiontest</h1><p>Find me in app/views/test/sessiontest.html.tpl</p>"
;; TODO: add controller method `sessiontest'
;; uncomment this line if you want to render view from template
(let* ((check-value (:cookies-ref rc 'sid "sid"))
)
(view-render "sessiontest" (the-environment) ))
))
check-value on the HTML page is #f
The sid is present in the headers though:
((host "127.0.0.1" . 3000) (user-agent . "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0") (accept (text/html) (application/xhtml+xml) (application/xml (q . 900)) (*/* (q . 800))) (accept-language (1000 . "en-US") (500 . "en")) (accept-encoding (1000 . "gzip") (1000 . "deflate")) (cookie . "sid=2f4836f4e7931ac27cc2396c6dad45ff") (connection keep-alive) (upgrade-insecure-requests . "1") (if-modified-since . #<date nanosecond: 0 second: 8 minute: 11 hour: 14 day: 1 month: 11 year: 2020 zone-offset: 0>)) meta: () port: #<input-output: socket 25>>
In the above "/sessiontest" method if I substitute (:cookies-ref....) with (:cookies-set! rc 'sid "sid" "sometext") I can successfully change the sid value.
check-value on the HTML page is "((sid . sometext)) " and "sometext" is the value of sid in the cookie console.
Are there known issues with using Postgres as the sessions database?
Will dropping the "engine=InnoDB" during table creation cause problems? (I think that is MySQL specific)
Any advice on what I am doing wrong with :cookies-ref?
Thanks
Mortimer