View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0020714FPCCompilerpublic2011-11-20 16:492012-07-10 17:21
ReporterMario Ray Mahardhika 
Assigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product VersionProduct Build 
Target Version2.6.1Fixed in Version2.7.1 
Summary0020714: HTTP server application will never work on Windows
DescriptionI'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.
TagsNo tags attached.
FPCOldBugId0
Fixed in Revision
Attached Filesdiff file icon fpwebfile.diff [^] (759 bytes) 2012-03-14 14:05 [Show Content]

- Relationships

-  Notes
(0057574)
Max Nazhalov (reporter)
2012-03-13 13:35
edited on: 2012-03-13 13:54

The reason of failure is uncertain, let's see rtl\win32\system.pp:

 DirectorySeparator = '\';
 AllowDirectorySeparators : set of char = ['\','/'];

so the DoDirSeparators call will replace '/' to '\'.

Moreover, Windows should treat '/' as '\' in this case.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247 [^]

"Note File I/O functions in the Windows API convert "/" to "\" as part of converting the name to an NT-style name, except when using the "\\?\" prefix as detailed in the following sections.."

(0057596)
Mario Ray Mahardhika (reporter)
2012-03-13 17:20

Before going to DoDirSeparators, D would be '' first, so worrying that doesn't make sense. It's Locations.Values[BaseURL] that causes the problem due to different path separator used in BaseURL when adding and searching the value.
(0057636)
Max Nazhalov (reporter)
2012-03-14 13:52
edited on: 2012-03-14 13:57

Yes, indeed "Locations" is just "TStrings" and does not care about any directory separators or so while searching for a matching string. That's may be a problem when it is used with such lack of care as in this case..

(0057640)
Michael Van Canneyt (administrator)
2012-03-14 14:06

Can you please apply the attached patch, and check if it helps ?
I don't have a windows installation available ATM.
(0057703)
Mario Ray Mahardhika (reporter)
2012-03-16 10:21

To which revision?
(0057704)
Michael Van Canneyt (administrator)
2012-03-16 10:26

Latest SVN, but I suspect it will work on earlier versions as well.
(0057877)
Mario Ray Mahardhika (reporter)
2012-03-21 16:50

Sorry for the long reply, I just got a free time for my Windows :)
Yep, the patch seems working.
(0060953)
Michael Van Canneyt (administrator)
2012-07-10 17:16

Conformed as fixed by reporter.

- Issue History
Date Modified Username Field Change
2011-11-20 16:49 Mario Ray Mahardhika New Issue
2011-11-20 16:49 Mario Ray Mahardhika Widgetset => Win32/Win64
2012-03-13 10:22 Vincent Snijders Project Packages => FPC
2012-03-13 13:17 Max Nazhalov Note Added: 0057573
2012-03-13 13:19 Max Nazhalov Note Deleted: 0057573
2012-03-13 13:35 Max Nazhalov Note Added: 0057574
2012-03-13 13:54 Max Nazhalov Note Edited: 0057574
2012-03-13 14:38 Jonas Maebe FPCOldBugId => 0
2012-03-13 14:38 Jonas Maebe Severity feature => minor
2012-03-13 14:38 Jonas Maebe Category - => Compiler
2012-03-13 14:38 Jonas Maebe Product Version 0.9.31 (SVN) =>
2012-03-13 14:38 Jonas Maebe Status new => assigned
2012-03-13 14:38 Jonas Maebe Assigned To => Michael Van Canneyt
2012-03-13 17:20 Mario Ray Mahardhika Note Added: 0057596
2012-03-14 13:52 Max Nazhalov Note Added: 0057636
2012-03-14 13:57 Max Nazhalov Note Edited: 0057636
2012-03-14 14:05 Michael Van Canneyt File Added: fpwebfile.diff
2012-03-14 14:06 Michael Van Canneyt Note Added: 0057640
2012-03-14 14:06 Michael Van Canneyt Status assigned => feedback
2012-03-16 10:21 Mario Ray Mahardhika Note Added: 0057703
2012-03-16 10:26 Michael Van Canneyt Note Added: 0057704
2012-03-21 16:50 Mario Ray Mahardhika Note Added: 0057877
2012-04-21 16:26 Marco van de Voort Status feedback => confirmed
2012-07-10 17:16 Michael Van Canneyt Status confirmed => resolved
2012-07-10 17:16 Michael Van Canneyt Fixed in Version => 2.7.1
2012-07-10 17:16 Michael Van Canneyt Resolution open => fixed
2012-07-10 17:16 Michael Van Canneyt Note Added: 0060953
2012-07-10 17:16 Michael Van Canneyt Target Version => 2.6.1
2012-07-10 17:21 Mario Ray Mahardhika Status resolved => closed



MantisBT 1.2.12[^]
Copyright © 2000 - 2012 MantisBT Group
Powered by Mantis Bugtracker