View Issue Details

IDProjectCategoryView StatusLast Update
0030073FPCFCLpublic2017-04-07 14:47
ReporterMarcos Douglas Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformi386/x86_64OSWindows 
Product Version3.1.1 
Target Version3.0.2Fixed in Version3.1.1 
Summary0030073: fcl-web: PATH_INFO variable on Microsoft-IIS
DescriptionI have one module:
ModuleName= 'pdf'
ModuleClass= TPDFModule

and two actions:
'act1'
'act2'

Browser:
http://localhost:2015/fcgitest/pdf/act1

Error:

The application encountered the following error:
Error: Could not determine HTTP module for request "fcgitest.exe"
Stack trace:
$004328E3
$00433012
$004323E2

The problem is the PATH_INFO variable.
I'm sending a patch to fix this.
Steps To ReproduceJust call an URL with module and action.
TagsNo tags attached.
Fixed in Revision33613,34466.
FPCOldBugId
FPCTarget
Attached Files

Activities

Marcos Douglas

2016-04-28 03:17

reporter  

fcl-web-base.patch (3,506 bytes)   
Index: packages/fcl-web/src/base/custcgi.pp
===================================================================
--- packages/fcl-web/src/base/custcgi.pp	(revision 33565)
+++ packages/fcl-web/src/base/custcgi.pp	(working copy)
@@ -180,7 +180,7 @@
     { 14: 'SERVER_NAME'            } (h:hhServer; v : hvUnknown),
     { 15: 'SERVER_PORT'            } (h:hhUnknown; v : hvServerPort),
     { 16: 'SERVER_PROTOCOL'        } (h:hhUnknown; v : hvUnknown),
-    { 17: 'SERVER_SOFTWARE'        } (h:hhUnknown; v : hvUnknown),
+    { 17: 'SERVER_SOFTWARE'        } (h:hhUnknown; v : hvServerSoftware),
     { 18: 'HTTP_ACCEPT'            } (h:hhAccept; v : hvUnknown),
     { 19: 'HTTP_ACCEPT_CHARSET'    } (h:hhAcceptCharset; v : hvUnknown),
     { 20: 'HTTP_ACCEPT_ENCODING'   } (h:hhAcceptEncoding; v : hvUnknown),
@@ -318,7 +318,7 @@
 function TCGIRequest.DoGetCGIVar(AVarName : String) : String;
 
 begin
-  GetEnvironmentVariable(AVarName);
+  Result := GetEnvironmentVariable(AVarName);
 end;
 
 function TCGIRequest.GetCGIVar(Index: integer): String;
@@ -349,30 +349,37 @@
 end;
 
 procedure TCGIRequest.InitFromEnvironment;
-
-
-Var
+var
   I : Integer;
-  R,V,OV : String;
+  R,V : string;
   M : TMap;
-  
 begin
   For I:=1 to CGIVarCount do
-    begin
+  begin
     V:=GetEnvironmentVariable(CGIVarNames[I]);
     if (V<>'') then
-      begin
+    begin
       M:=MapCgiToHTTP[i];
       if M.H<>hhUnknown then
         SetHeader(M.H,HTTPDecode(V))
       else if M.V<>hvUnknown then
-        begin
+      begin
         if M.V<>hvQuery then
           V:=HTTPDecode(V);
         SetHTTPVariable(M.V,V)
-        end;
       end;
     end;
+  end;
+
+  // Microsoft-IIS hack
+  if Pos('IIS', ServerSoftware) > 0 then
+  begin
+    SetHTTPVariable(
+      hvPathInfo,
+      StringReplace(PathInfo, ScriptName, '', [rfReplaceAll, rfIgnoreCase])
+    );
+  end;
+
   R:=UpCase(Method);
   if (R='POST') or (R='PUT') or (ContentLength>0) then
     ReadContent;
Index: packages/fcl-web/src/base/httpdefs.pp
===================================================================
--- packages/fcl-web/src/base/httpdefs.pp	(revision 33565)
+++ packages/fcl-web/src/base/httpdefs.pp	(working copy)
@@ -110,7 +110,7 @@
   // HTTP related variables.
   THTTPVariableType = (hvUnknown,hvHTTPVersion, hvMethod, hvCookie, hvSetCookie, hvXRequestedWith,
                    hvPathInfo,hvPathTranslated,hvRemoteAddress,hvRemoteHost,hvScriptName,
-                   hvServerPort,hvURL,hvQuery,hvContent);
+                   hvServerPort,hvURL,hvQuery,hvContent,hvServerSoftware);
   THTTPVariableTypes = Set of THTTPVariableType;
 
 Type
@@ -389,6 +389,7 @@
     Property RemoteHost : String Index Ord(hvRemoteHost) read  GetHTTPVariable Write SetHTTPVariable;
     Property ScriptName : String Index Ord(hvScriptName) read  GetHTTPVariable Write SetHTTPVariable;
     Property ServerPort : Word Read GetServerPort Write SetServerPort; // Index 30
+    Property ServerSoftware : String Index Ord(hvServerSoftware) read  GetHTTPVariable Write SetHTTPVariable;
     Property Method : String Index Ord(hvMethod) read GetHTTPVariable Write SetHTTPVariable;
     Property URL : String Index Ord(hvURL) read GetHTTPVariable Write SetHTTPVariable;
     Property Query : String Index Ord(hvQuery) read GetHTTPVariable Write SetHTTPVariable;
@@ -956,7 +957,7 @@
       (-1,
        0,31,11,22,36,
        25,26,27,28,29,
-       30,32,33,35);
+       30,32,33,35,17);
 
 begin
   Result:=High(THTTPVariableType);
fcl-web-base.patch (3,506 bytes)   

Michael Van Canneyt

2016-04-30 08:32

administrator   ~0092302

Thank you for the patch. I have applied the patch partially.

I did not add ServerSoftware to TRequest. It is already defined in TCGIRequest.

ServerSoftware is a CGI only variable, and is not part of the HTTP protocol.
So, it is only defined in TCGIRequest, not in TRequest.

A person that knows he is using CGI/FastCGI only can do a typecast
(Request as TCGIRequest)
to access additional CGI variables.

Please test and close the issue if OK.

Marcos Douglas

2016-04-30 16:10

reporter   ~0092314

Sorry my first long patch. Indeed you're right about ServerSoftware is a CGI only variable, and is not part of the HTTP protocol, of course.
But to work propertly you need this second patch — was part of the first one — that I'm attaching.

Marcos Douglas

2016-04-30 16:11

reporter  

custcgi.pp.patch (472 bytes)   
Index: packages/fcl-web/src/base/custcgi.pp
===================================================================
--- packages/fcl-web/src/base/custcgi.pp	(revision 33581)
+++ packages/fcl-web/src/base/custcgi.pp	(working copy)
@@ -318,7 +318,7 @@
 function TCGIRequest.DoGetCGIVar(AVarName : String) : String;
 
 begin
-  GetEnvironmentVariable(AVarName);
+  Result := GetEnvironmentVariable(AVarName);
 end;
 
 function TCGIRequest.GetCGIVar(Index: integer): String;
custcgi.pp.patch (472 bytes)   

Michael Van Canneyt

2016-05-02 15:18

administrator   ~0092337

Hm. Very strange that I never had problems with the existing code.
Maybe because I work only on 64-bit.

Applied your patch in 33613.

(I didn't notice this in your first patch, sorry!)

Marcos Douglas

2016-05-02 19:45

reporter   ~0092344

Thanks.

Marcos Douglas

2016-08-29 05:56

reporter   ~0094336

The same problem is occurring when using FastCGI.
I think TCGIRequest.InitFromEnvironment is not used by FastCGI module.

I'm trying with FPC 3.0.1 (fixes_3_0) and trunk

Marcos Douglas

2016-08-29 06:47

reporter  

custfcgi.pp.patch (612 bytes)   
Index: packages/fcl-web/src/base/custfcgi.pp
===================================================================
--- packages/fcl-web/src/base/custfcgi.pp	(revision 34383)
+++ packages/fcl-web/src/base/custfcgi.pp	(working copy)
@@ -354,6 +354,9 @@
     else
       NameValueList.Add(Name+'='+Value)
     end;
+  // Microsoft-IIS hack. IIS includes the script name in the PATH_INFO
+  if Pos('IIS', ServerSoftware) > 0 then
+    SetHTTPVariable(hvPathInfo,StringReplace(PathInfo, ScriptName, '', [rfReplaceAll, rfIgnoreCase]));
 end;
 
 procedure TFCGIRequest.Log(EventType: TEventType; const Msg: String);
custfcgi.pp.patch (612 bytes)   

Marcos Douglas

2016-08-29 06:51

reporter   ~0094338

I sent a new patch (custfcgi.pp.patch).
Solves my problem, but I don't like this solution because the "IIS hack" now exists in two units.

Michael Van Canneyt

2016-09-09 08:07

administrator   ~0094501

Applied second patch. Thanks for the patches.

Issue History

Date Modified Username Field Change
2016-04-28 03:17 Marcos Douglas New Issue
2016-04-28 03:17 Marcos Douglas File Added: fcl-web-base.patch
2016-04-30 08:11 Michael Van Canneyt Assigned To => Michael Van Canneyt
2016-04-30 08:11 Michael Van Canneyt Status new => assigned
2016-04-30 08:32 Michael Van Canneyt Fixed in Revision => 33576
2016-04-30 08:32 Michael Van Canneyt Note Added: 0092302
2016-04-30 08:32 Michael Van Canneyt Status assigned => resolved
2016-04-30 08:32 Michael Van Canneyt Fixed in Version => 3.1.1
2016-04-30 08:32 Michael Van Canneyt Resolution open => fixed
2016-04-30 08:32 Michael Van Canneyt Target Version => 3.0.2
2016-04-30 16:10 Marcos Douglas Note Added: 0092314
2016-04-30 16:10 Marcos Douglas Status resolved => feedback
2016-04-30 16:10 Marcos Douglas Resolution fixed => reopened
2016-04-30 16:11 Marcos Douglas File Added: custcgi.pp.patch
2016-05-02 15:18 Michael Van Canneyt Fixed in Revision 33576 => 33613
2016-05-02 15:18 Michael Van Canneyt Note Added: 0092337
2016-05-02 15:18 Michael Van Canneyt Status feedback => resolved
2016-05-02 15:18 Michael Van Canneyt Resolution reopened => fixed
2016-05-02 19:45 Marcos Douglas Note Added: 0092344
2016-05-02 19:45 Marcos Douglas Status resolved => closed
2016-08-29 05:56 Marcos Douglas Note Added: 0094336
2016-08-29 05:56 Marcos Douglas Status closed => feedback
2016-08-29 05:56 Marcos Douglas Resolution fixed => reopened
2016-08-29 06:47 Marcos Douglas File Added: custfcgi.pp.patch
2016-08-29 06:51 Marcos Douglas Note Added: 0094338
2016-08-29 06:51 Marcos Douglas Status feedback => assigned
2016-09-09 08:07 Michael Van Canneyt Fixed in Revision 33613 => 33613,34466.
2016-09-09 08:07 Michael Van Canneyt Note Added: 0094501
2016-09-09 08:07 Michael Van Canneyt Status assigned => resolved
2016-09-09 08:07 Michael Van Canneyt Resolution reopened => fixed
2017-04-07 14:47 Marcos Douglas Status resolved => closed