Skip to content

Commit

Permalink
Merge pull request #335 from anderbelluno/dev
Browse files Browse the repository at this point in the history
Ajustes internos
  • Loading branch information
mobius1qwe committed May 2, 2023
2 parents b50e09e + e41d674 commit 98f24a2
Showing 1 changed file with 48 additions and 21 deletions.
69 changes: 48 additions & 21 deletions CORE/Source/Sockets/Fphttp/uRESTDWFphttpBase.pas
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ procedure TRESTDWFphttpServicePooler.ExecRequest(Sender: TObject;
Var AResponse : TFPHTTPConnectionResponse);
var
vContentType,
AuthRealm,
vAuthRealm,
sCharSet,
ErrorMessage,
vResponseString : String;
Expand All @@ -118,6 +118,7 @@ procedure TRESTDWFphttpServicePooler.ExecRequest(Sender: TObject;
CORSCustomHeaders : TStringList;
ResultStream,
ContentStringStream : TStream;
mb : TStringStream;
vRedirect : TRedirect;

a : String;
Expand Down Expand Up @@ -192,11 +193,36 @@ procedure TRESTDWFphttpServicePooler.ExecRequest(Sender: TObject;
//end;
end;

Procedure DestroyComponents;
Begin
if assigned(vResponseHeader)then
FreeAndNil(vResponseHeader);
if assigned(ResultStream)then
FreeAndNil(ResultStream);
if assigned(CORSCustomHeaders)then
FreeAndNil(CORSCustomHeaders);
if assigned(ContentStringStream)then
FreeAndNil(ContentStringStream);
if assigned(HeaderList)then
FreeAndNil(HeaderList);
End;

procedure Redirect(Url: String);
begin
AResponse.SendRedirect(Url);
end;

Procedure WriteError;
Begin
AResponse.Code := StatusCode;
mb := TStringStream.Create(ErrorMessage);
mb.Position := 0;
AResponse.FreeContentStream := True;
AResponse.ContentStream := mb;
AResponse.ContentStream.Position := 0;
AResponse.ContentLength := -1;//mb.Size;
AResponse.SendContent;
End;

begin
aUserName:= EmptyStr;
Expand All @@ -211,9 +237,9 @@ procedure TRESTDWFphttpServicePooler.ExecRequest(Sender: TObject;

ParseHeader;

//@vRedirect := @Redirect; { #todo -oAnderson : Verificar como funciona o Redirect. }
vRedirect := TRedirect(@Redirect);
vContentType := ARequest.ContentType;
AuthRealm := '' ;
vAuthRealm := AResponse.WWWAuthenticate;
sCharSet := aRequest.AcceptCharset;
ErrorMessage := '';
vResponseString := '';
Expand Down Expand Up @@ -241,7 +267,7 @@ procedure TRESTDWFphttpServicePooler.ExecRequest(Sender: TObject;
aRequest.CustomHeaders , //Params
aRequest.URI , //QueryParams
ContentStringStream , //ContentStringStream
AuthRealm , //AuthRealm
vAuthRealm , //AuthRealm
sCharSet , //sCharSet
ErrorMessage , //ErrorMessage
StatusCode , //StatusCode
Expand All @@ -252,11 +278,9 @@ procedure TRESTDWFphttpServicePooler.ExecRequest(Sender: TObject;
vRedirect //Redirect
) then
begin


SetReplyCORS;
//AResponseInfo.AuthRealm := vAuthRealm;
AResponse.ContentType := vContentType;
AResponse.WWWAuthenticate := vAuthRealm;
AResponse.ContentType := vContentType;
If Encoding = esUtf8 Then
AResponse.AcceptCharset := 'utf-8'
Else
Expand All @@ -273,7 +297,8 @@ procedure TRESTDWFphttpServicePooler.ExecRequest(Sender: TObject;
ResultStream := TStringStream.Create(ErrorMessage);
End;

For I := 0 To vResponseHeader.Count -1 Do

For I := 0 To vResponseHeader.Count -1 Do
AResponse.CustomHeaders.AddPair(vResponseHeader.Names [I],
vResponseHeader.Values[vResponseHeader.Names[I]]);
If vResponseHeader.Count > 0 Then
Expand All @@ -288,24 +313,26 @@ procedure TRESTDWFphttpServicePooler.ExecRequest(Sender: TObject;
AResponse.ContentLength := ResultStream.Size;
End;


end
else
begin
a := 'no.';
SetReplyCORS;
AResponse.WWWAuthenticate := vAuthRealm;
AResponse.Code := StatusCode;

If ErrorMessage <> '' Then
AResponse.Content := ErrorMessage
Else
Begin
AResponse.FreeContentStream := True;
AResponse.ContentStream := ResultStream;
AResponse.ContentStream.Position := 0;
AResponse.ContentLength := -1;
End;
end;

finally
if assigned(vResponseHeader)then
FreeAndNil(vResponseHeader);
if assigned(ResultStream)then
FreeAndNil(ResultStream);
if assigned(CORSCustomHeaders)then
FreeAndNil(CORSCustomHeaders);
if assigned(ContentStringStream)then
FreeAndNil(ContentStringStream);
if assigned(HeaderList)then
FreeAndNil(HeaderList);
DestroyComponents;
end;
end;

Expand Down

0 comments on commit 98f24a2

Please sign in to comment.