FCL-Web package fix (sessions and web module request/response access)
Original Reporter info from Mantis: bobo
-
Reporter name: Attila Borka
Original Reporter info from Mantis: bobo
- Reporter name: Attila Borka
Description:
-
Web module (CGI and Apache) methods do not have access to the current Request and Response data structures.
Only the action event handlers are getting these passed to them.
This patch makes the Request and Response accessible (changes fpweb.pp), same as in Delphi -
When using sessions with Apache modules, some global session variables are not reset after a request is handled (with CGI it does not matter because CGI applications do not stay in memory like Apache modules do).
By adding a Resetvariables public procedure to the TIniWebSession object (websession.pp) and calling it from the HandleRequest method (fpweb.pp) this can be fixed.
---------------
Changes:
/packages/fcl-web/src/websession.pp
FROM
TIniWebSession = Class(TCustomSession)
.
.
.
Procedure RemoveVariable(VariableName : String); override;
end;
TO
TIniWebSession = Class(TCustomSession)
.
.
.
Procedure RemoveVariable(VariableName : String); override;
Procedure ResetVariables;
end;
Procedure TIniWebSession.ResetVariables;
begin //for apache module sequential calls these need to be reset
FSessionStarted := false;
FTerminated := false;
SID := '';
end;
-----------------
/packages/fcl-web/src/fpweb.pp
FROM
TCustomFPWebModule = Class(TSessionHTTPModule)
.
.
.
FTemplateVars : TTemplateVars;
.
.
.
Property OnTemplateContent : TGetParamEvent Read FOnGetParam Write FOnGetParam;
end;
TO
TCustomFPWebModule = Class(TSessionHTTPModule)
.
.
.
FTemplateVars : TTemplateVars;
FRequest : TRequest;
FResponse : TResponse;
.
.
.
Property OnTemplateContent : TGetParamEvent Read FOnGetParam Write FOnGetParam;
Property Request: TRequest Read FRequest;
Property Response: TResponse Read FResponse;
end;
AND FROM
procedure TCustomFPWebModule.HandleRequest(ARequest: TRequest; AResponse: TResponse);
.
.
.
CheckSession(ARequest);
.
.
.
UpdateSession(AResponse);
.
.
.
end;
TO
procedure TCustomFPWebModule.HandleRequest(ARequest: TRequest; AResponse: TResponse);
.
.
.
FRequest := ARequest; //So everything in the web module can access the current request variables
FResponse := AResponse;//So everything in the web module can access the current response variables
If CreateSession and Assigned(Session) then
TFPWebSession(Session).ResetVariables;//Initialize some variables that might have been changed from previous Apache requests
CheckSession(ARequest);
.
.
.
UpdateSession(AResponse);
FRequest := nil; //Reset for the next call, needed for apache modules
FResponse := nil;//Reset for the next call, needed for apache modules
.
.
.
end;
Additional information:
Goes together with
http://bugs.freepascal.org/view.php?id=13228
http://bugs.freepascal.org/view.php?id=13250
http://bugs.freepascal.org/view.php?id=13251
http://bugs.freepascal.org/view.php?id=13254
http://bugs.freepascal.org/view.php?id=13280