fix: set correctly request->session
The session cookie was not created because request->session pointed at a temporary session. While here: - do some cleaning in App - set request->mount too - add fcgi_cannot_create_request_delay to the config - fix: in mailregister plugin get model_connector from env (and not from the request)
This commit is contained in:
@@ -98,7 +98,7 @@ App::App()
|
||||
config.SetFileLog(&file_log);
|
||||
config.SetLogBuffer(&log_buffer);
|
||||
|
||||
cur.request = nullptr;
|
||||
cur.request = nullptr; // they are first set in App::Init()
|
||||
cur.session = nullptr;
|
||||
cur.mount = nullptr;
|
||||
|
||||
@@ -352,6 +352,12 @@ bool App::InitializePlugins()
|
||||
|
||||
bool App::Init()
|
||||
{
|
||||
cur.session = session_manager.GetTmpSession();
|
||||
cur.mount = system.mounts.GetEmptyMount();;
|
||||
system.req_tab.resize(1);
|
||||
cur.request = &system.req_tab.back();
|
||||
InitializeNewRequest(*cur.request); // this will set cur.request->session (from cur.session) and cur.request->mount (from cur.mount)
|
||||
|
||||
if( !config.db_conn_string.empty() )
|
||||
postgresql_connector.set_conn_param(config.db_conn_string);
|
||||
else
|
||||
@@ -617,9 +623,10 @@ void App::MakeRenameMeToABetterName()
|
||||
cur.request->item.set_connector(model_connector);
|
||||
|
||||
cur.session = session_manager.PrepareSession();
|
||||
cur.request->session = cur.session;
|
||||
model_connector.set_winix_session(cur.session);
|
||||
|
||||
functions.CheckFunctionAndSymlink(); // here a function can be changed
|
||||
functions.CheckFunctionAndSymlink(); // here a function can be changed (and mount point but cur.mount and cur->request->mount will be set)
|
||||
|
||||
if( cur.request->function )
|
||||
{
|
||||
@@ -628,6 +635,7 @@ void App::MakeRenameMeToABetterName()
|
||||
}
|
||||
|
||||
cur.session = session_manager.CheckIfFunctionRequireSession();
|
||||
cur.request->session = cur.session;
|
||||
model_connector.set_winix_session(cur.session);
|
||||
|
||||
SetLocale();
|
||||
@@ -736,6 +744,7 @@ void App::ProcessRequestThrow()
|
||||
}
|
||||
|
||||
cur.mount = system.mounts.CalcCurMount(cur.request);
|
||||
cur.request->mount = cur.mount;
|
||||
|
||||
if( cur.mount->type != system.mounts.MountTypeStatic() )
|
||||
{
|
||||
@@ -811,20 +820,20 @@ void App::ClearAfterRequest()
|
||||
}
|
||||
|
||||
|
||||
bool App::InitializeRequestForFastCGI()
|
||||
bool App::InitializeRequestForFastCGI(Request & request)
|
||||
{
|
||||
bool request_initialized = false;
|
||||
|
||||
while( !synchro.was_stop_signal && !request_initialized )
|
||||
{
|
||||
if( FCGX_InitRequest(&cur.request->fcgi_request, fcgi_socket, FCGI_FAIL_ACCEPT_ON_INTR) == 0 )
|
||||
if( FCGX_InitRequest(&request.fcgi_request, fcgi_socket, FCGI_FAIL_ACCEPT_ON_INTR) == 0 )
|
||||
{
|
||||
request_initialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "App: FCGX_InitRequest fails, I cannot read a new request, I wait 3s and will try again..." << logend << logsave;
|
||||
sleep(3); // IMPROVEME put me to config
|
||||
sleep(config.fcgi_cannot_create_request_delay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -832,44 +841,30 @@ bool App::InitializeRequestForFastCGI()
|
||||
}
|
||||
|
||||
|
||||
void App::SetRequestDependency()
|
||||
void App::SetRequestDependency(Request & request)
|
||||
{
|
||||
cur.request->SetConfig(&config);
|
||||
cur.request->SetTemplates(&templates);
|
||||
cur.request->SetCompress(&compress);
|
||||
cur.request->SetPlugin(&plugin);
|
||||
cur.request->SetMounts(&system.mounts);
|
||||
request.SetConfig(&config);
|
||||
request.SetTemplates(&templates);
|
||||
request.SetCompress(&compress);
|
||||
request.SetPlugin(&plugin);
|
||||
request.SetMounts(&system.mounts);
|
||||
|
||||
cur.request->session = cur.session;
|
||||
cur.request->mount = cur.mount;
|
||||
request.session = cur.session;
|
||||
request.mount = cur.mount;
|
||||
|
||||
cur.request->set_connector(&model_connector);
|
||||
cur.request->item.set_connector(&model_connector);
|
||||
request.set_connector(&model_connector);
|
||||
request.item.set_connector(&model_connector);
|
||||
}
|
||||
|
||||
|
||||
void App::InitializeNewRequest()
|
||||
void App::InitializeNewRequest(Request & request)
|
||||
{
|
||||
SetRequestDependency();
|
||||
cur.request->Clear(); // IMPROVE ME what about an 'id' in request? it should be unique?
|
||||
InitializeRequestForFastCGI();
|
||||
SetRequestDependency(request);
|
||||
request.Clear();
|
||||
InitializeRequestForFastCGI(request);
|
||||
}
|
||||
|
||||
|
||||
// use with lock/unlock
|
||||
void App::PrepareRequest()
|
||||
{
|
||||
Winix::Lock lock(synchro);
|
||||
|
||||
if( system.req_tab.empty() )
|
||||
{
|
||||
system.req_tab.resize(1);
|
||||
}
|
||||
|
||||
cur.request = &system.req_tab.back();
|
||||
InitializeNewRequest();
|
||||
}
|
||||
|
||||
|
||||
void App::PutRequestToJob()
|
||||
{
|
||||
@@ -903,12 +898,6 @@ void App::Start()
|
||||
{
|
||||
Winix::Lock lock(synchro);
|
||||
was_stop_signal = synchro.was_stop_signal;
|
||||
}
|
||||
|
||||
PrepareRequest();
|
||||
|
||||
{
|
||||
Winix::Lock lock(synchro);
|
||||
fcgi_request = &cur.request->fcgi_request;
|
||||
}
|
||||
|
||||
@@ -960,7 +949,7 @@ void App::Start()
|
||||
*/
|
||||
system.req_tab.resize(system.req_tab.size() + 1);
|
||||
cur.request = &system.req_tab.back();
|
||||
InitializeNewRequest();
|
||||
InitializeNewRequest(*cur.request); // cur.request->session, cur.request->mount, cur.request->id etc. are set when the request starts
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user