Hi Jan and happy 2024
My GIT search had some hidden results and I can now see that http:request_expansion/2 does indeed call http_session/3. But as far as I can tell, valid_session_id/2 is called only when session/1 is NOT in the Request. The other place valid_session_id/2 is called is in http_in_session/1,2 but again only when session/1 is not in the Request.
I wrote a simple server to try and see what’s going on. With this server, the session never times out and weirdly the idle time never exceeds 10 seconds even though I’ve set the timeout to 60 seconds. I expected to see the idle time get close to zero if I repeatedly and quickly hit the button but it just climbs up to about 10 seconds then goes back to zero. My program prints out the request session_id which seems always to be present in Request which means valid_session_id/2 never gets called and so the session never gets expired.
?- start_server.
% Started server at http://localhost:8080/
true.
?-
[Thread httpd@8080_2] Created session '67d4-f7a3-f754-2de5.MEE-Windows-PC' at path=/
request_session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC)
[Thread httpd@8080_2] Session id from global variable: ‘67d4-f7a3-f754-2de5.MEE-Windows-PC’
session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC) idle(1.8109769821166992)
request_session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC)
[Thread httpd@8080_3] Session id from global variable: '67d4-f7a3-f754-2de5.MEE-Windows-PC'
session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC) idle(2.4468560218811035)
request_session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC)
[Thread httpd@8080_2] Session id from global variable: ‘67d4-f7a3-f754-2de5.MEE-Windows-PC’
session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC) idle(3.0006749629974365)
request_session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC)
[Thread httpd@8080_1] Session id from global variable: '67d4-f7a3-f754-2de5.MEE-Windows-PC'
session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC) idle(3.534940004348755)
request_session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC)
[Thread httpd@8080_3] Session id from global variable: ‘67d4-f7a3-f754-2de5.MEE-Windows-PC’
session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC) idle(4.062686920166016)
request_session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC)
[Thread httpd@8080_2] Session id from global variable: '67d4-f7a3-f754-2de5.MEE-Windows-PC'
session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC) idle(4.598881959915161)
request_session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC)
[Thread httpd@8080_1] Session id from global variable: ‘67d4-f7a3-f754-2de5.MEE-Windows-PC’
session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC) idle(5.128626108169556)
request_session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC)
[Thread httpd@8080_3] Session id from global variable: '67d4-f7a3-f754-2de5.MEE-Windows-PC'
session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC) idle(5.639517068862915)
request_session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC)
[Thread httpd@8080_1] Session id from global variable: ‘67d4-f7a3-f754-2de5.MEE-Windows-PC’
session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC) idle(6.272963047027588)
request_session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC)
[Thread httpd@8080_3] Session id from global variable: '67d4-f7a3-f754-2de5.MEE-Windows-PC'
session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC) idle(6.944055080413818)
request_session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC)
[Thread httpd@8080_1] Session id from global variable: ‘67d4-f7a3-f754-2de5.MEE-Windows-PC’
session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC) idle(8.128846883773804)
request_session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC)
[Thread httpd@8080_2] Session id from global variable: '67d4-f7a3-f754-2de5.MEE-Windows-PC'
session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC) idle(1.319667100906372)
request_session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC)
[Thread httpd@8080_1] Session id from global variable: ‘67d4-f7a3-f754-2de5.MEE-Windows-PC’
session_id(67d4-f7a3-f754-2de5.MEE-Windows-PC) idle(3.7105391025543213)
Cheers
Mike
:- use_module(library(http/http_server)).
:- use_module(library(http/http_session)).
start_server :-
http_server([port(8080), timeout(60)]).
:- http_handler(root(.),
http_redirect(moved, location_by_id(home_page)),
[]).
:- http_handler(root(home), home_page, []).
:- debug(http_session).
home_page(_Request) :-
reply_html_page(
title('Session test server'),
\test_form).
test_form -->
html([form([action(button_pressed), method(post)],
input([type(submit), value('Submit')]))]).
:- http_handler(root(button_pressed), test_page, []).
test_page(Request) :-
( memberchk(session(Request_Session_ID), Request)
-> format(user_error, '~w~n', [request_session_id(Request_Session_ID)])
; format(user_error, 'No session ID in request~n', [])
),
( http_in_session(Session_ID)
-> http_current_session(Session_ID, idle(Idle)),
format(user_error, '~w ~w~n', [session_id(Session_ID), idle(Idle)])
; otherwise
-> format(user_error, 'No session~n', [])
),
reply_html_page(
title('Session test server'),
\test_form).
session_test.pl (1.17 KB)