diff options
author | michael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2011-06-04 13:20:25 +0000 |
---|---|---|
committer | michael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2011-06-04 13:20:25 +0000 |
commit | 550eb93d3e6e85c5b0a154af02b6b2ba07808299 (patch) | |
tree | dbd5f419496ad4057552e7b2e820bf1654216bf7 /packages/fcl-web | |
parent | 8a5acd535334a1ae3fd529258db68cb5b3722aeb (diff) | |
download | fpc-550eb93d3e6e85c5b0a154af02b6b2ba07808299.tar.gz |
* Moved session cookie up in the class hierarchie, so it can be configured at the session factory level
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@17653 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/fcl-web')
-rw-r--r-- | packages/fcl-web/src/base/fphttp.pp | 15 | ||||
-rw-r--r-- | packages/fcl-web/src/base/httpdefs.pp | 36 | ||||
-rw-r--r-- | packages/fcl-web/src/base/iniwebsession.pp | 9 |
3 files changed, 47 insertions, 13 deletions
diff --git a/packages/fcl-web/src/base/fphttp.pp b/packages/fcl-web/src/base/fphttp.pp index f2cf5929b7..ccff8a275e 100644 --- a/packages/fcl-web/src/base/fphttp.pp +++ b/packages/fcl-web/src/base/fphttp.pp @@ -147,6 +147,8 @@ Type TSessionFactory = Class(TComponent) private + FSessionCookie: String; + FSessionCookiePath: String; FTimeOut: Integer; FCleanupInterval: Integer; FDoneCount: Integer; @@ -167,6 +169,10 @@ Type Property CleanupInterval : Integer read FCleanupInterval Write FCleanUpInterval; // Default timeout for sessions, in minutes. Property DefaultTimeOutMinutes : Integer Read FTimeOut Write FTimeOut; + // Default session cookie. + property SessionCookie : String Read FSessionCookie Write FSessionCookie; + // Default session cookie path + Property SessionCookiePath : String Read FSessionCookiePath write FSessionCookiePath; end; TSessionFactoryClass = Class of TSessionFactory; @@ -242,8 +248,13 @@ end; function TSessionFactory.CreateSession(ARequest: TRequest): TCustomSession; begin Result:=DoCreateSession(ARequest); - if (FTimeOut<>0) and Assigned(Result) then - Result.TimeoutMinutes:=FTimeOut; + if Assigned(Result) then + begin + if (FTimeOut<>0) then + Result.TimeoutMinutes:=FTimeOut; + Result.SessionCookie:=Self.SessionCookie; + Result.SessionCookiePath:=Self.SessionCookiePath; + end; end; procedure TSessionFactory.DoneSession(var ASession: TCustomSession); diff --git a/packages/fcl-web/src/base/httpdefs.pp b/packages/fcl-web/src/base/httpdefs.pp index 8f1059abde..b1942caa79 100644 --- a/packages/fcl-web/src/base/httpdefs.pp +++ b/packages/fcl-web/src/base/httpdefs.pp @@ -32,6 +32,9 @@ interface uses Classes,Sysutils; const + DefaultTimeOut = 15; + SFPWebSession = 'FPWebSession'; // Cookie name for session. + fieldAccept = 'Accept'; fieldAcceptCharset = 'Accept-Charset'; fieldAcceptEncoding = 'Accept-Encoding'; @@ -355,9 +358,16 @@ type TCustomSession = Class(TComponent) Private + FSessionCookie: String; + FSessionCookiePath: String; FTimeOut: Integer; Protected + // Can be overridden to provide custom behaviour. + procedure SetSessionCookie(const AValue: String); virtual; + procedure SetSessionCookiePath(const AValue: String); virtual; + // When called, generates a new GUID. Override to retrieve GUID from cookie/URL/... Function GetSessionID : String; virtual; + // These must be overridden to actually store/retrieve variables. Function GetSessionVariable(VarName : String) : String; Virtual; abstract; procedure SetSessionVariable(VarName : String; const AValue: String);Virtual;abstract; Public @@ -368,10 +378,19 @@ type Procedure InitResponse(AResponse : TResponse); virtual; // Update response from session (typically, change cookie to response and write session data). Procedure UpdateResponse(AResponse : TResponse); virtual; Abstract; + // Remove variable from list of variables. Procedure RemoveVariable(VariableName : String); virtual; abstract; + // Terminate session Procedure Terminate; virtual; abstract; - Property TimeOutMinutes : Integer Read FTimeOut Write FTimeOut; + // Session timeout in minutes + Property TimeOutMinutes : Integer Read FTimeOut Write FTimeOut default 15; + // ID of this session. Property SessionID : String Read GetSessionID; + // Name of cookie used when tracing session. (may or may not be used) + property SessionCookie : String Read FSessionCookie Write SetSessionCookie; + // Path of cookie used when tracing session. (may or may not be used) + Property SessionCookiePath : String Read FSessionCookiePath write SetSessionCookiePath; + // Variables, tracked in session. Property Variables[VarName : String] : String Read GetSessionVariable Write SetSessionVariable; end; @@ -1709,6 +1728,16 @@ end; { TCustomSession } +procedure TCustomSession.SetSessionCookie(const AValue: String); +begin + FSessionCookie:=AValue; +end; + +procedure TCustomSession.SetSessionCookiePath(const AValue: String); +begin + FSessionCookiePath:=AValue; +end; + function TCustomSession.GetSessionID: String; Var @@ -1722,7 +1751,7 @@ end; constructor TCustomSession.Create(AOwner: TComponent); begin - FTimeOut:=15; + FTimeOut:=DefaultTimeOut; inherited Create(AOwner); end; @@ -1731,7 +1760,8 @@ begin // do nothing end; -procedure TCustomSession.InitSession(ARequest: TRequest; OnNewSession,OnExpired : TNotifyEvent); +procedure TCustomSession.InitSession(ARequest: TRequest; OnNewSession, + OnExpired: TNotifyEvent); begin // Do nothing end; diff --git a/packages/fcl-web/src/base/iniwebsession.pp b/packages/fcl-web/src/base/iniwebsession.pp index 9a55c06dc0..ba3bc5b12e 100644 --- a/packages/fcl-web/src/base/iniwebsession.pp +++ b/packages/fcl-web/src/base/iniwebsession.pp @@ -29,8 +29,6 @@ Type FSessionStarted : Boolean; FCached: Boolean; FIniFile : TMemInifile; - FSessionCookie: String; - FSessionCookiePath: String; FSessionDir: String; FTerminated :Boolean; SID : String; @@ -42,9 +40,7 @@ Type Function GetSessionVariable(VarName : String) : String; override; procedure SetSessionVariable(VarName : String; const AValue: String); override; Property Cached : Boolean Read FCached Write FCached; - property SessionCookie : String Read FSessionCookie Write FSessionCookie; Property SessionDir : String Read FSessionDir Write FSessionDir; - Property SessionCookiePath : String Read FSessionCookiePath write FSessionCookiePath; Public Destructor Destroy; override; Procedure Terminate; override; @@ -99,8 +95,6 @@ Const KeyLast = 'Last'; // Last seen time of session KeyTimeOut = 'Timeout'; // Timeout in seconds; - SFPWebSession = 'FPWebSession'; // Cookie name for session. - resourcestring SErrSessionTerminated = 'No web session active: Session was terminated'; SErrNoSession = 'No web session active: Session was not started'; @@ -297,7 +291,6 @@ begin FTerminated := False; // If a exception occured during a prior request FIniFile is still not freed if assigned(FIniFile) then FreeIniFile; - If (SessionCookie='') then SessionCookie:=SFPWebSession; S:=ARequest.CookieFields.Values[SessionCookie]; @@ -353,7 +346,7 @@ begin C.Name:=SessionCookie; end; C.Value:=SID; - C.Path:=FSessionCookiePath; + C.Path:=SessionCookiePath; end else If FTerminated then begin |