mORMot and Open Source friends
Check-in [f81cd8395f]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:{3939} introducing THttpApiServer.SetOnBeforeBody
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f81cd8395f94f0da16870f7ccf12ed46bad46d81
User & Date: ab 2017-10-27 18:32:43
Context
2017-10-28
08:16
{3940} introducing HasNoSize optional parameter to StringFromFile() to be used e.g. with character files under Linux (/proc/meminfo) check-in: 1fdfc1e04c user: ab tags: trunk
2017-10-27
18:32
{3939} introducing THttpApiServer.SetOnBeforeBody check-in: f81cd8395f user: ab tags: trunk
2017-10-26
17:43
{3938} included server side error message to cross-platform TSQLRestClientURI.CallRemoteService exception check-in: 3aaaade511 user: ab tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to SynCrtSock.pas.

1101
1102
1103
1104
1105
1106
1107

1108
1109
1110
1111
1112
1113
1114
....
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
....
1273
1274
1275
1276
1277
1278
1279

1280
1281
1282
1283
1284
1285
1286
....
4780
4781
4782
4783
4784
4785
4786





4787
4788
4789
4790
4791
4792
4793
....
7687
7688
7689
7690
7691
7692
7693









7694
7695
7696
7697
7698
7699
7700
    /// set by RegisterCompress method
    fCompressAcceptEncoding: SockString;
    fServerName: SockString;
    fCurrentConnectionID: integer;
    fCanNotifyCallback: boolean;
    function GetAPIVersion: string; virtual; abstract;
    procedure SetServerName(const aName: SockString); virtual;

    function NextConnectionID: integer;
  public
    /// initialize the server instance, in non suspended state
    constructor Create(CreateSuspended: boolean; OnStart,OnStop: TNotifyThreadEvent;
      const ProcessName: SockString); override;
    /// override this function to customize your http server
    // - InURL/InMethod/InContent properties are input parameters
................................................................................
    // virtual Request method
    // - warning: this process must be thread-safe (can be called by several
    // threads simultaneously)
    property OnRequest: TOnHttpServerRequest read fOnRequest write fOnRequest;
    /// event handler called just before the body is retrieved from the client
    // - should return STATUS_SUCCESS=200 to continue the process, or an HTTP
    // error code to reject the request
    property OnBeforeBody: TOnHttpServerBeforeBody read fOnBeforeBody write fOnBeforeBody;
    /// event handler called after each working Thread is just initiated
    // - called in the thread context at first place in THttpServerGeneric.Execute
    property OnHttpThreadStart: TNotifyThreadEvent
      read fOnHttpThreadStart write fOnHttpThreadStart;
    /// event handler called when a working Thread is terminating
    // - called in the corresponding thread context
    // - the TThread.OnTerminate event will be called within a Synchronize()
................................................................................
    procedure SetMaxBandwidth(aValue: Cardinal);
    function GetMaxConnections: Cardinal;
    procedure SetMaxConnections(aValue: Cardinal);
    procedure SetOnTerminate(const Event: TNotifyThreadEvent); override;
    function GetAPIVersion: string; override;
    function GetLogging: boolean;
    procedure SetServerName(const aName: SockString); override;

    procedure SetLoggingServiceName(const aName: SockString);
    /// server main loop - don't change directly
    // - will call the Request public virtual method with the appropriate
    // parameters to retrive the content
    procedure Execute; override;
    /// create a clone
    constructor CreateClone(From: THttpApiServer);
................................................................................
    'another communication protocol, e.g. WebSockets',[ClassName]);
end;

procedure THttpServerGeneric.SetServerName(const aName: SockString);
begin
  fServerName := aName;
end;






function THttpServerGeneric.NextConnectionID: integer;
begin
  result := InterlockedIncrement(fCurrentConnectionID);
end;


................................................................................
    ServerName := pointer(aName);
    ServerNameLength := Length(aName);
  end;
  if fClones<>nil then // server name is shared by all clones
    for i := 0 to fClones.Count-1 do
      THttpApiServer(fClones.List{$ifdef FPC}^{$endif}[i]).SetServerName(aName);
end;










procedure THttpApiServer.SetLoggingServiceName(const aName: SockString);
begin
  if self=nil then
    exit;
  fLoggingServiceName := aName;
  PHTTP_LOG_FIELDS_DATA(fLogDataStorage)^.ServiceNameLength := Length(fLoggingServiceName);






>







 







|







 







>







 







>
>
>
>
>







 







>
>
>
>
>
>
>
>
>







1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
....
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
....
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
....
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
....
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
    /// set by RegisterCompress method
    fCompressAcceptEncoding: SockString;
    fServerName: SockString;
    fCurrentConnectionID: integer;
    fCanNotifyCallback: boolean;
    function GetAPIVersion: string; virtual; abstract;
    procedure SetServerName(const aName: SockString); virtual;
    procedure SetOnBeforeBody(const aEvent: TOnHttpServerBeforeBody); virtual; 
    function NextConnectionID: integer;
  public
    /// initialize the server instance, in non suspended state
    constructor Create(CreateSuspended: boolean; OnStart,OnStop: TNotifyThreadEvent;
      const ProcessName: SockString); override;
    /// override this function to customize your http server
    // - InURL/InMethod/InContent properties are input parameters
................................................................................
    // virtual Request method
    // - warning: this process must be thread-safe (can be called by several
    // threads simultaneously)
    property OnRequest: TOnHttpServerRequest read fOnRequest write fOnRequest;
    /// event handler called just before the body is retrieved from the client
    // - should return STATUS_SUCCESS=200 to continue the process, or an HTTP
    // error code to reject the request
    property OnBeforeBody: TOnHttpServerBeforeBody read fOnBeforeBody write SetOnBeforeBody;
    /// event handler called after each working Thread is just initiated
    // - called in the thread context at first place in THttpServerGeneric.Execute
    property OnHttpThreadStart: TNotifyThreadEvent
      read fOnHttpThreadStart write fOnHttpThreadStart;
    /// event handler called when a working Thread is terminating
    // - called in the corresponding thread context
    // - the TThread.OnTerminate event will be called within a Synchronize()
................................................................................
    procedure SetMaxBandwidth(aValue: Cardinal);
    function GetMaxConnections: Cardinal;
    procedure SetMaxConnections(aValue: Cardinal);
    procedure SetOnTerminate(const Event: TNotifyThreadEvent); override;
    function GetAPIVersion: string; override;
    function GetLogging: boolean;
    procedure SetServerName(const aName: SockString); override;
    procedure SetOnBeforeBody(const aEvent: TOnHttpServerBeforeBody); override; 
    procedure SetLoggingServiceName(const aName: SockString);
    /// server main loop - don't change directly
    // - will call the Request public virtual method with the appropriate
    // parameters to retrive the content
    procedure Execute; override;
    /// create a clone
    constructor CreateClone(From: THttpApiServer);
................................................................................
    'another communication protocol, e.g. WebSockets',[ClassName]);
end;

procedure THttpServerGeneric.SetServerName(const aName: SockString);
begin
  fServerName := aName;
end;

procedure THttpServerGeneric.SetOnBeforeBody(const aEvent: TOnHttpServerBeforeBody);
begin
  fOnBeforeBody := aEvent;
end;

function THttpServerGeneric.NextConnectionID: integer;
begin
  result := InterlockedIncrement(fCurrentConnectionID);
end;


................................................................................
    ServerName := pointer(aName);
    ServerNameLength := Length(aName);
  end;
  if fClones<>nil then // server name is shared by all clones
    for i := 0 to fClones.Count-1 do
      THttpApiServer(fClones.List{$ifdef FPC}^{$endif}[i]).SetServerName(aName);
end;

procedure THttpApiServer.SetOnBeforeBody(const aEvent: TOnHttpServerBeforeBody);
var i: integer;
begin
  inherited SetOnBeforeBody(aEvent);
  if fClones<>nil then // server name is shared by all clones
    for i := 0 to fClones.Count-1 do
      THttpApiServer(fClones.List{$ifdef FPC}^{$endif}[i]).SetOnBeforeBody(aEvent);
end;

procedure THttpApiServer.SetLoggingServiceName(const aName: SockString);
begin
  if self=nil then
    exit;
  fLoggingServiceName := aName;
  PHTTP_LOG_FIELDS_DATA(fLogDataStorage)^.ServiceNameLength := Length(fLoggingServiceName);

Changes to SynopseCommit.inc.

1
'1.18.3938'
|
1
'1.18.3939'