mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 07:45:54 +01:00
This commit is contained in:
parent
d750b19e55
commit
52640cb1fb
@ -71,19 +71,25 @@ begin
|
||||
|
||||
FMVC.AddMiddleware(TMVCStaticFilesMiddleware.Create(
|
||||
'/static2',
|
||||
TPath.Combine(ExtractFilePath(GetModuleName(HInstance)), 'www2'),
|
||||
'index.html',True,'UTF-8',
|
||||
procedure(var PathInfo: String; var Allow: Boolean)
|
||||
begin
|
||||
// This rule disallow any .txt file
|
||||
Allow := not PathInfo.EndsWith('.txt', True);
|
||||
end)
|
||||
TPath.Combine(ExtractFilePath(GetModuleName(HInstance)), 'www2'))
|
||||
);
|
||||
|
||||
// FMVC.AddMiddleware(TMVCStaticFilesMiddleware.Create(
|
||||
// '/',
|
||||
// TPath.Combine(ExtractFilePath(GetModuleName(HInstance)), 'www2'))
|
||||
// );
|
||||
FMVC.AddMiddleware(TMVCStaticFilesMiddleware.Create(
|
||||
'/static3',
|
||||
TPath.Combine(ExtractFilePath(GetModuleName(HInstance)), 'www3'),
|
||||
'index.html',True,'UTF-8',
|
||||
procedure(const Context: TWebContext; var PathInfo: String; var Allow: Boolean)
|
||||
begin
|
||||
// This rule disallow any .txt file and translates file1.html into file2.html
|
||||
Allow := not PathInfo.EndsWith('.txt', True);
|
||||
if Allow and PathInfo.Contains('file1.html') then
|
||||
PathInfo := PathInfo.Replace('file1.html','file2.html');
|
||||
if not Allow then
|
||||
begin
|
||||
Context.Response.StatusCode := HTTP_STATUS.NotFound;
|
||||
end;
|
||||
end)
|
||||
);
|
||||
|
||||
// To enable compression (deflate, gzip) just add this middleware as the last one
|
||||
FMVC.AddMiddleware(TMVCCompressionMiddleware.Create);
|
||||
|
5
samples/middleware_staticfiles/bin/www3/file1.html
Normal file
5
samples/middleware_staticfiles/bin/www3/file1.html
Normal file
@ -0,0 +1,5 @@
|
||||
<!doctype html>
|
||||
<body>
|
||||
<h2>File1</h2>
|
||||
</body>
|
||||
</html>
|
5
samples/middleware_staticfiles/bin/www3/file2.html
Normal file
5
samples/middleware_staticfiles/bin/www3/file2.html
Normal file
@ -0,0 +1,5 @@
|
||||
<!doctype html>
|
||||
<body>
|
||||
<h2>File2</h2>
|
||||
</body>
|
||||
</html>
|
5
samples/middleware_staticfiles/bin/www3/file3.html
Normal file
5
samples/middleware_staticfiles/bin/www3/file3.html
Normal file
@ -0,0 +1,5 @@
|
||||
<!doctype html>
|
||||
<body>
|
||||
<h2>File3</h2>
|
||||
</body>
|
||||
</html>
|
@ -58,7 +58,7 @@ type
|
||||
STATIC_FILES_CONTENT_CHARSET = TMVCConstants.DEFAULT_CONTENT_CHARSET;
|
||||
end;
|
||||
|
||||
TMVCStaticFileRulesProc = reference to procedure(var PathInfo: String; var Allow: Boolean);
|
||||
TMVCStaticFileRulesProc = reference to procedure(const Context: TWebContext; var PathInfo: String; var Handled: Boolean);
|
||||
|
||||
TMVCStaticFilesMiddleware = class(TInterfacedObject, IMVCMiddleware)
|
||||
private
|
||||
@ -242,10 +242,9 @@ begin
|
||||
if Assigned(fRules) then
|
||||
begin
|
||||
lAllow := True;
|
||||
fRules(lPathInfo, lAllow);
|
||||
fRules(AContext, lPathInfo, lAllow);
|
||||
if not lAllow then
|
||||
begin
|
||||
AContext.Response.StatusCode := HTTP_STATUS.NotFound;
|
||||
AHandled := True;
|
||||
Exit;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user