[fpc-pascal] FastCGI on Windows IIS

Marcos Douglas md at delfire.net
Wed Apr 27 06:11:22 CEST 2016


On Tue, Apr 26, 2016 at 10:55 AM, Marcos Douglas <md at delfire.net> wrote:
> On Tue, Apr 26, 2016 at 3:39 AM, Michael Van Canneyt
> <michael at freepascal.org> wrote:
>> Well, time is of course an issue, but more importantly, I do not have ISS to
>> test with.
>>
>> I think that PATHINFO needs to be corrected in  custcgi.pp:
>>
>> Procedure TCGIRequest.InitFromEnvironment:
>>
>> Something like If Pos('IIS', ServerName)>0 then
>>   // Cut binary name from PathInfo
>>
>> It will then also be fixed for FastCGI as it reuses this routine.

Hi Michael,

Using the original sources of version 2.6.5 I can get the
SERVER_SOFTWARE=Microsoft-IIS/10.0

So, I replaced the fcl-web package, version 2.6.5 to use 3.1.1. But in
this last version SERVER_SOFTWARE is empty. I don't know why.

Look the code below.

===BEGIN===
procedure TCGIRequest.InitFromEnvironment;


Var
  I : Integer;
  R,V,OV : String;
  M : TMap;

begin
  For I:=1 to CGIVarCount do
    begin
    V:=GetEnvironmentVariable(CGIVarNames[I]);
    if (V<>'') then
      begin
      M:=MapCgiToHTTP[i];
      if M.H<>hhUnknown then
        SetHeader(M.H,HTTPDecode(V))
      else if M.V<>hvUnknown then
        begin
        if M.V<>hvQuery then
          V:=HTTPDecode(V);
        SetHTTPVariable(M.V,V)
        end;
      end;
    end;
//---------------------
  if Pos('IIS', ServerSoftware) > 0 then
    PathInfo := StringReplace(PathInfo, ScriptName, '', []);
//---------------------
  R:=UpCase(Method);
  if (R='POST') or (R='PUT') or (ContentLength>0) then
    ReadContent;
end;

===END===

Only these lines are new:
  if Pos('IIS', ServerSoftware) > 0 then
    PathInfo := StringReplace(PathInfo, ScriptName, '', []);

Nothing happens, because ServerSoftware is empty.
If I comment the first line, the PathInfo will be fixed but I got this error:
"Could not determine HTTP module for request "list""

Consider this:
1- PathInfo and ScriptName are properties of THTTPHeader class
2- ServerSoftware is a property of TCGIRequest

So, on this version you check: M.H<>hhUnknown or M.V<>hvUnknown, then
I'd tryed to implement:

[unit custcgi, line 166,  const MapCgiToHTTP]
{ 17: 'SERVER_SOFTWARE'        } (h:hhUnknown; v : hvServerSoftware),

...and added in httpdefs.THTTPVariableType too

...and I'd implemented this property too:
THTTPReader
    Property ServerSoftware : String Index Ord(hvServerSoftware) read
GetHTTPVariable Write SetHTTPVariable;

Does't work.

So, now I have 2 problems:
1- If I change the PathInfo without check ServerName, I can fix it but
the app raise an exception;
2- ServerSoftware doesn't work in version 3.1.1 .

Regards,
Marcos Douglas



More information about the fpc-pascal mailing list