Fossil SCM
Enhancements to the redirector so that it accepts the redirect value as the $PATH_INFO and so that it can redirect to a relative URL.
Commit
122a31ddfc9d405faeb2634d30eabd6aaf2fa67d
Parent
733361a55eb0eaa…
2 files changed
+5
-2
+12
-3
+5
-2
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -342,18 +342,21 @@ | ||
| 342 | 342 | ** The URL must be relative to the base of the fossil server. |
| 343 | 343 | */ |
| 344 | 344 | void cgi_redirect(const char *zURL){ |
| 345 | 345 | char *zLocation; |
| 346 | 346 | CGIDEBUG(("redirect to %s\n", zURL)); |
| 347 | - if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 || *zURL=='/' ){ | |
| 347 | + if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 ){ | |
| 348 | 348 | zLocation = mprintf("Location: %s\r\n", zURL); |
| 349 | + }else if( *zURL=='/' ){ | |
| 350 | + zLocation = mprintf("Location: %.*s%s\r\n", | |
| 351 | + strlen(g.zBaseURL)-strlen(g.zTop), g.zBaseURL, zURL); | |
| 349 | 352 | }else{ |
| 350 | 353 | zLocation = mprintf("Location: %s/%s\r\n", g.zBaseURL, zURL); |
| 351 | 354 | } |
| 352 | 355 | cgi_append_header(zLocation); |
| 353 | 356 | cgi_reset_content(); |
| 354 | - cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zURL); | |
| 357 | + cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zLocation); | |
| 355 | 358 | cgi_set_status(302, "Moved Temporarily"); |
| 356 | 359 | free(zLocation); |
| 357 | 360 | cgi_reply(); |
| 358 | 361 | fossil_exit(0); |
| 359 | 362 | } |
| 360 | 363 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -342,18 +342,21 @@ | |
| 342 | ** The URL must be relative to the base of the fossil server. |
| 343 | */ |
| 344 | void cgi_redirect(const char *zURL){ |
| 345 | char *zLocation; |
| 346 | CGIDEBUG(("redirect to %s\n", zURL)); |
| 347 | if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 || *zURL=='/' ){ |
| 348 | zLocation = mprintf("Location: %s\r\n", zURL); |
| 349 | }else{ |
| 350 | zLocation = mprintf("Location: %s/%s\r\n", g.zBaseURL, zURL); |
| 351 | } |
| 352 | cgi_append_header(zLocation); |
| 353 | cgi_reset_content(); |
| 354 | cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zURL); |
| 355 | cgi_set_status(302, "Moved Temporarily"); |
| 356 | free(zLocation); |
| 357 | cgi_reply(); |
| 358 | fossil_exit(0); |
| 359 | } |
| 360 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -342,18 +342,21 @@ | |
| 342 | ** The URL must be relative to the base of the fossil server. |
| 343 | */ |
| 344 | void cgi_redirect(const char *zURL){ |
| 345 | char *zLocation; |
| 346 | CGIDEBUG(("redirect to %s\n", zURL)); |
| 347 | if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 ){ |
| 348 | zLocation = mprintf("Location: %s\r\n", zURL); |
| 349 | }else if( *zURL=='/' ){ |
| 350 | zLocation = mprintf("Location: %.*s%s\r\n", |
| 351 | strlen(g.zBaseURL)-strlen(g.zTop), g.zBaseURL, zURL); |
| 352 | }else{ |
| 353 | zLocation = mprintf("Location: %s/%s\r\n", g.zBaseURL, zURL); |
| 354 | } |
| 355 | cgi_append_header(zLocation); |
| 356 | cgi_reset_content(); |
| 357 | cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zLocation); |
| 358 | cgi_set_status(302, "Moved Temporarily"); |
| 359 | free(zLocation); |
| 360 | cgi_reply(); |
| 361 | fossil_exit(0); |
| 362 | } |
| 363 |
+12
-3
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -796,14 +796,18 @@ | ||
| 796 | 796 | ** the fossil tree. Set g.zTop to g.zBaseURL without the |
| 797 | 797 | ** leading "http://" and the host and port. |
| 798 | 798 | */ |
| 799 | 799 | void set_base_url(void){ |
| 800 | 800 | int i; |
| 801 | - const char *zHost = PD("HTTP_HOST",""); | |
| 802 | - const char *zMode = PD("HTTPS","off"); | |
| 803 | - const char *zCur = PD("SCRIPT_NAME","/"); | |
| 801 | + const char *zHost; | |
| 802 | + const char *zMode; | |
| 803 | + const char *zCur; | |
| 804 | 804 | |
| 805 | + if( g.zBaseURL!=0 ) return; | |
| 806 | + zHost = PD("HTTP_HOST",""); | |
| 807 | + zMode = PD("HTTPS","off"); | |
| 808 | + zCur = PD("SCRIPT_NAME","/"); | |
| 805 | 809 | i = strlen(zCur); |
| 806 | 810 | while( i>0 && zCur[i-1]=='/' ) i--; |
| 807 | 811 | if( strcmp(zMode,"on")==0 ){ |
| 808 | 812 | g.zBaseURL = mprintf("https://%s%.*s", zHost, i, zCur); |
| 809 | 813 | g.zTop = &g.zBaseURL[8+strlen(zHost)]; |
| @@ -1123,10 +1127,15 @@ | ||
| 1123 | 1127 | */ |
| 1124 | 1128 | void redirect_web_page(int nRedirect, char **azRedirect){ |
| 1125 | 1129 | int i; /* Loop counter */ |
| 1126 | 1130 | const char *zNotFound = 0; /* Not found URL */ |
| 1127 | 1131 | const char *zName = P("name"); |
| 1132 | + set_base_url(); | |
| 1133 | + if( zName==0 ){ | |
| 1134 | + zName = P("SCRIPT_NAME"); | |
| 1135 | + if( zName && zName[0]=='/' ) zName++; | |
| 1136 | + } | |
| 1128 | 1137 | if( zName && validate16(zName, strlen(zName)) ){ |
| 1129 | 1138 | for(i=0; i<nRedirect; i++){ |
| 1130 | 1139 | if( strcmp(azRedirect[i*2],"*")==0 ){ |
| 1131 | 1140 | zNotFound = azRedirect[i*2+1]; |
| 1132 | 1141 | continue; |
| 1133 | 1142 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -796,14 +796,18 @@ | |
| 796 | ** the fossil tree. Set g.zTop to g.zBaseURL without the |
| 797 | ** leading "http://" and the host and port. |
| 798 | */ |
| 799 | void set_base_url(void){ |
| 800 | int i; |
| 801 | const char *zHost = PD("HTTP_HOST",""); |
| 802 | const char *zMode = PD("HTTPS","off"); |
| 803 | const char *zCur = PD("SCRIPT_NAME","/"); |
| 804 | |
| 805 | i = strlen(zCur); |
| 806 | while( i>0 && zCur[i-1]=='/' ) i--; |
| 807 | if( strcmp(zMode,"on")==0 ){ |
| 808 | g.zBaseURL = mprintf("https://%s%.*s", zHost, i, zCur); |
| 809 | g.zTop = &g.zBaseURL[8+strlen(zHost)]; |
| @@ -1123,10 +1127,15 @@ | |
| 1123 | */ |
| 1124 | void redirect_web_page(int nRedirect, char **azRedirect){ |
| 1125 | int i; /* Loop counter */ |
| 1126 | const char *zNotFound = 0; /* Not found URL */ |
| 1127 | const char *zName = P("name"); |
| 1128 | if( zName && validate16(zName, strlen(zName)) ){ |
| 1129 | for(i=0; i<nRedirect; i++){ |
| 1130 | if( strcmp(azRedirect[i*2],"*")==0 ){ |
| 1131 | zNotFound = azRedirect[i*2+1]; |
| 1132 | continue; |
| 1133 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -796,14 +796,18 @@ | |
| 796 | ** the fossil tree. Set g.zTop to g.zBaseURL without the |
| 797 | ** leading "http://" and the host and port. |
| 798 | */ |
| 799 | void set_base_url(void){ |
| 800 | int i; |
| 801 | const char *zHost; |
| 802 | const char *zMode; |
| 803 | const char *zCur; |
| 804 | |
| 805 | if( g.zBaseURL!=0 ) return; |
| 806 | zHost = PD("HTTP_HOST",""); |
| 807 | zMode = PD("HTTPS","off"); |
| 808 | zCur = PD("SCRIPT_NAME","/"); |
| 809 | i = strlen(zCur); |
| 810 | while( i>0 && zCur[i-1]=='/' ) i--; |
| 811 | if( strcmp(zMode,"on")==0 ){ |
| 812 | g.zBaseURL = mprintf("https://%s%.*s", zHost, i, zCur); |
| 813 | g.zTop = &g.zBaseURL[8+strlen(zHost)]; |
| @@ -1123,10 +1127,15 @@ | |
| 1127 | */ |
| 1128 | void redirect_web_page(int nRedirect, char **azRedirect){ |
| 1129 | int i; /* Loop counter */ |
| 1130 | const char *zNotFound = 0; /* Not found URL */ |
| 1131 | const char *zName = P("name"); |
| 1132 | set_base_url(); |
| 1133 | if( zName==0 ){ |
| 1134 | zName = P("SCRIPT_NAME"); |
| 1135 | if( zName && zName[0]=='/' ) zName++; |
| 1136 | } |
| 1137 | if( zName && validate16(zName, strlen(zName)) ){ |
| 1138 | for(i=0; i<nRedirect; i++){ |
| 1139 | if( strcmp(azRedirect[i*2],"*")==0 ){ |
| 1140 | zNotFound = azRedirect[i*2+1]; |
| 1141 | continue; |
| 1142 |