Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Change unconditional CGI redirects to be 301 Moved Permanently. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
33c1cfde9c6e8d5f4b3b91720264c75b |
| User & Date: | drh 2025-04-04 10:58:31.671 |
Context
|
2025-04-04
| ||
| 12:18 | Enable the search in the built-in help text even without a repository. ... (check-in: 3db304c755 user: tsbg tags: trunk) | |
| 10:58 | Change unconditional CGI redirects to be 301 Moved Permanently. ... (check-in: 33c1cfde9c user: drh tags: trunk) | |
|
2025-04-02
| ||
| 21:00 | allow to use tickets as templates, see [https://fossil-scm.org/forum/forumpost/c9982d733b94e1ac|this forum post] for details ... (check-in: 271a6bd31d user: jkosche tags: trunk) | |
Changes
Changes to src/cgi.c.
| ︙ | ︙ | |||
635 636 637 638 639 640 641 642 643 644 645 646 647 648 |
cgi_reset_content();
cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zLocation);
cgi_set_status(iStat, zStat);
free(zLocation);
cgi_reply();
fossil_exit(0);
}
NORETURN void cgi_redirect(const char *zURL){
cgi_redirect_with_status(zURL, 302, "Moved Temporarily");
}
NORETURN void cgi_redirect_with_method(const char *zURL){
cgi_redirect_with_status(zURL, 307, "Temporary Redirect");
}
NORETURN void cgi_redirectf(const char *zFormat, ...){
| > > > | 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 |
cgi_reset_content();
cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zLocation);
cgi_set_status(iStat, zStat);
free(zLocation);
cgi_reply();
fossil_exit(0);
}
NORETURN void cgi_redirect_perm(const char *zURL){
cgi_redirect_with_status(zURL, 301, "Moved Permanently");
}
NORETURN void cgi_redirect(const char *zURL){
cgi_redirect_with_status(zURL, 302, "Moved Temporarily");
}
NORETURN void cgi_redirect_with_method(const char *zURL){
cgi_redirect_with_status(zURL, 307, "Temporary Redirect");
}
NORETURN void cgi_redirectf(const char *zFormat, ...){
|
| ︙ | ︙ |
Changes to src/main.c.
| ︙ | ︙ | |||
2051 2052 2053 2054 2055 2056 2057 |
/* Use the first element of PATH_INFO as the page name
** and deliver the appropriate page back to the user.
*/
set_base_url(0);
if( fossil_redirect_to_https_if_needed(2) ) return;
if( zPathInfo==0 || zPathInfo[0]==0
|| (zPathInfo[0]=='/' && zPathInfo[1]==0) ){
| | > | 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 |
/* Use the first element of PATH_INFO as the page name
** and deliver the appropriate page back to the user.
*/
set_base_url(0);
if( fossil_redirect_to_https_if_needed(2) ) return;
if( zPathInfo==0 || zPathInfo[0]==0
|| (zPathInfo[0]=='/' && zPathInfo[1]==0) ){
/* Second special case: If the PATH_INFO is blank, issue a
** temporary 302 redirect:
** (1) to "/ckout" if g.useLocalauth and g.localOpen are both set.
** (2) to the home page identified by the "index-page" setting
** in the repository CONFIG table
** (3) to "/index" if there no "index-page" setting in CONFIG
*/
#ifdef FOSSIL_ENABLE_JSON
if(g.json.isJsonMode){
|
| ︙ | ︙ | |||
2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 |
** website we have an CGI at http://fossil.com/index.html (note
** ".com" instead of ".org") that looks like this:
**
** #!/usr/bin/fossil
** redirect: * https://fossil-scm.org/home
**
** Thus requests to the .com website redirect to the .org website.
*/
static void redirect_web_page(int nRedirect, char **azRedirect){
int i; /* Loop counter */
const char *zNotFound = 0; /* Not found URL */
const char *zName = P("name");
set_base_url(0);
if( zName==0 ){
| > > > > > > > > > > > | 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 |
** website we have an CGI at http://fossil.com/index.html (note
** ".com" instead of ".org") that looks like this:
**
** #!/usr/bin/fossil
** redirect: * https://fossil-scm.org/home
**
** Thus requests to the .com website redirect to the .org website.
** This form uses a 301 Permanent redirect.
**
** On a "*" redirect, the PATH_INFO and QUERY_STRING of the query
** that provoked the redirect are appended to the target. So, for
** example, if the input URL for the redirect above were
** "http://www.fossil.com/index.html/timeline?c=20250404", then
** the redirect would be to:
**
** https://fossil-scm.org/home/timeline?c=20250404
** ^^^^^^^^^^^^^^^^^^^^
** Copied from input URL
*/
static void redirect_web_page(int nRedirect, char **azRedirect){
int i; /* Loop counter */
const char *zNotFound = 0; /* Not found URL */
const char *zName = P("name");
set_base_url(0);
if( zName==0 ){
|
| ︙ | ︙ | |||
2295 2296 2297 2298 2299 2300 2301 |
}
}
}
if( zNotFound ){
Blob to;
const char *z;
if( strstr(zNotFound, "%s") ){
| | > | | | 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 |
}
}
}
if( zNotFound ){
Blob to;
const char *z;
if( strstr(zNotFound, "%s") ){
char *zTarget = mprintf(zNotFound /*works-like:"%s"*/, zName);
cgi_redirect_perm(zTarget);
}
if( strchr(zNotFound, '?') ){
cgi_redirect_perm(zNotFound);
}
blob_init(&to, zNotFound, -1);
z = P("PATH_INFO");
if( z && z[0]=='/' ) blob_append(&to, z, -1);
z = P("QUERY_STRING");
if( z && z[0]!=0 ) blob_appendf(&to, "?%s", z);
cgi_redirect_perm(blob_str(&to));
}else{
@ <html>
@ <head><title>No Such Object</title></head>
@ <body>
@ <p>No such object: <b>%h(zName)</b></p>
@ </body>
cgi_reply();
|
| ︙ | ︙ | |||
2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 | ** ** redirect: REPO URL Extract the "name" query parameter and search ** REPO for a check-in or ticket that matches the ** value of "name", then redirect to URL. There ** can be multiple "redirect:" lines that are ** processed in order. If the REPO is "*", then ** an unconditional redirect to URL is taken. ** ** jsmode: VALUE Specifies the delivery mode for JavaScript ** files. See the help text for the --jsmode ** flag of the http command. ** ** mainmenu: FILE Override the mainmenu config setting with the ** contents of the given file. | > > > | 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 | ** ** redirect: REPO URL Extract the "name" query parameter and search ** REPO for a check-in or ticket that matches the ** value of "name", then redirect to URL. There ** can be multiple "redirect:" lines that are ** processed in order. If the REPO is "*", then ** an unconditional redirect to URL is taken. ** When "*" is used a 301 permanent redirect is ** issued and the tail and query string from the ** original query are appeneded onto URL. ** ** jsmode: VALUE Specifies the delivery mode for JavaScript ** files. See the help text for the --jsmode ** flag of the http command. ** ** mainmenu: FILE Override the mainmenu config setting with the ** contents of the given file. |
| ︙ | ︙ |