Added OnSendData callback in TMVCRESTClient

This commit is contained in:
Daniele Teti 2024-04-23 14:34:40 +02:00
parent d7bbd34d2a
commit 2a7a840b13
2 changed files with 32 additions and 2 deletions

View File

@ -1,4 +1,4 @@
// ***************************************************************************
// ***************************************************************************
//
// Delphi MVC Framework
//
@ -53,6 +53,7 @@ type
TBeforeRequestProc = reference to procedure (aRequest: IHTTPRequest);
TRequestCompletedProc = reference to procedure (aResponse: IHTTPResponse; var aHandled: Boolean);
TResponseCompletedProc = reference to procedure(aResponse: IMVCRESTResponse);
TSendDataProc = reference to procedure(AContentLength, AWriteCount: Int64; var AAbort: Boolean);
IMVCRESTClient = interface
['{592BC90F-B825-4B3B-84A7-6CA3927BAD69}']
@ -103,6 +104,11 @@ type
/// </summary>
function SetResponseCompletedProc(aResponseCompletedProc: TResponseCompletedProc): IMVCRESTClient;
/// <summary>
/// Executes while sending data
/// </summary>
function SetSendDataProc(aSendDataProc: TSendDataProc): IMVCRESTClient;
///<summary>
/// Set the client certificate for the request</summary>
/// </summary>

View File

@ -1,4 +1,4 @@
// ***************************************************************************
// ***************************************************************************
//
// Delphi MVC Framework
//
@ -99,6 +99,7 @@ type
fBeforeRequestProc: TBeforeRequestProc;
fRequestCompletedProc: TRequestCompletedProc;
fResponseCompletedProc: TResponseCompletedProc;
fSendDataProc: TSendDataProc;
[Weak] fClientCertificate: TStream;
fClientCertPassword: string;
fClientCertPath: string;
@ -109,6 +110,7 @@ type
procedure DoBeforeRequest(aRequest: IHTTPRequest);
procedure DoRequestCompleted(aResponse: IHTTPResponse; var aHandled: Boolean);
procedure DoResponseCompleted(aMVCRESTResponse: IMVCRESTResponse);
procedure DoOnSendDataEvent(const Sender: TObject; AContentLength, AWriteCount: Int64; var AAbort: Boolean);
function GetBodyFormData: TMultipartFormData;
function ObjectIsList(aObject: TObject): Boolean;
function SerializeObject(aObject: TObject): string;
@ -185,6 +187,11 @@ type
/// </summary>
function SetResponseCompletedProc(aResponseCompletedProc: TResponseCompletedProc): IMVCRESTClient;
/// <summary>
/// Executes while sending data
/// </summary>
function SetSendDataProc(aSendDataProc: TSendDataProc): IMVCRESTClient;
///<summary>
/// Set the client certificate for the request</summary>
/// </summary>
@ -951,6 +958,7 @@ begin
fHTTPClient.OnValidateServerCertificate := DoValidateServerCertificate;
fHTTPClient.HandleRedirects := True;
fHTTPClient.MaxRedirects := TMVCRESTClientConsts.DEFAULT_MAX_REDIRECTS;
fHTTPClient.OnSendData := DoOnSendDataEvent;
{$IF defined(TOKYOORBETTER)}
fHTTPClient.SecureProtocols := CHTTPDefSecureProtocols;
{$ENDIF}
@ -959,6 +967,7 @@ begin
fBeforeRequestProc := nil;
fRequestCompletedProc := nil;
fResponseCompletedProc := nil;
fSendDataProc := nil;
fParameters := TList<TMVCRESTParam>.Create;
fRawBody := TMemoryStream.Create;
fBodyFormData := nil;
@ -1511,6 +1520,15 @@ begin
Result := fRttiContext.GetType(aObject.ClassType).GetMethod('GetEnumerator') <> nil;
end;
procedure TMVCRESTClient.DoOnSendDataEvent(const Sender: TObject; AContentLength,
AWriteCount: Int64; var AAbort: Boolean);
begin
if Assigned(fSendDataProc) then
begin
fSendDataProc(AContentLength, AWriteCount, AAbort);
end;
end;
function TMVCRESTClient.Options: IMVCRESTResponse;
begin
Result := ExecuteRequest(TMVCHTTPMethodType.httpOPTIONS);
@ -1878,6 +1896,12 @@ begin
fResponseCompletedProc := aResponseCompletedProc;
end;
function TMVCRESTClient.SetSendDataProc(
aSendDataProc: TSendDataProc): IMVCRESTClient;
begin
fSendDataProc := aSendDataProc;
end;
function TMVCRESTClient.SetValidateServerCertificateProc(
aValidateCertificateProc: TValidateServerCertificateProc): IMVCRESTClient;
begin