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 uRESTDWBasic e uRESTDWFphttpBase #337

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
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
28 changes: 24 additions & 4 deletions CORE/Source/Basic/uRESTDWBasic.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3045,11 +3045,15 @@ procedure TRESTClientPoolerBase.SetIpVersion(IpV: TRESTDWClientIpVersions);
If vDefaultPage.Count > 0 Then
vReplyString := vDefaultPage.Text
Else
if vErrorMessage <> EmptyStr then
if not WelcomeAccept then
begin
vReplyString := vErrorMessage;
vErrorCode := 401;
ContentType := 'text/html';
if vErrorMessage <> EmptyStr then
vReplyString := vErrorMessage
else
vReplyString := cInvalidWelcomeMessage;

vErrorCode := 401;
ContentType := 'text/html';
end
else
begin
Expand All @@ -3059,18 +3063,31 @@ procedure TRESTClientPoolerBase.SetIpVersion(IpV: TRESTDWClientIpVersions);
End
end
Else
if not WelcomeAccept then
begin
if vErrorMessage <> EmptyStr then
vReplyString := vErrorMessage
else
vReplyString := cInvalidWelcomeMessage;

vErrorCode := 401;
ContentType := 'text/html';
end
else
Begin
If vEncoding = esUtf8 Then
sCharSet := 'utf-8'
Else
sCharSet := 'ansi';

If DWParams <> Nil Then
Begin
If (DWParams.ItemsString['dwassyncexec'] <> Nil) And (Not (dwassyncexec)) Then
dwassyncexec := DWParams.ItemsString['dwassyncexec'].AsBoolean;
If DWParams.ItemsString['dwusecript'] <> Nil Then
vdwCriptKey := DWParams.ItemsString['dwusecript'].AsBoolean;
End;

If dwassyncexec Then
Begin
StatusCode := 200;
Expand All @@ -3085,8 +3102,10 @@ procedure TRESTClientPoolerBase.SetIpVersion(IpV: TRESTDWClientIpVersions);
WriteStream(mb, ResultStream);
FreeAndNil(mb);
End;

If DWParams.itemsstring['binaryRequest'] <> Nil Then
vBinaryEvent := DWParams.itemsstring['binaryRequest'].Value;

If DWParams.itemsstring['BinaryCompatibleMode'] <> Nil Then
vBinaryCompatibleMode := DWParams.itemsstring['BinaryCompatibleMode'].Value;
If DWParams.itemsstring['MetadataRequest'] <> Nil Then
Expand All @@ -3098,6 +3117,7 @@ procedure TRESTClientPoolerBase.SetIpVersion(IpV: TRESTDWClientIpVersions);
Begin
TServerMethodDatamodule(vTempServerMethods).SetClientInfo(ClientIP, UserAgent, vUrlToExec, ClientPort);
End;

If (Not (vGettoken)) And (Not (vTokenValidate)) Then
Begin
If Not ServiceMethods(TComponent(vTempServerMethods), AContext, vUrlToExec, vdwservereventname, DWParams,
Expand Down
24 changes: 14 additions & 10 deletions CORE/Source/Sockets/Fphttp/uRESTDWFphttpBase.pas
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ procedure TRESTDWFphttpServicePooler.ExecRequest(Sender: TObject;
for I := 0 to Pred(ARequest.CustomHeaders.Count) do
HeaderList.AddPair(ARequest.CustomHeaders.Names[I], ARequest.CustomHeaders.ValueFromIndex[I] );

s := ARequest.GetHTTPVariable(hvURL);
s := ARequest.GetHTTPVariable(hvQuery);
sl := TStringList.Create;
try
if (Pos('?', s) > 0)then
Expand Down Expand Up @@ -265,7 +265,7 @@ procedure TRESTDWFphttpServicePooler.ExecRequest(Sender: TObject;
StrToInt( aRequest.GetHTTPVariable(hvServerPort) ) , //ClientPort
HeaderList , //RawHeaders
aRequest.CustomHeaders , //Params
aRequest.URI , //QueryParams
aRequest.GetHTTPVariable(hvQuery) , //QueryParams
ContentStringStream , //ContentStringStream
vAuthRealm , //AuthRealm
sCharSet , //sCharSet
Expand All @@ -279,7 +279,10 @@ procedure TRESTDWFphttpServicePooler.ExecRequest(Sender: TObject;
) then
begin
SetReplyCORS;
AResponse.SetHeader(hhWWWAuthenticate, 'Basic realm="API"'); // Aqui estava o vAuthRealm, mas no caso do FPHTTP precisa ser diferente do Indy

if (vAuthRealm <> '') then
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
Expand Down Expand Up @@ -321,17 +324,18 @@ procedure TRESTDWFphttpServicePooler.ExecRequest(Sender: TObject;
else
begin
SetReplyCORS;
AResponse.SetHeader(hhWWWAuthenticate, 'Basic realm="API"');

if (vAuthRealm <> '') then
AResponse.SetHeader(hhWWWAuthenticate, 'Basic realm="API"');

AResponse.Code := StatusCode;

if ErrorMessage <> '' Then
AResponse.Content := ErrorMessage
else
if Assigned(ResultStream) then
begin
AResponse.FreeContentStream := True;
AResponse.ContentStream := ResultStream;
AResponse.ContentStream.Position := 0;
AResponse.ContentLength := -1;
AResponse.SendContent; //SendContent � necess�rio para devolver o conte�do
AResponse.ContentStream := Nil;
AResponse.ContentLength := ResultStream.Size;
end;
end;
finally
Expand Down