Fossil SCM
Untested, experimental patch for correct redirect to the /index page when only the CGI script name is specified.
Commit
f66089ec43a9dd200b3c7d20d27ab8d5876073f3
Parent
8fb641e071dc229…
2 files changed
+3
-2
+1
-5
+3
-2
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -295,13 +295,14 @@ | ||
| 295 | 295 | */ |
| 296 | 296 | void cgi_redirect(const char *zURL){ |
| 297 | 297 | char *zLocation; |
| 298 | 298 | CGIDEBUG(("redirect to %s\n", zURL)); |
| 299 | 299 | if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 || *zURL=='/' ){ |
| 300 | - cgi_panic("invalid redirect URL: %s", zURL); | |
| 300 | + zLocation = mprintf("Location: %s\r\n", zURL); | |
| 301 | + }else{ | |
| 302 | + zLocation = mprintf("Location: %s/%s\r\n", g.zBaseURL, zURL); | |
| 301 | 303 | } |
| 302 | - zLocation = mprintf("Location: %s/%s\r\n", g.zBaseURL, zURL); | |
| 303 | 304 | cgi_append_header(zLocation); |
| 304 | 305 | cgi_reset_content(); |
| 305 | 306 | cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zURL); |
| 306 | 307 | cgi_set_status(302, "Moved Temporarily"); |
| 307 | 308 | free(zLocation); |
| 308 | 309 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -295,13 +295,14 @@ | |
| 295 | */ |
| 296 | void cgi_redirect(const char *zURL){ |
| 297 | char *zLocation; |
| 298 | CGIDEBUG(("redirect to %s\n", zURL)); |
| 299 | if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 || *zURL=='/' ){ |
| 300 | cgi_panic("invalid redirect URL: %s", zURL); |
| 301 | } |
| 302 | zLocation = mprintf("Location: %s/%s\r\n", g.zBaseURL, zURL); |
| 303 | cgi_append_header(zLocation); |
| 304 | cgi_reset_content(); |
| 305 | cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zURL); |
| 306 | cgi_set_status(302, "Moved Temporarily"); |
| 307 | free(zLocation); |
| 308 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -295,13 +295,14 @@ | |
| 295 | */ |
| 296 | void cgi_redirect(const char *zURL){ |
| 297 | char *zLocation; |
| 298 | CGIDEBUG(("redirect to %s\n", zURL)); |
| 299 | if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 || *zURL=='/' ){ |
| 300 | zLocation = mprintf("Location: %s\r\n", zURL); |
| 301 | }else{ |
| 302 | zLocation = mprintf("Location: %s/%s\r\n", g.zBaseURL, zURL); |
| 303 | } |
| 304 | cgi_append_header(zLocation); |
| 305 | cgi_reset_content(); |
| 306 | cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zURL); |
| 307 | cgi_set_status(302, "Moved Temporarily"); |
| 308 | free(zLocation); |
| 309 |
+1
-5
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -466,18 +466,14 @@ | ||
| 466 | 466 | ** page. |
| 467 | 467 | */ |
| 468 | 468 | zPathInfo = P("PATH_INFO"); |
| 469 | 469 | if( zPathInfo==0 || zPathInfo[0]==0 ){ |
| 470 | 470 | const char *zUri; |
| 471 | - char *zBase; | |
| 472 | 471 | zUri = PD("REQUEST_URI","/"); |
| 473 | 472 | for(i=0; zUri[i] && zUri[i]!='?' && zUri[i]!='#'; i++){} |
| 474 | 473 | for(j=i; j>0 && zUri[j-1]!='/'; j--){} |
| 475 | - zBase = mprintf("%.*s/index", i-j, &zUri[j]); | |
| 476 | - cgi_redirect(zBase); | |
| 477 | - cgi_reply(); | |
| 478 | - return; | |
| 474 | + cgi_redirectf("%.*s/index", i, zUri); | |
| 479 | 475 | }else{ |
| 480 | 476 | zPath = mprintf("%s", zPathInfo); |
| 481 | 477 | } |
| 482 | 478 | |
| 483 | 479 | /* Remove the leading "/" at the beginning of the path. |
| 484 | 480 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -466,18 +466,14 @@ | |
| 466 | ** page. |
| 467 | */ |
| 468 | zPathInfo = P("PATH_INFO"); |
| 469 | if( zPathInfo==0 || zPathInfo[0]==0 ){ |
| 470 | const char *zUri; |
| 471 | char *zBase; |
| 472 | zUri = PD("REQUEST_URI","/"); |
| 473 | for(i=0; zUri[i] && zUri[i]!='?' && zUri[i]!='#'; i++){} |
| 474 | for(j=i; j>0 && zUri[j-1]!='/'; j--){} |
| 475 | zBase = mprintf("%.*s/index", i-j, &zUri[j]); |
| 476 | cgi_redirect(zBase); |
| 477 | cgi_reply(); |
| 478 | return; |
| 479 | }else{ |
| 480 | zPath = mprintf("%s", zPathInfo); |
| 481 | } |
| 482 | |
| 483 | /* Remove the leading "/" at the beginning of the path. |
| 484 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -466,18 +466,14 @@ | |
| 466 | ** page. |
| 467 | */ |
| 468 | zPathInfo = P("PATH_INFO"); |
| 469 | if( zPathInfo==0 || zPathInfo[0]==0 ){ |
| 470 | const char *zUri; |
| 471 | zUri = PD("REQUEST_URI","/"); |
| 472 | for(i=0; zUri[i] && zUri[i]!='?' && zUri[i]!='#'; i++){} |
| 473 | for(j=i; j>0 && zUri[j-1]!='/'; j--){} |
| 474 | cgi_redirectf("%.*s/index", i, zUri); |
| 475 | }else{ |
| 476 | zPath = mprintf("%s", zPathInfo); |
| 477 | } |
| 478 | |
| 479 | /* Remove the leading "/" at the beginning of the path. |
| 480 |