You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Marco Spinetti <m....@pisa.iol.it> on 2009/03/26 09:37:02 UTC

Set-Cookie

I have a doubt about ho to set multiple cookies.
I'm using apache 2.2 and in my module handler I'm trying to set two 
different cookies with:

apr_table_set(r->headers_out, "Set-Cookie", co);

apr_table_set(r->headers_out, "Set-Cookie", co1);

It seems that the second instruction override the first one.
So my question: how can I set two cookies in my module?

Best regards

Marco

Re: Set-Cookie

Posted by Joe Lewis <jo...@joe-lewis.com>.
Marco Spinetti wrote:
> Thanks very much.
> So I have to use:
>
> apr_table_add(r->headers_out, "Set-Cookie", co);
> apr_table_add(r->headers_out, "Set-Cookie", co1);

Rather than playing with a proxy or fireway gateway that could remove 
one of your set cookie headers (because you have multiple), you may want 
to combine the cookies into one.  See the Message Headers section for 
more information :

http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2

Joe
>
> Best regards.
>
> Marco
>
> Rainer Jung ha scritto:
>> On 26.03.2009 10:07, Marco Spinetti wrote:
>>> Ok, I have to use apr_table_add instead od apr_table_set.
>>> So I should write:
>>>
>>> apr_table_add(r->headers_out, "Set-Cookie", co);
>>> apr_table_add(r->headers_out, "Set-Cookie", co1);
>>>
>>> If I write:
>>>
>>> apr_table_set(r->headers_out, "Set-Cookie", co);
>>> apr_table_merge(r->headers_out, "Set-Cookie", co1);
>>>
>>> is it right?
>>>
>>> What are the differences between the two approches? browser 
>>> compatibility?
>>> Best regards
>>>
>>> Marco
>>
>> Whether to merge or add
>>
>> http://apr.apache.org/docs/apr/1.3/group__apr__tables.html
>>
>> depends on whether you need the various (header) values to get 
>> concatenated with ", " in between and the header send only once, or 
>> you want the headers multiple times, each time with a different value.
>>
>> What's right depends on the spec that defines the header. Set-Cookie 
>> requires the header once for each cookie to set.
>>
>> Regards,
>>
>> Rainer
>>
>>
>>
>


-- 
Joe Lewis
Chief Nerd 	SILVERHAWK <http://www.silverhawk.net/> 	(801) 660-1900

------------------------------------------------------------------------
/If gun laws in fact worked% the sponsors of this type of legislation 
should have no difficulty drawing upon long lists of examples of crime 
rates reduced by such legislation. That they cannot do so after a 
century and a half of trying--that they must sweep under the rug the 
southern attempts at gun control in the 1870-1910 period% the 
northeastern attempts in the 1920-1939 period% the attempts at both 
Federal and State levels in 1965-1976--establishes the repeated% 
complete and inevitable failure of gun laws to control serious crime.
    --Senator Orrin Hatch% Chairman% Senate Judiciary Committee 
Subcommittee on the Constitution% 97th Cong.% 2d Sess.% The Right to 
Keep and Bear Arms% Committee Print I-IX% 1-23 (1982)./

Re: Set-Cookie

Posted by Marco Spinetti <m....@pisa.iol.it>.
Thanks very much.
So I have to use:

apr_table_add(r->headers_out, "Set-Cookie", co);
apr_table_add(r->headers_out, "Set-Cookie", co1);

Best regards.

Marco

Rainer Jung ha scritto:
> On 26.03.2009 10:07, Marco Spinetti wrote:
>> Ok, I have to use apr_table_add instead od apr_table_set.
>> So I should write:
>>
>> apr_table_add(r->headers_out, "Set-Cookie", co);
>> apr_table_add(r->headers_out, "Set-Cookie", co1);
>>
>> If I write:
>>
>> apr_table_set(r->headers_out, "Set-Cookie", co);
>> apr_table_merge(r->headers_out, "Set-Cookie", co1);
>>
>> is it right?
>>
>> What are the differences between the two approches? browser 
>> compatibility?
>> Best regards
>>
>> Marco
>
> Whether to merge or add
>
> http://apr.apache.org/docs/apr/1.3/group__apr__tables.html
>
> depends on whether you need the various (header) values to get 
> concatenated with ", " in between and the header send only once, or 
> you want the headers multiple times, each time with a different value.
>
> What's right depends on the spec that defines the header. Set-Cookie 
> requires the header once for each cookie to set.
>
> Regards,
>
> Rainer
>
>
>


Re: Set-Cookie

Posted by Rainer Jung <ra...@kippdata.de>.
On 26.03.2009 10:07, Marco Spinetti wrote:
> Ok, I have to use apr_table_add instead od apr_table_set.
> So I should write:
>
> apr_table_add(r->headers_out, "Set-Cookie", co);
> apr_table_add(r->headers_out, "Set-Cookie", co1);
>
> If I write:
>
> apr_table_set(r->headers_out, "Set-Cookie", co);
> apr_table_merge(r->headers_out, "Set-Cookie", co1);
>
> is it right?
>
> What are the differences between the two approches? browser compatibility?
> Best regards
>
> Marco

Whether to merge or add

http://apr.apache.org/docs/apr/1.3/group__apr__tables.html

depends on whether you need the various (header) values to get 
concatenated with ", " in between and the header send only once, or you 
want the headers multiple times, each time with a different value.

What's right depends on the spec that defines the header. Set-Cookie 
requires the header once for each cookie to set.

Regards,

Rainer



Re: Set-Cookie

Posted by Marco Spinetti <m....@pisa.iol.it>.
Ok, I have to use apr_table_add instead od apr_table_set.
So I should write:

apr_table_add(r->headers_out, "Set-Cookie", co);
apr_table_add(r->headers_out, "Set-Cookie", co1);

If I write:

apr_table_set(r->headers_out, "Set-Cookie", co);
apr_table_merge(r->headers_out, "Set-Cookie", co1);

is it right?

What are the differences between the two approches? browser compatibility?
Best regards

Marco

Sorin Manolache ha scritto:
> On Thu, Mar 26, 2009 at 09:37, Marco Spinetti <m....@pisa.iol.it> wrote:
>   
>> I have a doubt about ho to set multiple cookies.
>> I'm using apache 2.2 and in my module handler I'm trying to set two
>> different cookies with:
>>
>> apr_table_set(r->headers_out, "Set-Cookie", co);
>>
>> apr_table_set(r->headers_out, "Set-Cookie", co1);
>>
>> It seems that the second instruction override the first one.
>> So my question: how can I set two cookies in my module?
>>     
>
> apr_table_addn(r->headers_out, "Set-Cookie", cookie);
>
>
>   


Re: Set-Cookie

Posted by Sorin Manolache <so...@gmail.com>.
On Thu, Mar 26, 2009 at 09:37, Marco Spinetti <m....@pisa.iol.it> wrote:
> I have a doubt about ho to set multiple cookies.
> I'm using apache 2.2 and in my module handler I'm trying to set two
> different cookies with:
>
> apr_table_set(r->headers_out, "Set-Cookie", co);
>
> apr_table_set(r->headers_out, "Set-Cookie", co1);
>
> It seems that the second instruction override the first one.
> So my question: how can I set two cookies in my module?

apr_table_addn(r->headers_out, "Set-Cookie", cookie);


-- 
A: Because it reverses the logical flow of conversation.
Q: Why is top-posting frowned upon?
A: Top-posting.
Q: What is the most annoying thing in e-mail?