Fossil SCM

Untested, experimental patch for correct redirect to the /index page when only the CGI script name is specified.

drh 2007-10-23 18:04 UTC trunk
Commit f66089ec43a9dd200b3c7d20d27ab8d5876073f3
2 files changed +3 -2 +1 -5
+3 -2
--- src/cgi.c
+++ src/cgi.c
@@ -295,13 +295,14 @@
295295
*/
296296
void cgi_redirect(const char *zURL){
297297
char *zLocation;
298298
CGIDEBUG(("redirect to %s\n", zURL));
299299
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);
301303
}
302
- zLocation = mprintf("Location: %s/%s\r\n", g.zBaseURL, zURL);
303304
cgi_append_header(zLocation);
304305
cgi_reset_content();
305306
cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zURL);
306307
cgi_set_status(302, "Moved Temporarily");
307308
free(zLocation);
308309
--- 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 @@
466466
** page.
467467
*/
468468
zPathInfo = P("PATH_INFO");
469469
if( zPathInfo==0 || zPathInfo[0]==0 ){
470470
const char *zUri;
471
- char *zBase;
472471
zUri = PD("REQUEST_URI","/");
473472
for(i=0; zUri[i] && zUri[i]!='?' && zUri[i]!='#'; i++){}
474473
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);
479475
}else{
480476
zPath = mprintf("%s", zPathInfo);
481477
}
482478
483479
/* Remove the leading "/" at the beginning of the path.
484480
--- 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

Keyboard Shortcuts

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