From cc5789d56e4bc8c5e11b8c3a653d6bb92b6207ac Mon Sep 17 00:00:00 2001 From: Daniele Teti Date: Wed, 21 Feb 2024 14:41:25 +0100 Subject: [PATCH] Now "NoRouteFound" error returns the correct content-type --- samples/functional_actions_showcase/ControllerU.pas | 7 +++++++ .../function_actions_showcase.dpr | 10 +++++----- samples/servercontainer/App1MainControllerU.pas | 2 +- sources/MVCFramework.pas | 5 +++-- unittests/general/TestServer/TestServer.dpr | 4 +++- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/samples/functional_actions_showcase/ControllerU.pas b/samples/functional_actions_showcase/ControllerU.pas index 76d23a1b..d1ed356e 100644 --- a/samples/functional_actions_showcase/ControllerU.pas +++ b/samples/functional_actions_showcase/ControllerU.pas @@ -34,6 +34,8 @@ type function GetSum(const A, B: Integer): Integer; [MVCPath('/sumsasfloat/($A)/($B)')] function GetSumAsFloat(const A, B: Extended): Extended; + [MVCPath('/string/($A)/($B)')] + function GetConcatAsString(const A, B: String): String; { actions returning records } [MVCPath('/records/single')] @@ -258,6 +260,11 @@ begin Result := A + B; end; +function TMyController.GetConcatAsString(const A, B: String): String; +begin + Result := A + B; +end; + function TMyController.GetWithCustomHeaders: TObjectList; begin Result := TObjectList.Create; diff --git a/samples/functional_actions_showcase/function_actions_showcase.dpr b/samples/functional_actions_showcase/function_actions_showcase.dpr index 518eae80..a77a40c4 100644 --- a/samples/functional_actions_showcase/function_actions_showcase.dpr +++ b/samples/functional_actions_showcase/function_actions_showcase.dpr @@ -25,7 +25,7 @@ procedure RunServer(APort: Integer); var LServer: TIdHTTPWebBrokerBridge; begin - Writeln('** DMVCFramework Server ** build ' + DMVCFRAMEWORK_VERSION); + LogI('** DMVCFramework Server ** build ' + DMVCFRAMEWORK_VERSION); LServer := TIdHTTPWebBrokerBridge.Create(nil); try LServer.OnParseAuthentication := TMVCParseAuthentication.OnParseAuthentication; @@ -35,8 +35,8 @@ begin LServer.ListenQueue := dotEnv.Env('dmvc.indy.listen_queue', 500); LServer.Active := True; - WriteLn('Listening on port ', APort); - Write('CTRL+C to shutdown the server'); + LogI('Listening on port ' + APort.ToString); + LogI('CTRL+C to shutdown the server'); WaitForTerminationSignal; EnterInShutdownState; LServer.Active := False; @@ -47,7 +47,7 @@ end; begin { Enable ReportMemoryLeaksOnShutdown during debug } - // ReportMemoryLeaksOnShutdown := True; + ReportMemoryLeaksOnShutdown := True; IsMultiThread := True; // DMVCFramework Specific Configuration @@ -78,6 +78,6 @@ begin RunServer(dotEnv.Env('dmvc.server.port', 8080)); except on E: Exception do - Writeln(E.ClassName, ': ', E.Message); + LogE(E.ClassName + ': ' + E.Message); end; end. diff --git a/samples/servercontainer/App1MainControllerU.pas b/samples/servercontainer/App1MainControllerU.pas index 81a1c3fb..fefb09ee 100644 --- a/samples/servercontainer/App1MainControllerU.pas +++ b/samples/servercontainer/App1MainControllerU.pas @@ -44,7 +44,7 @@ uses procedure TApp1MainController.HelloWorld; begin Render('Hello World called with GET'); - if Context.Request.ThereIsRequestBody then + if Context.Request.HasBody then Log('Body:' + Context.Request.Body); end; diff --git a/sources/MVCFramework.pas b/sources/MVCFramework.pas index 78d2cd11..1cbd7206 100644 --- a/sources/MVCFramework.pas +++ b/sources/MVCFramework.pas @@ -823,8 +823,8 @@ type /// /// Page calls GetRenderedView with sensible defaults. - /// Page method just concatenate -> commonheader_header_views + views + commonfooter_views - /// PageFragment ignore header and footer views + /// Page method with UseCommonHeadersAndFooters = True (default) concatenates + // commonheader_header_views + views + commonfooter_views /// function Page(const AViewNames: TArray; const JSONModel: TJSONObject; const UseCommonHeadersAndFooters: Boolean = True): string; overload; inline; @@ -2788,6 +2788,7 @@ begin begin lContext.Response.StatusCode := http_status.NotFound; lContext.Response.ReasonString := 'Not Found'; + lContext.Response.SetContentStream(TStringStream.Create(), FConfigCache_DefaultContentType); fOnRouterLog(lRouter, rlsRouteNotFound, lContext); end else diff --git a/unittests/general/TestServer/TestServer.dpr b/unittests/general/TestServer/TestServer.dpr index 63ebc894..388a4eaf 100644 --- a/unittests/general/TestServer/TestServer.dpr +++ b/unittests/general/TestServer/TestServer.dpr @@ -27,7 +27,8 @@ uses Entities in '..\Several\Entities.pas', EntitiesProcessors in '..\Several\EntitiesProcessors.pas', MVCFramework.JSONRPC.Client in '..\..\..\sources\MVCFramework.JSONRPC.Client.pas', - MVCFramework.JSONRPC in '..\..\..\sources\MVCFramework.JSONRPC.pas'; + MVCFramework.JSONRPC in '..\..\..\sources\MVCFramework.JSONRPC.pas', + MVCFramework.Serializer.Commons; {$R *.res} @@ -80,6 +81,7 @@ end; begin ReportMemoryLeaksOnShutdown := True; + gLocalTimeStampAsUTC := False; UseConsoleLogger := False; try if WebRequestHandler <> nil then