Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajustes internos #335

Merged
merged 1 commit into from
May 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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