I'll point you to an example, and include the basics here, but the idea is you need one procedure which will do the mapping, which replaces or enhances [ns_conn location]. The map is just from your internal virtual host to the external method:/host. Unfortunately my example AOLserver was both front end proxy and back end virtual server so the mapping was pretty easy, but here goes:
The code below is from the bottom of the page: http://www.rmadilo.com/files/vat/vat.txt I used [rename] so that no code had to be modified anywhere else. This is old code, so please forgive the style. You can use a global var, but you might choose a namespaced variable instead. The global var "Template" is setup using a filter. The filter runs for each connection...ahead of any other filter, so it needs to be registered in your $private_tcl_library/init.tcl file, or at least before anything else that needs to use the variable. Basically, your mapping procedure will run for each connection, or for each scheduled proc that needs the external address: (also can't figure out why I renamed the old versions "new"): # following is used for getting the correct redirect rename ns_conn ns_conn_new proc ns_conn { args } { if {[string match [lindex $args 0] "location"]} { global Template if {[info exists Template(host)]} { return http://${Template(host)} } else { return [ns_conn_new location] } } else { return [eval "ns_conn_new $args"] } } rename ns_returnredirect ns_returnredirect_new proc ns_returnredirect { arg } { ns_log Debug "arg is $arg" ns_log Debug "ns_conn url is [ns_conn url]" if {[string match -nocase "http*" $arg]} { ns_returnredirect_new $arg } elseif {[string match -nocase "/*" $arg]} { global Template ns_log Debug "Redirecting to ${Template(protocol)}://${Template(host)}$arg" ns_returnredirect_new ${Template(protocol)}://${Template(host)}$arg } else { global Template set full_url [ns_normalizepath [file dirname [ns_conn url]]/${arg}] ns_log Debug "full_url is $full_url" ns_log Debug "Redirecting to ${Template(protocol)}://${Template(host)}$arg" ns_returnredirect_new ${Template(protocol)}://${Template(host)}$full_url } return } InitTemplates segway # Following procs are for use with OpenACS (VirtualACS) # You can comment these out if you do not have multiple # ACS installations running from the same AOLserver. rename ns_info ns_info_old proc server_name_for_connection { } { global Template if {[info exists Template(server)]} { return $Template(server) } else { # Not in connection Thread return [nsv_get TemplateParameters defaultserver] } } proc ns_info { option } { switch $option { server { return [server_name_for_connection] } default { return [ns_info_old $option] } } } More info at in the vat directory: http://www.rmadilo.com/files/vat/ tom jackson On Mon, 2009-05-04 at 01:28 +0400, Alexey Pechnikov wrote: > Hello! > > On Sunday 03 May 2009 21:36:52 Tom Jackson wrote: > > If your solution below is working, it seems pretty simple to me, a tiny > > wrapper around ns_returnredirect. > > Well, can I replace internal ns_returnredirect function to my wrapper with > same name for all interps? AOL 4.5.1 has a lot of features but there are a > few > examples. May I use init script for all interps for this? Is it correct way? -- AOLserver - http://www.aolserver.com/ To Remove yourself from this list, simply send an email to <[email protected]> with the body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of your email blank.
