|
@@ -1401,14 +1401,14 @@ Procedure TFPCustomHTTPClient.DoKeepConnectionRequest(const AURI: TURI;
|
|
const AAllowedResponseCodes: array of Integer;
|
|
const AAllowedResponseCodes: array of Integer;
|
|
AHeadersOnly, AIsHttps: Boolean);
|
|
AHeadersOnly, AIsHttps: Boolean);
|
|
Var
|
|
Var
|
|
- T: Boolean;
|
|
|
|
|
|
+ SkipReconnect: Boolean;
|
|
CHost: string;
|
|
CHost: string;
|
|
CPort: Word;
|
|
CPort: Word;
|
|
- A: Integer;
|
|
|
|
|
|
+ ACount: Integer;
|
|
begin
|
|
begin
|
|
ExtractHostPort(AURI, CHost, CPort);
|
|
ExtractHostPort(AURI, CHost, CPort);
|
|
- T := False;
|
|
|
|
- A := 0;
|
|
|
|
|
|
+ SkipReconnect := False;
|
|
|
|
+ ACount := 0;
|
|
Repeat
|
|
Repeat
|
|
If Not IsConnected Then
|
|
If Not IsConnected Then
|
|
ConnectToServer(CHost,CPort,AIsHttps);
|
|
ConnectToServer(CHost,CPort,AIsHttps);
|
|
@@ -1419,32 +1419,32 @@ begin
|
|
SendRequest(AMethod,AURI);
|
|
SendRequest(AMethod,AURI);
|
|
if Terminated then
|
|
if Terminated then
|
|
break;
|
|
break;
|
|
- T := ReadResponse(AStream,AAllowedResponseCodes,AHeadersOnly);
|
|
|
|
|
|
+ SkipReconnect := ReadResponse(AStream,AAllowedResponseCodes,AHeadersOnly);
|
|
except
|
|
except
|
|
on E: EHTTPClientSocket do
|
|
on E: EHTTPClientSocket do
|
|
begin
|
|
begin
|
|
- if ((FKeepConnectionReconnectLimit>=0) and (A>=KeepConnectionReconnectLimit)) then
|
|
|
|
|
|
+ if ((FKeepConnectionReconnectLimit>=0) and (aCount>=KeepConnectionReconnectLimit)) then
|
|
raise // reconnect limit is reached -> reraise
|
|
raise // reconnect limit is reached -> reraise
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
// failed socket operations raise exceptions - e.g. if ReadString() fails
|
|
// failed socket operations raise exceptions - e.g. if ReadString() fails
|
|
// this can be due to a closed keep-alive connection by the server
|
|
// this can be due to a closed keep-alive connection by the server
|
|
// -> try to reconnect
|
|
// -> try to reconnect
|
|
- T:=False;
|
|
|
|
|
|
+ SkipReconnect:=False;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
- if (FKeepConnectionReconnectLimit>=0) and (A>=KeepConnectionReconnectLimit) then
|
|
|
|
|
|
+ if (FKeepConnectionReconnectLimit>=0) and (ACount>=KeepConnectionReconnectLimit) then
|
|
break; // reconnect limit is reached -> exit
|
|
break; // reconnect limit is reached -> exit
|
|
- If Not T and Not Terminated Then
|
|
|
|
|
|
+ If Not SkipReconnect and Not Terminated Then
|
|
ReconnectToServer(CHost,CPort,AIsHttps);
|
|
ReconnectToServer(CHost,CPort,AIsHttps);
|
|
- Inc(A);
|
|
|
|
|
|
+ Inc(ACount);
|
|
Finally
|
|
Finally
|
|
// On terminate, we close the request
|
|
// On terminate, we close the request
|
|
If HasConnectionClose or Terminated Then
|
|
If HasConnectionClose or Terminated Then
|
|
DisconnectFromServer;
|
|
DisconnectFromServer;
|
|
End;
|
|
End;
|
|
- Until T or Terminated;
|
|
|
|
|
|
+ Until SkipReconnect or Terminated;
|
|
end;
|
|
end;
|
|
|
|
|
|
Procedure TFPCustomHTTPClient.DoMethod(Const AMethod, AURL: String;
|
|
Procedure TFPCustomHTTPClient.DoMethod(Const AMethod, AURL: String;
|