Skip to content

Commit

Permalink
修正:回调中触发异常会再次触发回调的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
winddriver committed Dec 17, 2023
1 parent c7ddf5e commit 01b5b76
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions Net/Net.CrossHttpClient.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,10 @@ procedure TCrossHttpClientResponse.ParseRecvData(const ABuf: Pointer;
// 因为有可能响应完成的数据在超时后才到来, 这时候请求状态已经被置为超时
// 不应该再触发完成回调
if (LHttpConnection.RequestStatus = rsReponsding) then
try
TriggerResponseSuccess;
except
end;
end;
end;
except
Expand All @@ -1803,27 +1806,37 @@ procedure TCrossHttpClientResponse.ParseRecvData(const ABuf: Pointer;
end;

procedure TCrossHttpClientResponse.TriggerResponseFailed(const AStatusCode: Integer; const AStatusText: string);
var
LCallback: TCrossHttpResponseProc;
begin
try
LCallback := FCallback;
FCallback := nil;

_SetStatus(AStatusCode, AStatusText);

FConnection._SetRequestStatus(rsRespondFailed);
FConnection.Close;

if Assigned(FCallback) then
FCallback(FConnection.FResponse);
if Assigned(LCallback) then
LCallback(FConnection.FResponse);
finally
FConnection._EndRequest;
end;
end;

procedure TCrossHttpClientResponse.TriggerResponseSuccess;
var
LCallback: TCrossHttpResponseProc;
begin
try
LCallback := FCallback;
FCallback := nil;

FConnection._SetRequestStatus(rsRespondSuccess);

if Assigned(FCallback) then
FCallback(FConnection.FResponse);
if Assigned(LCallback) then
LCallback(FConnection.FResponse);

FConnection._SetRequestStatus(rsIdle);
FConnection._UpdateWatch;
Expand Down Expand Up @@ -1940,16 +1953,21 @@ procedure TCrossHttpClientResponse.TriggerResponseDataEnd;
end;

procedure TCrossHttpClientResponse.TriggerResponseTimeout;
var
LCallback: TCrossHttpResponseProc;
begin
try
LCallback := FCallback;
FCallback := nil;

// 408 = Request Time-out
_SetStatus(408);

FConnection._SetRequestStatus(rsRespondTimeout);
FConnection.Close;

if Assigned(FCallback) then
FCallback(FConnection.FResponse);
if Assigned(LCallback) then
LCallback(FConnection.FResponse);
finally
FConnection._EndRequest;
end;
Expand Down

0 comments on commit 01b5b76

Please sign in to comment.