Skip to content

Commit

Permalink
StartSession cannot specify a specific session type anymore.
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Dec 24, 2024
1 parent a29bbf1 commit 7d599a3
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions sources/MVCFramework.pas
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ TWebContext = class
const AConfig: TMVCConfig; const ASerializers: TDictionary<string, IMVCSerializer>);
destructor Destroy; override;

procedure SessionStart(SessionType: String = ''); virtual;
procedure SessionStart; virtual;
procedure SessionStop(const ARaiseExceptionIfExpired: Boolean = True); virtual;

function SessionStarted: Boolean;
Expand Down Expand Up @@ -2387,9 +2387,13 @@ function TWebContext.GetWebSession: TMVCWebSession;
if not Assigned(FWebSession) then
begin
lSessionType := Config[TMVCConfigKey.SessionType];
if lSessionType.IsEmpty then
begin
raise EMVCException.Create('SessionType cannot be empty');
end;
if not TMVCSessionFactory.GetInstance.TryFindSessionID(lSessionType, lSessionIDFromRequest) then
begin
SessionStart(lSessionType);
SessionStart;
end
else
begin
Expand Down Expand Up @@ -2431,16 +2435,18 @@ function TWebContext.SessionMustBeClose: Boolean;
Result := FSessionMustBeClose;
end;

procedure TWebContext.SessionStart(SessionType: String);
procedure TWebContext.SessionStart;
var
ID: string;
SessionType: String;
begin
if not Assigned(FWebSession) then
begin
ID := TMVCEngine.SendSessionCookie(Self);
SessionType := Config[TMVCConfigKey.SessionType];
if SessionType.IsEmpty then
begin
SessionType := Config[TMVCConfigKey.SessionType];
SessionType := 'memory';
end;
FWebSession := AddSessionToTheSessionList(SessionType, ID,
StrToInt64(Config[TMVCConfigKey.SessionTimeout]));
Expand Down Expand Up @@ -3329,8 +3335,8 @@ procedure TMVCEngine.FillActualParamsForAction(const ASelectedController: TMVCCo
if not AContext.Request.SegmentParam(lParamName, lStrValue) then
begin
raise EMVCException.CreateFmt(http_status.BadRequest,
'Invalid parameter %s for action %s (Hint: Here parameters names are case-sensitive)',
[lParamName, AActionName]);
'Invalid parameter "%s" for action "%s" (Hint: Here parameters names are case-sensitive)',
[lParamName, AContext.ActionQualifiedName]);
end;
AActualParams[I] := GetActualParam(AActionFormalParams[I], lStrValue);
end;
Expand All @@ -3340,7 +3346,7 @@ procedure TMVCEngine.FillActualParamsForAction(const ASelectedController: TMVCCo
begin
raise EMVCException.CreateFmt(http_status.BadRequest,
'Parameters count mismatch (expected %d actual %d) for action "%s"',
[Length(AActionFormalParams), AContext.Request.SegmentParamsCount, AActionName]);
[Length(AActionFormalParams), AContext.Request.SegmentParamsCount, AContext.ActionQualifiedName]);
end;
end;

Expand Down

0 comments on commit 7d599a3

Please sign in to comment.