From 440868ccc873d9e8d8e1a7a043c63b2859efd593 Mon Sep 17 00:00:00 2001 From: Mateus Rocha Date: Sat, 29 Jun 2024 09:55:09 -0300 Subject: [PATCH] Connection Timeout --- src/RESTRequest4D.Request.Contract.pas | 1 + src/RESTRequest4D.Request.NetHTTP.pas | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/RESTRequest4D.Request.Contract.pas b/src/RESTRequest4D.Request.Contract.pas index 02a67a5..381c4ae 100644 --- a/src/RESTRequest4D.Request.Contract.pas +++ b/src/RESTRequest4D.Request.Contract.pas @@ -74,6 +74,7 @@ interface {$IF DEFINED(RR4D_NETHTTP)} function Asynchronous(const AValue: Boolean): IRequest; function SynchronizedEvents(const AValue: Boolean): IRequest; + function ConnectionTimeout(const AConnectiomTimeout: Integer): IRequest; {$ENDIF} {$IF DEFINED(RR4D_INDY) or DEFINED(FPC) or DEFINED(RR4D_SYNAPSE) or DEFINED(RR4D_NETHTTP) or DEFINED(RR4D_ICS)} function AddParam(const AName, AValue: string): IRequest; diff --git a/src/RESTRequest4D.Request.NetHTTP.pas b/src/RESTRequest4D.Request.NetHTTP.pas index 227420b..0e9ef9a 100644 --- a/src/RESTRequest4D.Request.NetHTTP.pas +++ b/src/RESTRequest4D.Request.NetHTTP.pas @@ -33,6 +33,7 @@ TRequestNetHTTP = class(TInterfacedObject, IRequest) function Accept(const AAccept: string): IRequest; overload; function Timeout: Integer; overload; function Timeout(const ATimeout: Integer): IRequest; overload; + function ConnectionTimeout(const AConnectiomTimeout: Integer): IRequest; function Adapters(const AAdapter: IRequestAdapter): IRequest; overload; function Adapters(const AAdapters: TArray): IRequest; overload; function Adapters: TArray; overload; @@ -339,6 +340,12 @@ function TRequestNetHTTP.ClearParams: IRequest; FParams.Clear; end; +function TRequestNetHTTP.ConnectionTimeout(const AConnectiomTimeout: Integer): IRequest; +begin + Result := Self; + FNetHTTPClient.ConnectionTimeout := AConnectiomTimeout; +end; + function TRequestNetHTTP.ContentType: string; begin Result := FNetHTTPClient.CustHeaders.Value['Content-Type']; @@ -352,7 +359,7 @@ function TRequestNetHTTP.ContentType(const AContentType: string): IRequest; constructor TRequestNetHTTP.Create; begin - FNetHTTPClient := TNetHTTPClient.Create(nil);; + FNetHTTPClient := TNetHTTPClient.Create(nil); FNetHTTPClient.ResponseTimeout := 900000; FNetHTTPClient.ConnectionTimeout := 900000; FNetHTTPClient.UserAgent := 'User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36';