Fossil

Check-in [a68280c4]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Tolerate CGI systems that do not send REQUEST_URI.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:a68280c4fcbdb9a78ef091a6ec561a395e89553e
User & Date: drh 2013-10-17 17:38:11
Context
2013-10-17
18:10
Update the change log. No changes to code. check-in: d694ef08 user: drh tags: trunk
17:38
Tolerate CGI systems that do not send REQUEST_URI. check-in: a68280c4 user: drh tags: trunk
16:10
minor typo fix. check-in: bd209802 user: stephan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/cgi.c.

   828    828   /* Forward declaration */
   829    829   static NORETURN void malformed_request(const char *zMsg);
   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   
   857    876     z = (char*)P("HTTP_COOKIE");