Fossil SCM

Tolerate CGI systems that do not send REQUEST_URI.

drh 2013-10-17 17:38 trunk
Commit a68280c4fcbdb9a78ef091a6ec561a395e89553e
1 file changed +21 -2
+21 -2
--- src/cgi.c
+++ src/cgi.c
@@ -830,26 +830,45 @@
830830
831831
/*
832832
** Initialize the query parameter database. Information is pulled from
833833
** the QUERY_STRING environment variable (if it exists), from standard
834834
** input if there is POST data, and from HTTP_COOKIE.
835
+**
836
+** We require parameter SCRIPT_NAME and one of REQUEST_URI or PATH_INFO.
837
+** These three are related as following:
838
+**
839
+** REQUEST_URI == SCRIPT_NAME + PATH_INFO
840
+**
841
+** Where "+" means concatenate. One of PATH_INFO or REQUEST_URI can
842
+** be missing and it will be computed from the other two terms.
843
+**
844
+** SCGI typically omits PATH_INFO. CGI sometimes omits REQUEST_URI.
835845
*/
836846
void cgi_init(void){
837847
char *z;
838848
const char *zType;
839849
int len;
840850
const char *zRequestUri = cgi_parameter("REQUEST_URI",0);
841851
const char *zScriptName = cgi_parameter("SCRIPT_NAME",0);
852
+ const char *zPathInfo = cgi_parameter("PATH_INFO",0);
842853
843854
#ifdef FOSSIL_ENABLE_JSON
844855
json_main_bootstrap();
845856
#endif
846857
g.isHTTP = 1;
847858
cgi_destination(CGI_BODY);
848
- if( zRequestUri==0 ) malformed_request("missing REQUEST_URI");
849859
if( zScriptName==0 ) malformed_request("missing SCRIPT_NAME");
850
- if( cgi_parameter("PATH_INFO",0)==0 ){
860
+ if( zRequestUri==0 ){
861
+ const char *z = zPathInfo;
862
+ if( zPathInfo==0 ){
863
+ malformed_request("missing PATH_INFO and/or REQUEST_URI");
864
+ }
865
+ if( z[0]=='/' ) z++;
866
+ zRequestUri = mprintf("%s/%s", zScriptName, z);
867
+ cgi_set_parameter("REQUEST_URI", zRequestUri);
868
+ }
869
+ if( zPathInfo==0 ){
851870
int i, j;
852871
for(i=0; zRequestUri[i]==zScriptName[i] && zRequestUri[i]; i++){}
853872
for(j=i; zRequestUri[j] && zRequestUri[j]!='?'; j++){}
854873
cgi_set_parameter("PATH_INFO", mprintf("%.*s", j-i, zRequestUri+i));
855874
}
856875
--- src/cgi.c
+++ src/cgi.c
@@ -830,26 +830,45 @@
830
831 /*
832 ** Initialize the query parameter database. Information is pulled from
833 ** the QUERY_STRING environment variable (if it exists), from standard
834 ** input if there is POST data, and from HTTP_COOKIE.
 
 
 
 
 
 
 
 
 
 
835 */
836 void cgi_init(void){
837 char *z;
838 const char *zType;
839 int len;
840 const char *zRequestUri = cgi_parameter("REQUEST_URI",0);
841 const char *zScriptName = cgi_parameter("SCRIPT_NAME",0);
 
842
843 #ifdef FOSSIL_ENABLE_JSON
844 json_main_bootstrap();
845 #endif
846 g.isHTTP = 1;
847 cgi_destination(CGI_BODY);
848 if( zRequestUri==0 ) malformed_request("missing REQUEST_URI");
849 if( zScriptName==0 ) malformed_request("missing SCRIPT_NAME");
850 if( cgi_parameter("PATH_INFO",0)==0 ){
 
 
 
 
 
 
 
 
 
851 int i, j;
852 for(i=0; zRequestUri[i]==zScriptName[i] && zRequestUri[i]; i++){}
853 for(j=i; zRequestUri[j] && zRequestUri[j]!='?'; j++){}
854 cgi_set_parameter("PATH_INFO", mprintf("%.*s", j-i, zRequestUri+i));
855 }
856
--- src/cgi.c
+++ src/cgi.c
@@ -830,26 +830,45 @@
830
831 /*
832 ** Initialize the query parameter database. Information is pulled from
833 ** the QUERY_STRING environment variable (if it exists), from standard
834 ** input if there is POST data, and from HTTP_COOKIE.
835 **
836 ** We require parameter SCRIPT_NAME and one of REQUEST_URI or PATH_INFO.
837 ** These three are related as following:
838 **
839 ** REQUEST_URI == SCRIPT_NAME + PATH_INFO
840 **
841 ** Where "+" means concatenate. One of PATH_INFO or REQUEST_URI can
842 ** be missing and it will be computed from the other two terms.
843 **
844 ** SCGI typically omits PATH_INFO. CGI sometimes omits REQUEST_URI.
845 */
846 void cgi_init(void){
847 char *z;
848 const char *zType;
849 int len;
850 const char *zRequestUri = cgi_parameter("REQUEST_URI",0);
851 const char *zScriptName = cgi_parameter("SCRIPT_NAME",0);
852 const char *zPathInfo = cgi_parameter("PATH_INFO",0);
853
854 #ifdef FOSSIL_ENABLE_JSON
855 json_main_bootstrap();
856 #endif
857 g.isHTTP = 1;
858 cgi_destination(CGI_BODY);
 
859 if( zScriptName==0 ) malformed_request("missing SCRIPT_NAME");
860 if( zRequestUri==0 ){
861 const char *z = zPathInfo;
862 if( zPathInfo==0 ){
863 malformed_request("missing PATH_INFO and/or REQUEST_URI");
864 }
865 if( z[0]=='/' ) z++;
866 zRequestUri = mprintf("%s/%s", zScriptName, z);
867 cgi_set_parameter("REQUEST_URI", zRequestUri);
868 }
869 if( zPathInfo==0 ){
870 int i, j;
871 for(i=0; zRequestUri[i]==zScriptName[i] && zRequestUri[i]; i++){}
872 for(j=i; zRequestUri[j] && zRequestUri[j]!='?'; j++){}
873 cgi_set_parameter("PATH_INFO", mprintf("%.*s", j-i, zRequestUri+i));
874 }
875

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button