Small improvements on shutdown

This commit is contained in:
Daniele Teti 2023-06-06 17:34:24 +02:00
parent e30db206cc
commit 93ee4225f4
6 changed files with 37 additions and 25 deletions

View File

@ -41,7 +41,8 @@ uses
IdContext,
System.Generics.Collections,
MVCFramework.DuckTyping,
JsonDataObjects, MVCFramework.DotEnv;
JsonDataObjects,
MVCFramework.DotEnv;
{$I dmvcframeworkbuildconsts.inc}

View File

@ -175,6 +175,10 @@ begin
fIndex := -1;
fCurLine := 0;
fSavedIndex := 0;
if fCodeLength = 0 then { empty .env file }
begin
Exit;
end;
NextChar;
while fIndex < Length(DotEnvCode) do
begin

View File

@ -97,8 +97,7 @@ end;
procedure TMVCTraceMiddleware.OnAfterRouting(Context: TWebContext; const AHandled: Boolean);
begin
Log.Debug('[AFTER ROUTING][REQUESTED URL: %s][HANDLED: %s]',
[Context.Request.PathInfo, AHandled.ToString(TUseBoolStrs.True)], 'trace');
//do nothing
end;
procedure TMVCTraceMiddleware.OnBeforeControllerAction(Context: TWebContext;
@ -112,29 +111,36 @@ procedure TMVCTraceMiddleware.OnBeforeRouting(Context: TWebContext; var Handled:
var
lContentStream: TStringStream;
lContentType: string;
lReq: TMVCWebRequest;
begin
lContentStream := TStringStream.Create;
try
Context.Request.RawWebRequest.ReadTotalContent;
Log.Debug('[BEFORE ROUTING][REQUEST][IP] ' + Context.Request.ClientIp, 'trace');
Log.Debug('[BEFORE ROUTING][REQUEST][URL] ' + Context.Request.RawWebRequest.PathInfo, 'trace');
Log.Debug('[BEFORE ROUTING][REQUEST][QUERYSTRING] ' + Context.Request.RawWebRequest.QueryFields.
DelimitedText, 'trace');
lContentType := Context.Request.Headers['content-type'].ToLower;
if lContentType.StartsWith(TMVCMediaType.APPLICATION_JSON, true) or
lContentType.StartsWith(TMVCMediaType.APPLICATION_XML, true) or
lContentType.StartsWith(TMVCMediaType.APPLICATION_FORM_URLENCODED, true) or
lContentType.StartsWith('text/') then
lReq := Context.Request;
Log.Debug('[BEFORE ROUTING][%s][IP: %s][URL: %s][QUERYSTRING: %s][LENGTH: %d]', [
lReq.HTTPMethodAsString,
lReq.ClientIp,
lReq.RawWebRequest.PathInfo,
lReq.RawWebRequest.QueryFields.DelimitedText,
lReq.RawWebRequest.ContentLength
],'trace');
if Context.Request.HTTPMethod in [httpPOST, httpPUT] then
begin
lContentStream.WriteString(EncodingGetString(lContentType,
Context.Request.RawWebRequest.RawContent).Substring(0, fMaxBodySize));
end
else
begin
lContentStream.WriteString('<hidden non text content>');
lContentType := Context.Request.Headers['content-type'].ToLower;
if lContentType.StartsWith(TMVCMediaType.APPLICATION_JSON, true) or
lContentType.StartsWith(TMVCMediaType.APPLICATION_XML, true) or
lContentType.StartsWith(TMVCMediaType.APPLICATION_FORM_URLENCODED, true) or
lContentType.StartsWith('text/') then
begin
lContentStream.WriteString(EncodingGetString(lContentType,
Context.Request.RawWebRequest.RawContent).Substring(0, fMaxBodySize));
end
else
begin
lContentStream.WriteString('<hidden non text content>');
end;
Log.Debug('[BEFORE ROUTING][REQUEST][BODY] ' + lContentStream.DataString, 'trace');
end;
Log.Debug('[BEFORE ROUTING][REQUEST][BODY] ' + lContentStream.DataString, 'trace');
finally
lContentStream.Free;
end;

View File

@ -1127,19 +1127,19 @@ uses
MVCFramework.Utils;
var
gIsShuttingDown: Int64 = 0;
gIsShuttingDown: Boolean = False;
gMVCGlobalActionParamsCache: TMVCStringObjectDictionary<TMVCActionParamCacheItem> = nil;
gHostingFramework: TMVCHostingFrameworkType = hftUnknown;
function IsShuttingDown: Boolean;
begin
Result := TInterlocked.Read(gIsShuttingDown) = 1
Result := gIsShuttingDown;
end;
procedure EnterInShutdownState;
begin
TInterlocked.CompareExchange(gIsShuttingDown, 1, 0);
gIsShuttingDown := True;
end;
function CreateResponse(const StatusCode: UInt16; const ReasonString: string;
@ -4310,7 +4310,7 @@ initialization
// https://quality.embarcadero.com/browse/RSP-38281
TRttiContext.KeepContext;
gIsShuttingDown := 0;
gIsShuttingDown := False;
gMVCGlobalActionParamsCache := TMVCStringObjectDictionary<TMVCActionParamCacheItem>.Create;

View File

@ -10,6 +10,7 @@ uses
System.SysUtils,
System.IOUtils,
DUnitX.TestFramework,
DUnitX.Loggers.XML.NUnit,
{$IFDEF CONSOLE_TESTRUNNER}
DUnitX.Loggers.Console,
{$ENDIF }

View File

@ -4,7 +4,7 @@
<ProjectVersion>19.5</ProjectVersion>
<FrameworkType>VCL</FrameworkType>
<Base>True</Base>
<Config Condition="'$(Config)'==''">TESTINSIGHT</Config>
<Config Condition="'$(Config)'==''">CI</Config>
<Platform Condition="'$(Platform)'==''">Win64</Platform>
<TargetedPlatforms>3</TargetedPlatforms>
<AppType>Console</AppType>