mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 07:45:54 +01:00
Small improvements on shutdown
This commit is contained in:
parent
e30db206cc
commit
93ee4225f4
@ -41,7 +41,8 @@ uses
|
||||
IdContext,
|
||||
System.Generics.Collections,
|
||||
MVCFramework.DuckTyping,
|
||||
JsonDataObjects, MVCFramework.DotEnv;
|
||||
JsonDataObjects,
|
||||
MVCFramework.DotEnv;
|
||||
|
||||
{$I dmvcframeworkbuildconsts.inc}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -10,6 +10,7 @@ uses
|
||||
System.SysUtils,
|
||||
System.IOUtils,
|
||||
DUnitX.TestFramework,
|
||||
DUnitX.Loggers.XML.NUnit,
|
||||
{$IFDEF CONSOLE_TESTRUNNER}
|
||||
DUnitX.Loggers.Console,
|
||||
{$ENDIF }
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user