Skip to content

Commit

Permalink
Added Synchronize function
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciussanchez committed Mar 12, 2021
1 parent 8c95942 commit 0cf7b1c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/RESTRequest4D.Request.Client.pas
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ TRequestClient = class(TInterfacedObject, IRequest)
function AddBody(const AContent: TJSONArray; const AOwns: Boolean = True): IRequest; overload;
function AddBody(const AContent: TObject; const AOwns: Boolean = True): IRequest; overload;
function AddBody(const AContent: TStream; const AOwns: Boolean = True): IRequest; overload;
function SynchronizedEvents(const AValue: Boolean): IRequest;
function ClearHeaders: IRequest;
function AddHeader(const AName, AValue: string; const AOptions: TRESTRequestParameterOptions = []): IRequest;
function ClearParams: IRequest;
Expand Down Expand Up @@ -212,8 +213,12 @@ function TRequestClient.UserAgent(const AName: string): IRequest;
constructor TRequestClient.Create;
begin
FRESTResponse := TRESTResponse.Create(nil);

FRESTClient := TRESTClient.Create(nil);
FRESTClient.SynchronizedEvents := False;

FRESTRequest := TRESTRequest.Create(nil);
FRESTRequest.SynchronizedEvents := False;

FParams := TStringList.Create;
FHeaders := TStringList.Create;
Expand Down Expand Up @@ -329,6 +334,12 @@ function TRequestClient.ResourceSuffix: string;
Result := FRESTRequest.ResourceSuffix;
end;

function TRequestClient.SynchronizedEvents(const AValue: Boolean): IRequest;
begin
FRESTClient.SynchronizedEvents := AValue;
FRESTRequest.SynchronizedEvents := AValue;
end;

function TRequestClient.Timeout: Integer;
begin
Result := FRESTRequest.Timeout;
Expand Down
4 changes: 4 additions & 0 deletions src/RESTRequest4D.Request.Contract.pas
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ interface
function Patch: IResponse;
function FullRequestURL(const AIncludeParams: Boolean = True): string;
function ClearBody: IRequest;
{$IF DEFINED(RR4D_NETHTTP)}
function Asynchronous(const AValue: Boolean): IRequest;
{$ENDIF}
{$IF DEFINED(RR4D_INDY) or DEFINED(FPC) or DEFINED(RR4D_NETHTTP)}
function AddParam(const AName, AValue: string): IRequest;
function AddBody(const AContent: string): IRequest; overload;
function AddHeader(const AName, AValue: string): IRequest;
{$ELSE}
function SynchronizedEvents(const AValue: Boolean): IRequest;
function AddHeader(const AName, AValue: string; const AOptions: TRESTRequestParameterOptions = []): IRequest;
function AddParam(const AName, AValue: string; const AKind: TRESTRequestParameterKind = {$IF COMPILERVERSION < 33}TRESTRequestParameterKind.pkGETorPOST{$ELSE}TRESTRequestParameterKind.pkQUERY{$ENDIF}): IRequest;
function AddBody(const AContent: string; const AContentType: TRESTContentType = ctAPPLICATION_JSON): IRequest; overload;
Expand Down
7 changes: 7 additions & 0 deletions src/RESTRequest4D.Request.NetHTTP.pas
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ TRequestNetHTTP = class(TInterfacedObject, IRequest)
function AddCookies(const ACookies: TStrings): IRequest;
function AddParam(const AName, AValue: string): IRequest;
function AddFile(const AName: string; const AValue: TStream): IRequest;
function Asynchronous(const AValue: Boolean): IRequest;
function MakeURL(const AIncludeParams: Boolean = True): string;
function Proxy(const AServer, APassword, AUsername: string; const APort: Integer): IRequest;
function DeactivateProxy: IRequest;
Expand Down Expand Up @@ -194,6 +195,11 @@ function TRequestNetHTTP.AddParam(const AName, AValue: string): IRequest;
FParams.Add(AName + '=' + AValue);
end;

function TRequestNetHTTP.Asynchronous(const AValue: Boolean): IRequest;
begin
FNetHTTPClient.Asynchronous := AValue;
end;

function TRequestNetHTTP.BaseURL(const ABaseURL: string): IRequest;
begin
Result := Self;
Expand Down Expand Up @@ -256,6 +262,7 @@ constructor TRequestNetHTTP.Create;
FNetHTTPClient.ContentType := 'application/json';
FNetHTTPClient.OnRequestError := DoHTTPProtocolError;
FNetHTTPClient.OnRequestCompleted := DoAfterExecute;
FNetHTTPClient.Asynchronous := False;

FParams := TStringList.Create;

Expand Down

0 comments on commit 0cf7b1c

Please sign in to comment.