Forum OpenACS Q&A: Updating header before calling ns_returnredirect

Hi,
I need to add a header before calling ns_returnredirect but somehow not succeeding to do it. As suggested in one of the aolserver articles, I tried the following but no success:

ns_set put [ns_conn outputheaders] myHeader $myHeaderValue
ns_returnredirect $location

Any suggestions?

Collapse
Posted by Gustaf Neumann on
Hi Sunil,

The following script named "redirect.tcl"

ns_set put [ns_conn outputheaders] myHeader foo
ns_returnredirect /
returns the following to the browser
Connection:keep-alive
Content-Length:307
Content-Type:text/html; charset=utf-8
Date:Fri, 21 Apr 2017 17:07:45 GMT
Location:/
myHeader:foo
Server:NaviServer/4.99.16d4
... so, the extra header is includes, everything works as expected. This is with NaviServer 4.99.16d4.

What exact server are you using?
-g

Collapse
Posted by Sunil Shenoy on
Thanks Gustaf,

I am using AOLserver/3.5.11 ..... thought the code you mentioned should function the same way; but apparently it does not.

Regards,
Sunil

Collapse
Posted by Gustaf Neumann on
AOLserver/3.5.11 was released in 2003, more than 13 years ago! You should upgrade at least to AOLserver/4.5.2, i would expect this to code to work there the same way as in NaviServer.
Collapse
Posted by Sunil Shenoy on
Thank you very much Gustaf.

Regards,
Sunil

Collapse
Posted by Brian Fenton on
Hi Sunil

AOLserver/3.5.11 is not *that* old that it should have a different way of writing headers.

One thing you could try is to search your existing codebase for examples of how headers are set. Presumably it's working, so it is just a matter of finding it. For example, search for where cookies are created. If you are not using OpenACS, the headers might be written with just a raw ns_write.

Let us know if you need more help
Brian