Skip to content

Commit

Permalink
Issue #98: tentative fix for GETAsync. Minor refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-magni committed Dec 9, 2020
1 parent 07623c0 commit 9d1f257
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
35 changes: 16 additions & 19 deletions Source/MARS.Client.CustomResource.pas
Original file line number Diff line number Diff line change
Expand Up @@ -652,14 +652,16 @@ procedure TMARSClientCustomResource.GETAsync(
begin
LClient := TMARSCustomClientClass(Client.ClassType).Create(nil);
try
LClient.Assign(Client);
LClient.CloneSetup(Client);

LApplication := TMARSClientApplication.Create(nil);
try
LApplication.Assign(Application);
LApplication.CloneSetup(Application);
LApplication.Client := LClient;

LResource := TMARSClientCustomResourceClass(ClassType).Create(nil);
try
LResource.Assign(Self);
LResource.CloneSetup(Self);
LResource.SpecificClient := nil;
LResource.Application := LApplication;

Expand All @@ -669,8 +671,8 @@ procedure TMARSClientCustomResource.GETAsync(
LOnException: TProc<Exception>;
begin
try
LOnException := nil;
if Assigned(AOnException) then
begin
LOnException :=
procedure (AException: Exception)
begin
Expand All @@ -684,14 +686,12 @@ procedure TMARSClientCustomResource.GETAsync(
else
AOnException(AException);
end;
end
else
LOnException := nil;

LResource.GET(nil
LResource.GET(
nil
, procedure (AStream: TStream)
begin
Assign(LResource);
CloneStatus(LResource);

if Assigned(ACompletionHandler) then
begin
Expand All @@ -709,9 +709,9 @@ procedure TMARSClientCustomResource.GETAsync(
, LOnException
);
finally
LResource.Free;
LApplication.Free;
LClient.Free;
FreeAndNil(LResource);
FreeAndNil(LApplication);
FreeAndNil(LClient);
end;
end
);
Expand Down Expand Up @@ -803,8 +803,8 @@ procedure TMARSClientCustomResource.POSTAsync(
LOnException: TProc<Exception>;
begin
try
LOnException := nil;
if Assigned(AOnException) then
begin
LOnException :=
procedure (AException: Exception)
begin
Expand All @@ -818,9 +818,6 @@ procedure TMARSClientCustomResource.POSTAsync(
else
AOnException(AException);
end;
end
else
LOnException := nil;

LResource.POST(
ABeforeExecute
Expand All @@ -844,9 +841,9 @@ procedure TMARSClientCustomResource.POSTAsync(
, LOnException
);
finally
LResource.Free;
LApplication.Free;
LClient.Free;
FreeAndNil(LResource);
FreeAndNil(LApplication);
FreeAndNil(LClient);
end;
end
);
Expand Down
4 changes: 2 additions & 2 deletions Source/MARS.Client.Resource.FormUrlEncoded.pas
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ procedure TMARSClientResourceFormUrlEncoded.AssignTo(Dest: TPersistent);
procedure TMARSClientResourceFormUrlEncoded.CloneStatus(
const ASource: TMARSClientCustomResource);
var
LSource: TMARSClientResourceFormData;
LSource: TMARSClientResourceFormUrlEncoded;
begin
inherited;
LSource := ASource as TMARSClientResourceFormData;
LSource := ASource as TMARSClientResourceFormUrlEncoded;
if Assigned(LSource) then
begin
Response.Size := 0; // empty
Expand Down

0 comments on commit 9d1f257

Please sign in to comment.