Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Enhance TH1 'redirect' command to support for HTTP redirects with a status code of 307. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
bee6dbde5498e07d7876abe206792b2b |
| User & Date: | mistachkin 2016-12-19 07:04:50.939 |
Context
|
2016-12-23
| ||
| 23:25 | Update the built-in SQLite to the latest 3.16.0 alpha for testing. ... (check-in: 20cffa1f89 user: drh tags: trunk) | |
|
2016-12-21
| ||
| 17:50 | When calling gdiff (or stash gdiff) command between 2 versions, use the filename to prefix the temporary random filename so once inside the external diff program we know what file is being compared. (pending-review) ... (Closed-Leaf check-in: 856ca01b13 user: mgagnon tags: gdiff-tmpfilename-prefix) | |
|
2016-12-19
| ||
| 07:04 | Enhance TH1 'redirect' command to support for HTTP redirects with a status code of 307. ... (check-in: bee6dbde54 user: mistachkin tags: trunk) | |
|
2016-12-14
| ||
| 01:09 | Fix the logic that combines merge risers (originally added to trunk by check-in [95d6ddc3]). Add test cases for this fix to graph-test-1.wiki. ... (check-in: 9ed134360b user: drh tags: trunk) | |
Changes
Changes to src/cgi.c.
| ︙ | ︙ | |||
398 399 400 401 402 403 404 | } /* ** Do a redirect request to the URL given in the argument. ** ** The URL must be relative to the base of the fossil server. */ | > | > > > | > > > > > > | 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
}
/*
** Do a redirect request to the URL given in the argument.
**
** The URL must be relative to the base of the fossil server.
*/
NORETURN static void cgi_redirect_with_status(
const char *zURL,
int iStat,
const char *zStat
){
char *zLocation;
CGIDEBUG(("redirect to %s\n", zURL));
if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 ){
zLocation = mprintf("Location: %s\r\n", zURL);
}else if( *zURL=='/' ){
int n1 = (int)strlen(g.zBaseURL);
int n2 = (int)strlen(g.zTop);
if( g.zBaseURL[n1-1]=='/' ) zURL++;
zLocation = mprintf("Location: %.*s%s\r\n", n1-n2, g.zBaseURL, zURL);
}else{
zLocation = mprintf("Location: %s/%s\r\n", g.zBaseURL, zURL);
}
cgi_append_header(zLocation);
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, ...){
va_list ap;
va_start(ap, zFormat);
cgi_redirect(vmprintf(zFormat, ap));
va_end(ap);
}
|
| ︙ | ︙ |
Changes to src/th_main.c.
| ︙ | ︙ | |||
430 431 432 433 434 435 436 |
return Th_WrongNumArgs(interp, "puts STRING");
}
sendText((char*)argv[1], argl[1], *(unsigned int*)pConvert);
return TH_OK;
}
/*
| | | > > > > | > | | > > > > > > > > | > | 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
return Th_WrongNumArgs(interp, "puts STRING");
}
sendText((char*)argv[1], argl[1], *(unsigned int*)pConvert);
return TH_OK;
}
/*
** TH1 command: redirect URL ?withMethod?
**
** Issues an HTTP redirect to the specified URL and then exits the process.
** By default, an HTTP status code of 302 is used. If the optional withMethod
** argument is present and non-zero, an HTTP status code of 307 is used, which
** should force the user agent to preserve the original method for the request
** (e.g. GET, POST) instead of (possibly) forcing the user agent to change the
** method to GET.
*/
static int redirectCmd(
Th_Interp *interp,
void *p,
int argc,
const char **argv,
int *argl
){
int withMethod = 0;
if( argc!=2 && argc!=3 ){
return Th_WrongNumArgs(interp, "redirect URL ?withMethod?");
}
if( argc==3 ){
if( Th_ToInt(interp, argv[2], argl[2], &withMethod) ){
return TH_ERROR;
}
}
if( withMethod ){
cgi_redirect_with_method(argv[1]);
}else{
cgi_redirect(argv[1]);
}
Th_SetResult(interp, argv[1], argl[1]); /* NOT REACHED */
return TH_OK;
}
/*
** TH1 command: insertCsrf
**
|
| ︙ | ︙ |
Changes to www/th1.md.
| ︙ | ︙ | |||
438 439 440 441 442 443 444 | Returns a string of N*2 random hexadecimal digits with N<50. If N is omitted, use a value of 10. <a name="redirect"></a>TH1 redirect Command ------------------------------------------- | | | | > > > > | 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | Returns a string of N*2 random hexadecimal digits with N<50. If N is omitted, use a value of 10. <a name="redirect"></a>TH1 redirect Command ------------------------------------------- * redirect URL ?withMethod? Issues an HTTP redirect to the specified URL and then exits the process. By default, an HTTP status code of 302 is used. If the optional withMethod argument is present and non-zero, an HTTP status code of 307 is used, which should force the user agent to preserve the original method for the request (e.g. GET, POST) instead of (possibly) forcing the user agent to change the method to GET. <a name="regexp"></a>TH1 regexp Command --------------------------------------- * regexp ?-nocase? ?--? exp string Checks the string against the specified regular expression and returns |
| ︙ | ︙ |