2016-09-18 19:19:23 +02:00
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// Delphi MVC Framework
|
|
|
|
//
|
2017-01-05 12:44:34 +01:00
|
|
|
// Copyright (c) 2010-2017 Daniele Teti and the DMVCFramework Team
|
2016-09-18 19:19:23 +02:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// *************************************************************************** }
|
|
|
|
|
2014-03-31 11:25:16 +02:00
|
|
|
unit SpeedMiddlewareU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
MVCFramework;
|
|
|
|
|
|
|
|
type
|
|
|
|
TMVCSpeedMiddleware = class(TInterfacedObject, IMVCMiddleware)
|
|
|
|
public
|
2014-03-31 11:40:25 +02:00
|
|
|
procedure OnBeforeRouting(Context: TWebContext; var Handled: Boolean);
|
2014-03-31 11:25:16 +02:00
|
|
|
procedure OnAfterControllerAction(Context: TWebContext; const AActionNAme: string; const Handled: Boolean);
|
2015-04-01 17:01:23 +02:00
|
|
|
procedure OnBeforeControllerAction(Context: TWebContext;
|
|
|
|
const AControllerQualifiedClassName: string; const AActionNAme: string;
|
|
|
|
var Handled: Boolean);
|
2014-03-31 11:25:16 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
ObjectsMappers, System.SysUtils, DateUtils;
|
|
|
|
|
|
|
|
{ TMVCSpeedMiddleware }
|
|
|
|
|
|
|
|
procedure TMVCSpeedMiddleware.OnAfterControllerAction(Context: TWebContext; const AActionNAme: string;
|
|
|
|
const Handled: Boolean);
|
|
|
|
begin
|
|
|
|
Context.Response.CustomHeaders.Values['request_gen_time'] :=
|
|
|
|
MilliSecondsBetween(Now, ISOStrToDateTime(Context.Data[classname + 'startup'])).ToString
|
|
|
|
end;
|
|
|
|
|
2015-04-01 17:01:23 +02:00
|
|
|
procedure TMVCSpeedMiddleware.OnBeforeControllerAction(Context: TWebContext;
|
|
|
|
const AControllerQualifiedClassName, AActionNAme: string;
|
|
|
|
var Handled: Boolean);
|
|
|
|
begin
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2014-03-31 11:40:25 +02:00
|
|
|
procedure TMVCSpeedMiddleware.OnBeforeRouting(Context: TWebContext; var Handled: Boolean);
|
2014-03-31 11:25:16 +02:00
|
|
|
begin
|
2014-03-31 11:40:25 +02:00
|
|
|
if Context.Request.PathInfo = '/handledbymiddleware' then
|
|
|
|
begin
|
|
|
|
Handled := True;
|
|
|
|
Context.Response.RawWebResponse.Content := 'This is a middleware response';
|
|
|
|
Context.Response.StatusCode := 200;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
|
|
|
|
Context.Data.Add(classname + 'startup', ISODateTimeToString(Now));
|
2014-03-31 11:25:16 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|