INDY Read and Connect timeout

90 views
Skip to first unread message

Dimitrios Chr. Ioannidis

unread,
Mar 15, 2016, 12:03:51 PM3/15/16
to WST-LIST
Hi,

  I added read and connect timeout support to indy_http_protocol . Tested ( basic tests ) and it seems to work ok in both INDY 9 and INDY 10.

 
Index: indy_http_protocol.pas
===================================================================
--- indy_http_protocol.pas    (revision 4555)
+++ indy_http_protocol.pas    (working copy)
@@ -56,14 +56,18 @@
     
FFormat : string;
     
FConnection : TidHttp;
     
FCookieManager : ICookieManager;
+    FConnectTimeout, FReadTimeout: Integer;
   
private
     
function GetAddress: string;
+    function GetConnectTimeout: Integer;
     
function GetProtocolVersion : string;
     
function GetProxyPassword: string;
     
function GetProxyPort: Integer;
     
function GetProxyServer: string;
     
function GetProxyUsername: string;
+    function GetReadTimeOut: Integer;
     procedure
SetAddress(const AValue: string);
+    procedure SetConnectTimeout(AValue: Integer);
     procedure
SetProtocolVersion(const AValue : string);
     procedure
SetProxyPassword(const AValue: string);
     procedure
SetProxyPort(const AValue: Integer);
@@ -72,7 +76,11 @@
     
function GetContentType: string;
     procedure
SetContentType(const Value: string);
     
function GetSoapAction: string;
+    procedure SetReadTimeout(AValue: Integer);
     procedure
SetSoapAction(const Value: string);
+{$IFDEF INDY_9}
+    procedure SetReadTimeoutOnConnect(Sender: TObject);
+{$ENDIF}
   
protected
     procedure
DoSendAndReceive(ARequest,AResponse:TStream);override;
   
public
@@ -90,6 +98,8 @@
     property
SoapAction : string read GetSoapAction write SetSoapAction;
     property
Format : string read FFormat write FFormat;
     property
ProtocolVersion : string read GetProtocolVersion write SetProtocolVersion;
+    property ConnectTimeout: Integer read GetConnectTimeout write SetConnectTimeout;
+    property ReadTimeout: Integer read GetReadTimeout write SetReadTimeout;
   
End;
 
   procedure INDY_RegisterHTTP_Transport
();
@@ -126,6 +136,11 @@
   
Result := FConnection.Request.URL;
 
end;
 
+function THTTPTransport.GetConnectTimeout: Integer;
+begin
+  Result := FConnectTimeout;
+end;
+
 
function THTTPTransport.GetProtocolVersion : string;
 
begin
   
Result := ProtocolVersionMAP[FConnection.ProtocolVersion];
@@ -151,11 +166,21 @@
   
Result := FConnection.ProxyParams.ProxyUsername;
 
end;
 
+function THTTPTransport.GetReadTimeOut: Integer;
+begin
+  Result := FReadTimeout;
+end;
+
 
function THTTPTransport.GetSoapAction: string;
 
begin
   
Result := FConnection.Request.CustomHeaders.Values['SOAPAction'];
 
end;
 
+procedure THTTPTransport.SetReadTimeout(AValue: Integer);
+begin
+  FReadTimeout := AValue;
+end;
+
 
function THTTPTransport.GetTransportName() : string;
 
begin
   
Result := sTRANSPORT_NAME;
@@ -166,6 +191,11 @@
   
FConnection.Request.URL := AValue;
 
end;
 
+procedure THTTPTransport.SetConnectTimeout(AValue: Integer);
+begin
+  FConnectTimeout := AValue;
+end;
+
 procedure
THTTPTransport.SetContentType(const Value: string);
 
begin
   
FConnection.Request.ContentType := Value;
@@ -207,10 +237,20 @@
   
FConnection.Request.CustomHeaders.Values['SOAPAction'] := Value;
 
end;
 
+{$IFDEF INDY_9}
+procedure THTTPTransport.SetReadTimeoutOnConnect(Sender: TObject);
+begin
+  FConnection.ReadTimeout := FReadTimeout;
+end;
+{$ENDIF}
+
 constructor
THTTPTransport.Create();
 
begin
   inherited
;
   
FConnection := TidHttp.Create(Nil);
+{$IFDEF INDY_9}
+  FConnection.OnConnected := {$IFDEF FPC}@{$ENDIF}SetReadTimeoutOnConnect;
+{$ENDIF}
 
end;
 
 destructor
THTTPTransport.Destroy();
@@ -227,7 +267,12 @@
   
then begin
     
FConnection.ProxyParams.BasicAuthentication := True;
   
end;
-  FConnection.Post(Address,ARequest, AResponse);
+
+{$IFDEF INDY_9}
+  FConnection.ReadTimeout := FConnectTimeout;
+{$ENDIF}
+
+  FConnection.Post(Address, ARequest, AResponse);
 
end;
 
 
function THTTPTransport.GetContentType: string;
Εισαγωγή κώδικα εδώ...

Best regards ,

Inoussa OUEDRAOGO

unread,
Apr 9, 2016, 7:57:55 AM4/9/16
to wst-list
Hi

2016-03-15 16:03 GMT+00:00 Dimitrios Chr. Ioannidis <d.ioa...@nephelae.eu>:
Hi,

  I added read and connect timeout support to indy_http_protocol . Tested ( basic tests ) and it seems to work ok in both INDY 9 and INDY 10.

I modify the patch to actually set the properties for INDY10, keeping the INDY9 part as your.

Thank you very much, very appreciated.

Best regards.

--
Inoussa O.
Reply all
Reply to author
Forward
0 new messages