| | @@ -432,26 +432,40 @@ |
| 432 | 432 | sendText((char*)argv[1], argl[1], *(unsigned int*)pConvert); |
| 433 | 433 | return TH_OK; |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /* |
| 437 | | -** TH1 command: redirect URL |
| 437 | +** TH1 command: redirect URL ?withMethod? |
| 438 | 438 | ** |
| 439 | | -** Issues an HTTP redirect (302) to the specified URL and then exits the |
| 440 | | -** process. |
| 439 | +** Issues an HTTP redirect to the specified URL and then exits the process. |
| 440 | +** By default, an HTTP status code of 302 is used. If the optional withMethod |
| 441 | +** argument is present and non-zero, an HTTP status code of 307 is used, which |
| 442 | +** should force the user agent to preserve the original method for the request |
| 443 | +** (e.g. GET, POST) instead of (possibly) forcing the user agent to change the |
| 444 | +** method to GET. |
| 441 | 445 | */ |
| 442 | 446 | static int redirectCmd( |
| 443 | 447 | Th_Interp *interp, |
| 444 | 448 | void *p, |
| 445 | 449 | int argc, |
| 446 | 450 | const char **argv, |
| 447 | 451 | int *argl |
| 448 | 452 | ){ |
| 449 | | - if( argc!=2 ){ |
| 450 | | - return Th_WrongNumArgs(interp, "redirect URL"); |
| 453 | + int withMethod = 0; |
| 454 | + if( argc!=2 && argc!=3 ){ |
| 455 | + return Th_WrongNumArgs(interp, "redirect URL ?withMethod?"); |
| 451 | 456 | } |
| 452 | | - cgi_redirect(argv[1]); |
| 457 | + if( argc==3 ){ |
| 458 | + if( Th_ToInt(interp, argv[2], argl[2], &withMethod) ){ |
| 459 | + return TH_ERROR; |
| 460 | + } |
| 461 | + } |
| 462 | + if( withMethod ){ |
| 463 | + cgi_redirect_with_method(argv[1]); |
| 464 | + }else{ |
| 465 | + cgi_redirect(argv[1]); |
| 466 | + } |
| 453 | 467 | Th_SetResult(interp, argv[1], argl[1]); /* NOT REACHED */ |
| 454 | 468 | return TH_OK; |
| 455 | 469 | } |
| 456 | 470 | |
| 457 | 471 | /* |
| 458 | 472 | |