delphimvcframework/samples/middleware/MiddlewareSample1.pas

90 lines
3.0 KiB
ObjectPascal
Raw Normal View History

unit MiddlewareSample1;
interface
uses
MVCFramework, MVCFramework.Logger;
type
TMVCSalutationMiddleware = class(TInterfacedObject, IMVCMiddleware)
protected
2015-04-01 17:01:23 +02:00
procedure OnAfterControllerAction(Context: TWebContext; const AActionNAme: string;
const Handled: Boolean);
procedure OnBeforeRouting(Context: TWebContext; var Handled: Boolean);
2015-04-01 17:01:23 +02:00
procedure OnBeforeControllerAction(Context: TWebContext;
const AControllerQualifiedClassName: string; const AActionNAme: string; var Handled: Boolean);
procedure OnAfterRouting(AContext: TWebContext; const AHandled: Boolean);
end;
TMVCRedirectAndroidDeviceOnPlayStore = class(TInterfacedObject, IMVCMiddleware)
protected
procedure OnBeforeRouting(Context: TWebContext; var Handled: Boolean);
2015-04-01 17:01:23 +02:00
procedure OnAfterControllerAction(Context: TWebContext; const AActionNAme: string;
const Handled: Boolean);
procedure OnBeforeControllerAction(Context: TWebContext;
const AControllerQualifiedClassName: string; const AActionNAme: string; var Handled: Boolean);
procedure OnAfterRouting(AContext: TWebContext; const AHandled: Boolean);
end;
implementation
uses
2021-04-08 23:04:11 +02:00
System.SysUtils, MVCFramework.Commons;
{ TMVCSalutationMiddleware }
2015-04-01 17:01:23 +02:00
procedure TMVCSalutationMiddleware.OnAfterControllerAction(Context: TWebContext;
const AActionNAme: string; const Handled: Boolean);
begin
Context.Response.CustomHeaders.Values['X-PROUD-HEADER'] :=
2016-11-27 23:17:20 +01:00
'Proudly served by DelphiMVCFramework (https://github.com/danieleteti/delphimvcframework)';
end;
2015-04-01 17:01:23 +02:00
procedure TMVCRedirectAndroidDeviceOnPlayStore.OnAfterControllerAction(Context: TWebContext;
const AActionNAme: string; const Handled: Boolean);
begin
2016-11-27 23:17:20 +01:00
// do nothing
end;
procedure TMVCRedirectAndroidDeviceOnPlayStore.OnAfterRouting(AContext: TWebContext; const AHandled: Boolean);
begin
// do nothing
end;
2015-04-01 17:01:23 +02:00
procedure TMVCRedirectAndroidDeviceOnPlayStore.OnBeforeControllerAction(
Context: TWebContext; const AControllerQualifiedClassName,
AActionNAme: string; var Handled: Boolean);
begin
2016-11-27 23:17:20 +01:00
// do nothing
2015-04-01 17:01:23 +02:00
end;
procedure TMVCRedirectAndroidDeviceOnPlayStore.OnBeforeRouting(Context: TWebContext;
var Handled: Boolean);
begin
Log(Context.Request.Headers['User-Agent']);
if Context.Request.Headers['User-Agent'].Contains('Android') then
begin
Context.Response.Location := 'http://play.google.com';
Context.Response.StatusCode := HTTP_STATUS.TemporaryRedirect; // 307 - temporary redirect
Handled := True;
end;
end;
procedure TMVCSalutationMiddleware.OnAfterRouting(AContext: TWebContext; const AHandled: Boolean);
begin
// do nothing
end;
2015-04-01 17:01:23 +02:00
procedure TMVCSalutationMiddleware.OnBeforeControllerAction(Context: TWebContext;
const AControllerQualifiedClassName, AActionNAme: string; var Handled: Boolean);
begin
2016-11-27 23:17:20 +01:00
// do nothing
2015-04-01 17:01:23 +02:00
end;
procedure TMVCSalutationMiddleware.OnBeforeRouting(Context: TWebContext; var Handled: Boolean);
begin
2016-11-27 23:17:20 +01:00
// do nothing
end;
end.