Fossil SCM
Tolerate CGI systems that do not send REQUEST_URI.
Commit
a68280c4fcbdb9a78ef091a6ec561a395e89553e
Parent
bd209802bfcf4c7…
1 file changed
+21
-2
+21
-2
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -830,26 +830,45 @@ | ||
| 830 | 830 | |
| 831 | 831 | /* |
| 832 | 832 | ** Initialize the query parameter database. Information is pulled from |
| 833 | 833 | ** the QUERY_STRING environment variable (if it exists), from standard |
| 834 | 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. | |
| 835 | 845 | */ |
| 836 | 846 | void cgi_init(void){ |
| 837 | 847 | char *z; |
| 838 | 848 | const char *zType; |
| 839 | 849 | int len; |
| 840 | 850 | const char *zRequestUri = cgi_parameter("REQUEST_URI",0); |
| 841 | 851 | const char *zScriptName = cgi_parameter("SCRIPT_NAME",0); |
| 852 | + const char *zPathInfo = cgi_parameter("PATH_INFO",0); | |
| 842 | 853 | |
| 843 | 854 | #ifdef FOSSIL_ENABLE_JSON |
| 844 | 855 | json_main_bootstrap(); |
| 845 | 856 | #endif |
| 846 | 857 | g.isHTTP = 1; |
| 847 | 858 | cgi_destination(CGI_BODY); |
| 848 | - if( zRequestUri==0 ) malformed_request("missing REQUEST_URI"); | |
| 849 | 859 | 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 ){ | |
| 851 | 870 | int i, j; |
| 852 | 871 | for(i=0; zRequestUri[i]==zScriptName[i] && zRequestUri[i]; i++){} |
| 853 | 872 | for(j=i; zRequestUri[j] && zRequestUri[j]!='?'; j++){} |
| 854 | 873 | cgi_set_parameter("PATH_INFO", mprintf("%.*s", j-i, zRequestUri+i)); |
| 855 | 874 | } |
| 856 | 875 |
| --- 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 |