2014-04-01 02:12:34 +02:00
|
|
|
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);
|
2014-04-01 02:12:34 +02:00
|
|
|
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);
|
2020-04-29 01:59:41 +02:00
|
|
|
procedure OnAfterRouting(AContext: TWebContext; const AHandled: Boolean);
|
2014-04-01 02:12:34 +02:00
|
|
|
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);
|
2020-04-29 01:59:41 +02:00
|
|
|
procedure OnAfterRouting(AContext: TWebContext; const AHandled: Boolean);
|
2014-04-01 02:12:34 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2021-04-08 23:04:11 +02:00
|
|
|
System.SysUtils, MVCFramework.Commons;
|
2014-04-01 02:12:34 +02:00
|
|
|
|
|
|
|
{ TMVCSalutationMiddleware }
|
|
|
|
|
2015-04-01 17:01:23 +02:00
|
|
|
procedure TMVCSalutationMiddleware.OnAfterControllerAction(Context: TWebContext;
|
|
|
|
const AActionNAme: string; const Handled: Boolean);
|
2014-04-01 02:12:34 +02:00
|
|
|
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)';
|
2014-04-01 02:12:34 +02:00
|
|
|
end;
|
|
|
|
|
2015-04-01 17:01:23 +02:00
|
|
|
procedure TMVCRedirectAndroidDeviceOnPlayStore.OnAfterControllerAction(Context: TWebContext;
|
|
|
|
const AActionNAme: string; const Handled: Boolean);
|
2014-04-01 02:12:34 +02:00
|
|
|
begin
|
2016-11-27 23:17:20 +01:00
|
|
|
// do nothing
|
2014-04-01 02:12:34 +02:00
|
|
|
end;
|
|
|
|
|
2020-04-29 01:59:41 +02:00
|
|
|
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);
|
2014-04-01 02:12:34 +02:00
|
|
|
begin
|
|
|
|
Log(Context.Request.Headers['User-Agent']);
|
|
|
|
if Context.Request.Headers['User-Agent'].Contains('Android') then
|
|
|
|
begin
|
|
|
|
Context.Response.Location := 'http://play.google.com';
|
2022-01-26 23:00:32 +01:00
|
|
|
Context.Response.StatusCode := HTTP_STATUS.TemporaryRedirect; // 307 - temporary redirect
|
2014-04-01 02:12:34 +02:00
|
|
|
Handled := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2020-04-29 01:59:41 +02:00
|
|
|
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;
|
|
|
|
|
2014-04-01 02:12:34 +02:00
|
|
|
procedure TMVCSalutationMiddleware.OnBeforeRouting(Context: TWebContext; var Handled: Boolean);
|
|
|
|
begin
|
2016-11-27 23:17:20 +01:00
|
|
|
// do nothing
|
2014-04-01 02:12:34 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|