-
Notifications
You must be signed in to change notification settings - Fork 120
Description
Hi,
I’m trying to follow the example, but the session doesn’t seem to persist correctly. Here’s the exact flow I’m testing:
step 1:
visitit "/"
-> click "Start the test"
Session started: (no error)
-> click "Check if it really was"
Session was started by OpenResty Fan (no error)
"The quick brown fox jumps over the lazy dog"
-> click "Modify session"
"Session was modified (no error)"
-> click Check if it modified
Session was started by Anonymous (invalid session message authentication code)
It seems like the session data is lost or reset after modification. Could this be a configuration issue? I’m using OpenResty 1.27.1.2.
OS: MacOS 14.5 (sonoma)
Browser: Safari
Thanks in advance.
Update 1
As says here #194, restoring to 4.0.5 solve the issue
Here my nginx.conf
worker_processes 1;
error_log stderr notice;
daemon off;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
init_by_lua_block {
require "lpeg"
require "resty.debug"
require "resty.session".init({
storage = "cookie",
cookie_path = "/",
cookie_name= "konektassid",
store_metadata = true,
secret = "RaJKp8UQW1",
secret_fallbacks = {
"X88FuG1AkY",
"fxWNymIpbb",
},
})
}
init_worker_by_lua_block {
local uuid = require("resty.jit-uuid")
uuid.seed()
}
lua_shared_dict sessions 10m;
lua_shared_dict sessions_locks 10m;
server {
listen 8080;
lua_code_cache off;
location / {
resolver 8.8.8.8;
default_type text/html;
set $_url "";
content_by_lua_block {
ngx.say([[
<html>
<body>
<a href=/start>Start the test</a>
</body>
</html>
]])
}
}
location /start {
default_type text/html;
content_by_lua_block {
local session = require "resty.session".new()
session:set_subject("OpenResty Fan")
session:set("quote", "The quick brown fox jumps over the lazy dog")
local ok, err = session:save()
ngx.say(string.format([[
<html>
<body>
<p>Session started: [ (%s) ]</p>
<p><a href=/started>Check if it really was</a></p>
</body>
</html>
]], err or "no error"))
}
}
location /started {
default_type text/html;
content_by_lua_block {
local session, err = require "resty.session".start()
ngx.say(string.format([[
<html>
<body>
<p>Session was started by %s (%s)</p>
<p><blockquote>"%s"</blockquote></p>
<p><a href=/modify>Modify the session</a></p>
</body>
</html>
]],
session:get_subject() or "Anonymous",
err or "no error",
session:get("quote") or "no quote"
))
}
}
location /modify {
default_type text/html;
content_by_lua_block {
local session, err = require "resty.session".start()
session:set_subject("Lua Fan")
session:set("quote", "Lorem ipsum dolor sit amet")
local _, err_save = session:save()
ngx.say(string.format([[
<html>
<body>
<p>Session was modified (%s)</p>
<p><a href=/modified>Check if it is modified</a></p>
</body>
</html>
]], err or err_save or "no error"))
}
}
location /modified {
default_type text/html;
content_by_lua_block {
local session, err = require "resty.session".start()
ngx.say(string.format([[
<html>
<body>
<p>Session was started by %s (%s)</p>
<p><blockquote>%s</blockquote></p>
<p><a href=/destroy>Destroy the session</a></p>
</body>
</html>
]],
session:get_subject() or "Anonymous",
err or "no error",
session:get("quote") or "no quote"
))
}
}
location /static/ {
alias static/;
}
location /favicon.ico {
alias static/favicon.ico;
}
}
}