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 uRESTDWFphttpBase #336

Merged
merged 1 commit into from
May 7, 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
87 changes: 45 additions & 42 deletions CORE/Source/Sockets/Fphttp/uRESTDWFphttpBase.pas
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface
uRESTDWComponentEvents, uRESTDWBasicTypes, uRESTDWJSONObject, uRESTDWBasic,
uRESTDWBasicDB, uRESTDWParams, uRESTDWBasicClass, uRESTDWAbout,
uRESTDWConsts, uRESTDWDataUtils, uRESTDWTools, uRESTDWAuthenticators,
fphttpserver, HTTPDefs, fpwebclient, base64, opensslsockets;
fphttpserver, HTTPDefs, fpwebclient, base64, opensslsockets, httpprotocol;

Type

Expand Down Expand Up @@ -278,59 +278,62 @@ procedure TRESTDWFphttpServicePooler.ExecRequest(Sender: TObject;
vRedirect //Redirect
) then
begin
SetReplyCORS;
AResponse.WWWAuthenticate := vAuthRealm;
AResponse.ContentType := vContentType;
If Encoding = esUtf8 Then
AResponse.AcceptCharset := 'utf-8'
Else
AResponse.AcceptCharset := 'ansi';
AResponse.Code := StatusCode;
If (vResponseString <> '') Or
(ErrorMessage <> '') Then
Begin
If Assigned(ResultStream) Then
FreeAndNil(ResultStream);
If (vResponseString <> '') Then
ResultStream := TStringStream.Create(vResponseString)
Else
ResultStream := TStringStream.Create(ErrorMessage);
End;


For I := 0 To vResponseHeader.Count -1 Do
AResponse.CustomHeaders.AddPair(vResponseHeader.Names [I],
vResponseHeader.Values[vResponseHeader.Names[I]]);
If vResponseHeader.Count > 0 Then
AResponse.SendHeaders;
//AResponse.WriteContent;

If Assigned(ResultStream) Then
Begin
AResponse.ContentStream := ResultStream;
AResponse.SendContent; //SendContent � necess�rio para devolver o conte�do
AResponse.ContentStream := Nil;
AResponse.ContentLength := ResultStream.Size;
End;
SetReplyCORS;
AResponse.SetHeader(hhWWWAuthenticate, 'Basic realm="API"'); // Aqui estava o vAuthRealm, mas no caso do FPHTTP precisa ser diferente do Indy
AResponse.ContentType := vContentType;

If Encoding = esUtf8 Then
AResponse.AcceptCharset := 'utf-8'
else
AResponse.AcceptCharset := 'ansi';

AResponse.Code := StatusCode;



if (vResponseString <> '') Or (ErrorMessage <> '') Then
begin
if Assigned(ResultStream) then
FreeAndNil(ResultStream);

if (vResponseString <> '') then
ResultStream := TStringStream.Create(vResponseString)
else
ResultStream := TStringStream.Create(ErrorMessage);
end;


for I := 0 To vResponseHeader.Count -1 Do
AResponse.CustomHeaders.AddPair(vResponseHeader.Names [I], vResponseHeader.Values[vResponseHeader.Names[I]]);

if vResponseHeader.Count > 0 then
AResponse.SendHeaders;
//AResponse.WriteContent;

if Assigned(ResultStream) then
begin
AResponse.ContentStream := ResultStream;
AResponse.SendContent; //SendContent � necess�rio para devolver o conte�do
AResponse.ContentStream := Nil;
AResponse.ContentLength := ResultStream.Size;
end;
end
else
begin
SetReplyCORS;
AResponse.WWWAuthenticate := vAuthRealm;
AResponse.SetHeader(hhWWWAuthenticate, 'Basic realm="API"');
AResponse.Code := StatusCode;

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

finally
DestroyComponents;
end;
Expand Down