Jonas Nordström <[EMAIL PROTECTED]> writes:

> How can I copy cookies from an incoming request to a LWP-request and also
> add a custom cookie? Can I use HTTP::Cookies?
> 
> I use:
> $request->header('Cookie' => $r->header_in("Cookie")); 
> and it works fine, but now I want to add a cookie that the client didn't
> send.
> Can I use $cookie_jar->set_cookie() and then
> $cookie_jar->add_cookie_header($request);? But what happens with the
> original cookies?

It goes away if any cookies from the $cookie_jar applies.
$cookie_jar->add_cookie_header() currently overrides the cookie header
by calling:

  $request->header(Cookie => join("; ", @cval)) if @cval;

If we change this to:

  $request->push_header(...)

then you get two header lines.  Don't know if most server apps can
deal with it.  Still anoter alternative would be to do something like:

  if (my $old_cookie = $request->header('Cookie')) {
       unshift(@cval, $old_cookie);
  }
  $request->header(Cookie => join("; ", @cval)) if @cval;

That should append to the current value if it was set.
Do you want this?

Regards,
Gisle

Reply via email to