Skip to content

Commit

Permalink
Merge pull request #337 from anderbelluno/dev
Browse files Browse the repository at this point in the history
Ajustes uRESTDWBasic e uRESTDWFphttpBase
  • Loading branch information
mobius1qwe committed May 10, 2023
2 parents 2712bac + 325dbea commit 0951a7c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
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

0 comments on commit 0951a7c

Please sign in to comment.