Send DocumentIndex if request route = '/' and index file exists

FIX Charset issue on static contents
This commit is contained in:
danieleteti 2016-09-05 15:34:17 +02:00
parent b760489777
commit be7d5d7183
4 changed files with 61 additions and 33 deletions

View File

@ -309,8 +309,13 @@ type
implementation
{$IF CompilerVersion > 30}
uses
AnsiStrings;
System.AnsiStrings;
{$ENDIF}
type
TRESTResponse = class(TInterfacedObject, IRESTResponse)
@ -1258,7 +1263,7 @@ var
I: Integer;
begin
Result := '';
for I := Low(AResourceParams) to High(AResourceParams) do
for I := low(AResourceParams) to high(AResourceParams) do
Result := Result + '/' + TIdURI.ParamsEncode(AResourceParams[I]);
end;
@ -1396,7 +1401,7 @@ var
I: Integer;
begin
SetLength(FParams, Length(AValues));
for I := Low(AValues) to High(AValues) do
for I := low(AValues) to high(AValues) do
FParams[I] := AValues[I];
Result := self;
end;
@ -1490,7 +1495,12 @@ begin
begin
Result.HasError := True;
Result.Body.Write(UTF8Encode(E.ErrorMessage)[1],
AnsiStrings.ElementToCharLen(UTF8Encode(E.ErrorMessage), Length(E.ErrorMessage) * 2));
{$IF CompilerVersion > 30}
System.AnsiStrings.ElementToCharLen(UTF8Encode(E.ErrorMessage),
{$ELSE}
ElementToCharLen(UTF8Encode(E.ErrorMessage),
{$ENDIF}
Length(E.ErrorMessage) * 2));
end
else
raise;
@ -1569,7 +1579,12 @@ begin
except
on E: EIdHTTPProtocolException do
Result.Body.Write(UTF8Encode(E.ErrorMessage)[1],
AnsiStrings.ElementToCharLen(UTF8Encode(E.ErrorMessage), Length(E.ErrorMessage) * 2));
{$IF CompilerVersion > 30}
System.AnsiStrings.ElementToCharLen(UTF8Encode(E.ErrorMessage),
{$ELSE}
ElementToCharLen(UTF8Encode(E.ErrorMessage),
{$ENDIF}
Length(E.ErrorMessage) * 2));
else
raise;
end;

View File

@ -787,9 +787,15 @@ var
Config[TMVCConfigKey.IndexDocument]);
if TFile.Exists(lStaticFileName) then
begin
if not FMimeTypes.TryGetValue(LowerCase(ExtractFileExt(lStaticFileName)),
lContentType) then
if FMimeTypes.TryGetValue(LowerCase(ExtractFileExt(lStaticFileName)), lContentType) then
begin
lContentType := lContentType + ';charset=' + FMVCConfig
[TMVCConfigKey.DefaultContentCharset];
end
else
begin
lContentType := TMVCMimeType.APPLICATION_OCTETSTREAM;
end;
TMVCStaticContents.SendFile(lStaticFileName, lContentType, lContext);
Result := true;
end
@ -925,9 +931,15 @@ begin
// end
// else // serve the file
// begin
if not FMimeTypes.TryGetValue(LowerCase(ExtractFileExt(lStaticFileName)
), lContentType) then
if FMimeTypes.TryGetValue(LowerCase(ExtractFileExt(lStaticFileName)), lContentType) then
begin
lContentType := lContentType + ';charset=' + FMVCConfig
[TMVCConfigKey.DefaultContentCharset];
end
else
begin
lContentType := TMVCMimeType.APPLICATION_OCTETSTREAM;
end;
TMVCStaticContents.SendFile(lStaticFileName, lContentType, lContext);
Result := true;
// end;
@ -1064,17 +1076,19 @@ begin
if Config[TMVCConfigKey.AllowUnhandledAction] = 'false' then
// tristan
begin
// if not SendDocumentIndexIfPresent then //danieleteti
// begin
Http404(lContext);
Log(TLogLevel.levNormal, Request.Method + ':' +
Request.RawPathInfo + ' -> NO ACTION ' + ' - ' +
IntToStr(Response.StatusCode) + ' ' +
Response.ReasonString);
// end;
Result := true;
if not SendDocumentIndexIfPresent then // danieleteti
begin
Http404(lContext);
Log(TLogLevel.levNormal, Request.Method + ':' +
Request.RawPathInfo + ' -> NO ACTION ' + ' - ' +
IntToStr(Response.StatusCode) + ' ' +
Response.ReasonString);
end;
end
else
begin
Result := false;
lContext.Response.FlushOnDestroy := false; // tristan
end;
end;
@ -1850,9 +1864,9 @@ end;
function TMVCController.GetNewStompClient(ClientID: string): IStompClient;
begin
raise EMVCException.Create('Not Implemented');
// Result := StompUtils.NewStomp(Config[TMVCConfigKey.StompServer],
// StrToInt(Config[TMVCConfigKey.StompServerPort]), GetClientID,
// Config[TMVCConfigKey.StompUsername], Config[TMVCConfigKey.StompPassword]);
// Result := StompUtils.NewStomp(Config[TMVCConfigKey.StompServer],
// StrToInt(Config[TMVCConfigKey.StompServerPort]), GetClientID,
// Config[TMVCConfigKey.StompUsername], Config[TMVCConfigKey.StompPassword]);
end;
function TMVCController.GetRenderedView(const ViewNames

View File

@ -4,7 +4,7 @@
<ProjectVersion>18.1</ProjectVersion>
<FrameworkType>VCL</FrameworkType>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<Config Condition="'$(Config)'==''">USE_MESSAGING</Config>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
<TargetedPlatforms>1</TargetedPlatforms>
<AppType>Console</AppType>
@ -98,7 +98,6 @@
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
<Manifest_File>(None)</Manifest_File>
<VerInfo_Locale>1033</VerInfo_Locale>
<DCC_RemoteDebug>false</DCC_RemoteDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_3)'!=''">
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
@ -230,7 +229,16 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployClass Name="ProjectiOSDeviceResourceRules"/>
<DeployClass Name="DependencyModule">
<Platform Name="Win32">
<Operation>0</Operation>
<Extensions>.dll;.bpl</Extensions>
</Platform>
<Platform Name="OSX32">
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
</DeployClass>
<DeployClass Name="ProjectOSXResource">
<Platform Name="OSX32">
<RemoteDir>Contents\Resources</RemoteDir>
@ -544,16 +552,7 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="DependencyModule">
<Platform Name="Win32">
<Operation>0</Operation>
<Extensions>.dll;.bpl</Extensions>
</Platform>
<Platform Name="OSX32">
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
</DeployClass>
<DeployClass Name="ProjectiOSDeviceResourceRules"/>
<ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>