mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 15:55:54 +01:00
Improved caching and add X-Powered-By optional header
This commit is contained in:
parent
0145a1c89e
commit
e6a7c80ef6
@ -467,6 +467,8 @@ end;
|
|||||||
|
|
||||||
- New! The **MVCAREntitiesGenerator** can optionally register all the generated entities also in the `ActiveRecordMappingRegistry` (Thanks to [Fabrizio Bitti](https://twitter.com/fabriziobitti) from [bit Time Software](http://www.bittime.it))
|
- New! The **MVCAREntitiesGenerator** can optionally register all the generated entities also in the `ActiveRecordMappingRegistry` (Thanks to [Fabrizio Bitti](https://twitter.com/fabriziobitti) from [bit Time Software](http://www.bittime.it))
|
||||||
|
|
||||||
|
- Compression through `TMVCCompressionMiddleware` is not enabled is DMVCFramework service is compiled as Apache module or IIS ISAPI. The host webserver should handle the actual compression.
|
||||||
|
|
||||||
- New! Children objects lifecycle management in `TMVCActiveRecord` (methods `AddChildren` and `RemoveChildren`). Really useful to manage child objects such relations or derived properties and are safe in case of multiple addition of the same object as children.
|
- New! Children objects lifecycle management in `TMVCActiveRecord` (methods `AddChildren` and `RemoveChildren`). Really useful to manage child objects such relations or derived properties and are safe in case of multiple addition of the same object as children.
|
||||||
|
|
||||||
```delphi
|
```delphi
|
||||||
|
@ -348,6 +348,8 @@ resourcestring
|
|||||||
' Config[TMVCConfigKey.MaxEntitiesRecordCount] := ''20'';' + sLineBreak +
|
' Config[TMVCConfigKey.MaxEntitiesRecordCount] := ''20'';' + sLineBreak +
|
||||||
' //Enable Server Signature in response' + sLineBreak +
|
' //Enable Server Signature in response' + sLineBreak +
|
||||||
' Config[TMVCConfigKey.ExposeServerSignature] := ''true'';' + sLineBreak +
|
' Config[TMVCConfigKey.ExposeServerSignature] := ''true'';' + sLineBreak +
|
||||||
|
' //Enable X-Powered-By Header in response' + sLineBreak +
|
||||||
|
' Config[TMVCConfigKey.ExposeXPoweredBy] := ''true'';' + sLineBreak +
|
||||||
// ' // Define a default URL for requests that don''t map to a route or a file (useful for client side web app)' + sLineBreak +
|
// ' // Define a default URL for requests that don''t map to a route or a file (useful for client side web app)' + sLineBreak +
|
||||||
// ' Config[TMVCConfigKey.FallbackResource] := ''index.html'';' + sLineBreak +
|
// ' Config[TMVCConfigKey.FallbackResource] := ''index.html'';' + sLineBreak +
|
||||||
' // Max request size in bytes' + sLineBreak +
|
' // Max request size in bytes' + sLineBreak +
|
||||||
|
@ -151,6 +151,7 @@ type
|
|||||||
AllowUnhandledAction = 'allow_unhandled_action';
|
AllowUnhandledAction = 'allow_unhandled_action';
|
||||||
ServerName = 'server_name';
|
ServerName = 'server_name';
|
||||||
ExposeServerSignature = 'server_signature';
|
ExposeServerSignature = 'server_signature';
|
||||||
|
ExposeXPoweredBy = 'xpoweredby';
|
||||||
SessionType = 'session_type';
|
SessionType = 'session_type';
|
||||||
MaxEntitiesRecordCount = 'max_entities_record_count';
|
MaxEntitiesRecordCount = 'max_entities_record_count';
|
||||||
MaxRequestSize = 'max_request_size'; // bytes
|
MaxRequestSize = 'max_request_size'; // bytes
|
||||||
|
@ -853,6 +853,9 @@ type
|
|||||||
FWebModule: TWebModule;
|
FWebModule: TWebModule;
|
||||||
FConfig: TMVCConfig;
|
FConfig: TMVCConfig;
|
||||||
FConfigCache_MaxRequestSize: Int64;
|
FConfigCache_MaxRequestSize: Int64;
|
||||||
|
FConfigCache_ExposeServerSignature: Boolean;
|
||||||
|
FConfigCache_ServerSignature: String;
|
||||||
|
FConfigCache_ExposeXPoweredBy: Boolean;
|
||||||
FSerializers: TDictionary<string, IMVCSerializer>;
|
FSerializers: TDictionary<string, IMVCSerializer>;
|
||||||
FMiddlewares: TList<IMVCMiddleware>;
|
FMiddlewares: TList<IMVCMiddleware>;
|
||||||
FControllers: TObjectList<TMVCControllerDelegate>;
|
FControllers: TObjectList<TMVCControllerDelegate>;
|
||||||
@ -909,7 +912,6 @@ type
|
|||||||
function SetViewEngine(const AViewEngineClass: TMVCViewEngineClass): TMVCEngine;
|
function SetViewEngine(const AViewEngineClass: TMVCViewEngineClass): TMVCEngine;
|
||||||
function SetExceptionHandler(const AExceptionHandlerProc: TMVCExceptionHandlerProc): TMVCEngine;
|
function SetExceptionHandler(const AExceptionHandlerProc: TMVCExceptionHandlerProc): TMVCEngine;
|
||||||
|
|
||||||
function GetServerSignature(const AContext: TWebContext): string;
|
|
||||||
procedure HTTP404(const AContext: TWebContext);
|
procedure HTTP404(const AContext: TWebContext);
|
||||||
procedure HTTP500(const AContext: TWebContext; const AReasonString: string = '');
|
procedure HTTP500(const AContext: TWebContext; const AReasonString: string = '');
|
||||||
procedure SendRawHTTPStatus(const AContext: TWebContext; const HTTPStatusCode: Integer;
|
procedure SendRawHTTPStatus(const AContext: TWebContext; const HTTPStatusCode: Integer;
|
||||||
@ -1998,6 +2000,7 @@ begin
|
|||||||
Config[TMVCConfigKey.AllowUnhandledAction] := 'false';
|
Config[TMVCConfigKey.AllowUnhandledAction] := 'false';
|
||||||
Config[TMVCConfigKey.ServerName] := 'DelphiMVCFramework';
|
Config[TMVCConfigKey.ServerName] := 'DelphiMVCFramework';
|
||||||
Config[TMVCConfigKey.ExposeServerSignature] := 'true';
|
Config[TMVCConfigKey.ExposeServerSignature] := 'true';
|
||||||
|
Config[TMVCConfigKey.ExposeXPoweredBy] := 'true';
|
||||||
Config[TMVCConfigKey.SessionType] := 'memory';
|
Config[TMVCConfigKey.SessionType] := 'memory';
|
||||||
Config[TMVCConfigKey.MaxEntitiesRecordCount] := '20';
|
Config[TMVCConfigKey.MaxEntitiesRecordCount] := '20';
|
||||||
Config[TMVCConfigKey.MaxRequestSize] := IntToStr(TMVCConstants.DEFAULT_MAX_REQUEST_SIZE);
|
Config[TMVCConfigKey.MaxRequestSize] := IntToStr(TMVCConstants.DEFAULT_MAX_REQUEST_SIZE);
|
||||||
@ -2075,8 +2078,10 @@ end;
|
|||||||
|
|
||||||
procedure TMVCEngine.DefineDefaultResponseHeaders(const AContext: TWebContext);
|
procedure TMVCEngine.DefineDefaultResponseHeaders(const AContext: TWebContext);
|
||||||
begin
|
begin
|
||||||
if Config[TMVCConfigKey.ExposeServerSignature] = 'true' then
|
if FConfigCache_ExposeServerSignature and (not IsLibrary) then
|
||||||
AContext.Response.CustomHeaders.Values['Server'] := GetServerSignature(AContext);
|
AContext.Response.CustomHeaders.Values['Server'] := FConfigCache_ServerSignature;
|
||||||
|
if FConfigCache_ExposeXPoweredBy then
|
||||||
|
AContext.Response.CustomHeaders.Values['X-Powered-By'] := 'DMVCFramework ' + DMVCFRAMEWORK_VERSION;
|
||||||
AContext.Response.RawWebResponse.Date := Now;
|
AContext.Response.RawWebResponse.Date := Now;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2588,18 +2593,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMVCEngine.GetServerSignature(const AContext: TWebContext): string;
|
|
||||||
begin
|
|
||||||
if AContext.Config.Value[TMVCConfigKey.ExposeServerSignature] = 'true' then
|
|
||||||
begin
|
|
||||||
Result := 'DelphiMVCFramework ' + DMVCFRAMEWORK_VERSION;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
Result := '';
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TMVCEngine.GetSessionBySessionId(const ASessionId: string): TWebSession;
|
function TMVCEngine.GetSessionBySessionId(const ASessionId: string): TWebSession;
|
||||||
begin
|
begin
|
||||||
Result := TMVCEngine.GetCurrentSession(StrToInt64(Config[TMVCConfigKey.SessionTimeout]), ASessionId, False);
|
Result := TMVCEngine.GetCurrentSession(StrToInt64(Config[TMVCConfigKey.SessionTimeout]), ASessionId, False);
|
||||||
@ -2621,7 +2614,7 @@ begin
|
|||||||
AContext.Response.SetContentType(BuildContentType(TMVCMediaType.TEXT_PLAIN,
|
AContext.Response.SetContentType(BuildContentType(TMVCMediaType.TEXT_PLAIN,
|
||||||
AContext.Config[TMVCConfigKey.DefaultContentCharset]));
|
AContext.Config[TMVCConfigKey.DefaultContentCharset]));
|
||||||
AContext.Response.SetReasonString('Not Found');
|
AContext.Response.SetReasonString('Not Found');
|
||||||
AContext.Response.SetContent('Not Found' + sLineBreak + GetServerSignature(AContext));
|
AContext.Response.SetContent('Not Found' + sLineBreak + FConfigCache_ServerSignature);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMVCEngine.HTTP500(const AContext: TWebContext; const AReasonString: string);
|
procedure TMVCEngine.HTTP500(const AContext: TWebContext; const AReasonString: string);
|
||||||
@ -2630,7 +2623,7 @@ begin
|
|||||||
AContext.Response.SetContentType(BuildContentType(TMVCMediaType.TEXT_PLAIN,
|
AContext.Response.SetContentType(BuildContentType(TMVCMediaType.TEXT_PLAIN,
|
||||||
AContext.Config[TMVCConfigKey.DefaultContentCharset]));
|
AContext.Config[TMVCConfigKey.DefaultContentCharset]));
|
||||||
AContext.Response.SetReasonString('Internal server error');
|
AContext.Response.SetReasonString('Internal server error');
|
||||||
AContext.Response.SetContent('Internal server error' + sLineBreak + GetServerSignature(AContext) + ': ' +
|
AContext.Response.SetContent('Internal server error' + sLineBreak + FConfigCache_ServerSignature + ': ' +
|
||||||
AReasonString);
|
AReasonString);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2658,7 +2651,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
AContext.Response.SetContentType(BuildContentType(TMVCMediaType.TEXT_PLAIN,
|
AContext.Response.SetContentType(BuildContentType(TMVCMediaType.TEXT_PLAIN,
|
||||||
AContext.Config[TMVCConfigKey.DefaultContentCharset]));
|
AContext.Config[TMVCConfigKey.DefaultContentCharset]));
|
||||||
AContext.Response.SetContent(GetServerSignature(AContext) + sLineBreak + 'HTTP ' + HTTPStatusCode.ToString + ': ' +
|
AContext.Response.SetContent(FConfigCache_ServerSignature + sLineBreak + 'HTTP ' + HTTPStatusCode.ToString + ': ' +
|
||||||
AReasonString);
|
AReasonString);
|
||||||
end;
|
end;
|
||||||
AContext.Response.SetStatusCode(HTTPStatusCode);
|
AContext.Response.SetStatusCode(HTTPStatusCode);
|
||||||
@ -2771,6 +2764,9 @@ procedure TMVCEngine.SaveCacheConfigValues;
|
|||||||
begin
|
begin
|
||||||
FConfigCache_MaxRequestSize := StrToInt64Def(Config[TMVCConfigKey.MaxRequestSize],
|
FConfigCache_MaxRequestSize := StrToInt64Def(Config[TMVCConfigKey.MaxRequestSize],
|
||||||
TMVCConstants.DEFAULT_MAX_REQUEST_SIZE);
|
TMVCConstants.DEFAULT_MAX_REQUEST_SIZE);
|
||||||
|
FConfigCache_ExposeServerSignature := Config[TMVCConfigKey.ExposeServerSignature] = 'true';
|
||||||
|
FConfigCache_ServerSignature := Config[TMVCConfigKey.ServerName];
|
||||||
|
FConfigCache_ExposeXPoweredBy := Config[TMVCConfigKey.ExposeXPoweredBy] = 'true';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TMVCEngine.SendSessionCookie(const AContext: TWebContext; const ASessionId: string): string;
|
class function TMVCEngine.SendSessionCookie(const AContext: TWebContext; const ASessionId: string): string;
|
||||||
|
Loading…
Reference in New Issue
Block a user