Forum OpenACS Q&A: Interaction between automatic headers and ns_write

Say you want to punch out a header with a Set-Cookie, so you "ns_set put" into the "ns_conn outputheaders" in preparation for the eventual header return. Later though you follow that change to the outputheaders with a bunch of ns_writes. Starting with one looking like this:
ns_write "HTTP/1.0 200 OK
MIME-Version: 1.0
Content-Type: $content_type
pragma: no-cache

"

My question is whether AOLserver is smart enough to pause the ns_write at the right moment (say before MIME-Version: 1.0) and insert whatever was in outputheaders (like the Set-Cookie)? Is that the default behavior? This is what I was thinking it might do.

ns_write "HTTP/1.0 200 OK
[More headers from ns_conn outputheaders]
MIME-Version: 1.0
Content-Type: $content_type
pragma: no-cache

"

I did some basic RTFM, but couldn't find anything yet. I grep tcldev/*.htm for coverage on outputheaders but nothing. I swear I read about the behavior though, maybe phil's book.

I'm asking to confirm whether this behavior is true. Thanks for any clarification and pointers to RTFM!

I did a little experimentation (telnetting to see the headers), ReturnHeadersNoCache (which manually uses ns_write to produce the headers) did not use util_WriteWithExtraOutputHeaders (which ReturnHeaders do use) so if you set ns_conn outputheaders beforehand, use of ReturnHeadersNoCache will ignore any additions to ns_conn. There are functions that will automatically take into account additional headers from ns_conn outputheaders, procedures like ns_return for example. I remember the differences now :)

Bug? ReturnHeadersWithCookieNoCache is what www/curriculum/index.tcl may have to use if it intends to send out a header with cookies but with caching disabled. Would someone confirm this? Thanks.