File: redirect.tcl

package info (click to toggle)
libapache2-mod-rivet 2.3.3-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 5,156 kB
  • ctags: 1,093
  • sloc: xml: 7,696; tcl: 6,939; ansic: 5,682; sh: 4,862; makefile: 199; sql: 91; lisp: 78
file content (33 lines) | stat: -rw-r--r-- 897 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#
# -- ::rivet::redirect
#
#  Redirecting to a new URL by issuing a 301 or 302 (permanent)
# diversion to a new resource. 
#
# Arguments:
#
#   - url               - URL to which we are redirecting the client
#   - permanent:[0 | 1] - whether redirection will be permanent (default)
#
#

namespace eval ::rivet {

    proc redirect {url {permanent 0}} {

        if {[::rivet::headers sent]} {

            return  -code error \
                    -errorcode headers_already_sent \
                    -errorinfo "Impossible to redirect: headers already sent"
        }

        ::rivet::no_body ; ## don’t output anything on a redirect
        ::rivet::headers set Location $url
        ::rivet::headers numeric [expr {$permanent ? "301" : "302"}]
        ::rivet::abort_page [dict create error_code redirect location $url] ; ## stop any further processing

        return -error ok 
    }

}