delphimvcframework/sources/MVCFramework.Middleware.CORS.pas
daniele.teti db659d0590
2014-10-03 09:40:57 +00:00

42 lines
1.1 KiB
ObjectPascal

unit MVCFramework.Middleware.CORS;
interface
uses
MVCFramework;
type
TCORSMiddleware = class(TInterfacedObject, IMVCMiddleware)
public
procedure OnBeforeRouting(Context: TWebContext; var Handled: Boolean);
procedure OnAfterControllerAction(Context: TWebContext;
const AActionNAme: string; const Handled: Boolean);
end;
implementation
{ TCORSMiddleware }
procedure TCORSMiddleware.OnAfterControllerAction(Context: TWebContext;
const AActionNAme: string; const Handled: Boolean);
begin
end;
procedure TCORSMiddleware.OnBeforeRouting(Context: TWebContext;
var Handled: Boolean);
begin
Context.Response.RawWebResponse.CustomHeaders.Values['Access-Control-Allow-Origin'] := '*';
Context.Response.RawWebResponse.CustomHeaders.Values['Access-Control-Allow-Methods'] :=
'POST, GET, OPTIONS, PUT, DELETE';
Context.Response.RawWebResponse.CustomHeaders.Values['Access-Control-Allow-Headers'] := 'content-type';
if Context.Request.HTTPMethod = httpOPTIONS then
begin
Context.Response.StatusCode := 200;
Handled := True;
end;
end;
end.