mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 07:45:54 +01:00
Middleware Trace
This commit is contained in:
parent
e2f6bd76d4
commit
7c89df545d
@ -249,6 +249,8 @@ end;
|
||||
|
||||
- Fixed! [issue232](https://github.com/danieleteti/delphimvcframework/issues/232) (Thanks to [João Antônio Duarte](https://github.com/joaoduarte19))
|
||||
|
||||
- Fixed! [issue312](https://github.com/danieleteti/delphimvcframework/issues/312)
|
||||
|
||||
- New Installation procedure!
|
||||
|
||||
- Open the project group (select the correct one from the following table)
|
||||
|
BIN
delphimvcframework_handbook_cover.png
Normal file
BIN
delphimvcframework_handbook_cover.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 71 KiB |
102
sources/MVCFramework.Middleware.Trace.pas
Normal file
102
sources/MVCFramework.Middleware.Trace.pas
Normal file
@ -0,0 +1,102 @@
|
||||
// ***************************************************************************
|
||||
//
|
||||
// Delphi MVC Framework
|
||||
//
|
||||
// Copyright (c) 2010-2019 Daniele Teti and the DMVCFramework Team
|
||||
//
|
||||
// https://github.com/danieleteti/delphimvcframework
|
||||
//
|
||||
// ***************************************************************************
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// *************************************************************************** }
|
||||
|
||||
unit MVCFramework.Middleware.Trace;
|
||||
|
||||
{$I dmvcframework.inc}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
MVCFramework,
|
||||
MVCFramework.Logger;
|
||||
|
||||
type
|
||||
TMVCTraceMiddleware = class(TInterfacedObject, IMVCMiddleware)
|
||||
protected
|
||||
procedure OnAfterControllerAction(Context: TWebContext; const AActionNAme: string;
|
||||
const Handled: Boolean);
|
||||
procedure OnBeforeRouting(Context: TWebContext; var Handled: Boolean);
|
||||
procedure OnBeforeControllerAction(Context: TWebContext;
|
||||
const AControllerQualifiedClassName: string; const AActionNAme: string; var Handled: Boolean);
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
System.SysUtils,
|
||||
System.ZLib,
|
||||
System.Classes,
|
||||
MVCFramework.Commons, Web.HTTPApp;
|
||||
|
||||
{ TMVCSalutationMiddleware }
|
||||
|
||||
procedure TMVCTraceMiddleware.OnAfterControllerAction(Context: TWebContext;
|
||||
const AActionNAme: string; const Handled: Boolean);
|
||||
var
|
||||
lContentStream: TStringStream;
|
||||
begin
|
||||
lContentStream := TStringStream.Create;
|
||||
try
|
||||
Log.Debug('[RESPONSE][HEADERS] ' + string.Join(' | ', Context.Response.CustomHeaders.ToStringArray), 'trace');
|
||||
if Assigned(Context.Response.RawWebResponse.ContentStream) then
|
||||
begin
|
||||
lContentStream.CopyFrom(Context.Response.RawWebResponse.ContentStream, 0);
|
||||
Context.Response.RawWebResponse.ContentStream.Position := 0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
lContentStream.WriteString(Context.Response.RawWebResponse.Content);
|
||||
end;
|
||||
Log.Debug('[RESPONSE][BODY] ' + lContentStream.DataString, 'trace');
|
||||
finally
|
||||
lContentStream.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMVCTraceMiddleware.OnBeforeControllerAction(Context: TWebContext;
|
||||
const AControllerQualifiedClassName, AActionNAme: string; var Handled: Boolean);
|
||||
begin
|
||||
Log.Debug('[BEFORE ACTION][CONTROLLER: %s][ACTION: %s]',
|
||||
[AControllerQualifiedClassName, AActionNAme], 'trace');
|
||||
end;
|
||||
|
||||
procedure TMVCTraceMiddleware.OnBeforeRouting(Context: TWebContext; var Handled: Boolean);
|
||||
var
|
||||
lContentStream: TStringStream;
|
||||
begin
|
||||
lContentStream := TStringStream.Create;
|
||||
try
|
||||
Context.Request.RawWebRequest.ReadTotalContent;
|
||||
Log.Debug('[REQUEST][URL] ' + Context.Request.RawWebRequest.PathInfo, 'trace');
|
||||
Log.Debug('[REQUEST][QUERYSTRING] ' + Context.Request.RawWebRequest.QueryFields.DelimitedText, 'trace');
|
||||
lContentStream.WriteString(EncodingGetString(Context.Request.Headers['content-type'],
|
||||
Context.Request.RawWebRequest.RawContent));
|
||||
Log.Debug('[REQUEST][BODY] ' + lContentStream.DataString, 'trace');
|
||||
finally
|
||||
lContentStream.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
Loading…
Reference in New Issue
Block a user