delphimvcframework/unittests/TestServer/SpeedMiddlewareU.pas
2015-04-01 15:01:23 +00:00

53 lines
1.5 KiB
ObjectPascal

unit SpeedMiddlewareU;
interface
uses
MVCFramework;
type
TMVCSpeedMiddleware = class(TInterfacedObject, IMVCMiddleware)
public
procedure OnBeforeRouting(Context: TWebContext; var Handled: Boolean);
procedure OnAfterControllerAction(Context: TWebContext; const AActionNAme: string; const Handled: Boolean);
procedure OnBeforeControllerAction(Context: TWebContext;
const AControllerQualifiedClassName: string; const AActionNAme: string;
var Handled: Boolean);
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;
procedure TMVCSpeedMiddleware.OnBeforeControllerAction(Context: TWebContext;
const AControllerQualifiedClassName, AActionNAme: string;
var Handled: Boolean);
begin
end;
procedure TMVCSpeedMiddleware.OnBeforeRouting(Context: TWebContext; var Handled: Boolean);
begin
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));
end;
end.