HTTP server application will never work on Windows
Original Reporter info from Mantis: leledumbo_cool@yahoo.co.id @leledumbo
-
Reporter name: Mario Ray Mahardhika
Original Reporter info from Mantis: leledumbo_cool@yahoo.co.id @leledumbo
- Reporter name: Mario Ray Mahardhika
Description:
I'm testing Project->HTTP server application
However, no files can be served by the application, it always ends up in error. Debugging everything, I found something strange in fpwebfile.pp, where file serving module is registered. Starting from RegisterFileLocation procedure:
Procedure RegisterFileLocation(Const ALocation,ADirectory : String);
...
Locations.Values[IncludeTrailingPathDelimiter(ALocation)]:=ExtractFilePath(ParamStr(0))
else
Locations.Values[IncludeTrailingPathDelimiter(ALocation)]:=IncludeTrailingPathDelimiter(ADirectory);
RegisterHTTPModule(ALocation,DefaultFileModuleClass,true);
end;
As can be seen, ALocation is added to Locations by applying IncludeTrailingPathDelimiter first, which is '' on Windows. Now let's goto custweb.pp and take a look at TWebHandler.SetBaseURL:
procedure TWebHandler.SetBaseURL(AModule: TCustomHTTPModule;
Const AModuleName : String; ARequest: TRequest);
...
S:=IncludeHTTPPathDelimiter(GetApplicationURL(ARequest));
P:=IncludeHTTPPathDelimiter(ARequest.ReturnedPathInfo);
If (P='') or (P='/') then
P:=IncludeHTTPPathDelimiter(AModuleName);
...
AModule.BaseURL:=S+P;
end;
Here, P, and thus AModule.BaseURL, is where applied IncludeHTTPPathDelimiter to, which is '/' on any platform. What's the problem with this? The answer lies in TFPCustomFileModule.MapFileName, which is used to get the file:
Function TFPCustomFileModule.MapFileName(Const AFileName : String) : String;
...
D:=Locations.Values[BaseURL];
If (D='') then
Result:=''
else
begin
Result:=D+AFileName;
DoDirSeparators(Result);
end;
end;
BaseURL would always have '/' appended, while on Windows it would always be '', causing the module to fail to find the location.
Mantis conversion info:
- Mantis ID: 20714
- Fixed in version: 3.0.0
- Target version: 2.6.1