Name

redirect — Interrupt processing and divert to a new URL

Synopsis

::rivet::redirect ?URL? ?permanent (default: 0)?

Description

::rivet::redirect diverts the browser to a new URL and marks the redirection as either permanent in the browser local cache or non permanent (default). Calling ::rivet::redirect causes the script execution to interrupt and control passes to AbortScript, if such script is set, by calling ::rivet::abort_page and passing as abort code a dictionary with 2 keys:

  • error_code: string literal 'redirect'
  • location: the URL the browser will be redirected to

::rivet::redirect drives the redirection by setting the 301 (permanent redirect) or 302 (non permanent redirect) HTTP status codes and attempts to discard the output the script might have already placed in the stdout channel buffer. Therefore the command can fail if

  • A flush stdout was called before ::rivet::redirect thus causing the HTTP headers to be sent and preventing any possibility to manipulate them
  • The channel buffer was filled causing Tcl to flush the channel

The stdout channel, like any Tcl channels, can be manipulated and if needed its internal buffer streched.