Redirects and Cache-Control

This is a multi-part message in MIME format.

------=_NextPart_000_0049_01C9B945.2E5F0170
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi

I am trying to use:

$headers =3D $r->headers_out;
$r->no_cache(1);
$headers->set( Location =3D> url );
return REDIRECT.

The first problem is this does not set the Cache-Control header.

If instead of the redirect I output some content (200 ) then it does, =
correctly.

Is there some reason why this may be? I couldn't see anything in our =
Apache configuration files where this is set up.

Second question:

Does it make sense to try to set Cache-Control with a redirect anyway?

If url1 is requested and the redirect is to url2. What is the =
browser/proxy being told not to cache - url1 or url2? Since it is url2 =
in the response headers surely url2?

Many thanks

Justin Wyllie
------=_NextPart_000_0049_01C9B945.2E5F0170
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6000.16809" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I am trying to use:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>$headers =3D =
$r->headers_out;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>$r->no_cache(1);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>$headers->set( Location =
=3D> url  );
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>return REDIRECT.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>The first problem is this does not set =
the
Cache-Control header.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>If instead of the redirect I output =
some content
(200 ) then it does, correctly.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Is there some reason why this may be? I =
couldn't
see anything in our Apache configuration  files where this is set
up.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Second question:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Does it make sense to try to set =
Cache-Control with
a redirect anyway?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>If url1 is requested and the redirect =
is to url2.
What is the browser/proxy being told not to cache - url1 or url2? Since =
it is
url2 in the response headers surely url2? </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Many thanks</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Justin =
Wyllie</FONT></DIV></BODY></HTML>

------=_NextPart_000_0049_01C9B945.2E5F0170--
kropotkin [ Do, 09 April 2009 19:58 ] [ ID #1997028 ]

Re: Redirects and Cache-Control

Justin Wyllie wrote:
> Hi
>
> I am trying to use:
>
> $headers = $r->headers_out;
> $r->no_cache(1);
> $headers->set( Location => url );
> return REDIRECT.
>
> The first problem is this does not set the Cache-Control header.
>
> If instead of the redirect I output some content (200 ) then it does,
> correctly.
>
> Is there some reason why this may be? I couldn't see anything in our
> Apache configuration files where this is set up.

No idea. Does it set the Pragma header, but not the Cache-Control one?

>
> Second question:
>
> Does it make sense to try to set Cache-Control with a redirect anyway?

To my mind, no. There's no content to cache, and normally (IIRC) if a
browser is sent a 302, it'll request it again if you request it again.
With a 301, some browsers will cache the fact that that URL 301'd
before, and just take you right to the page you 301'd to.


> If url1 is requested and the redirect is to url2. What is the
> browser/proxy being told not to cache - url1 or url2? Since it is url2
> in the response headers surely url2?

I have no idea what the spec would be, but if you 302 with a
Cache-Control header to a page that doesn't have a Cache-Control header,
I would not expect (or want) the header from the 302 to apply to the
other page.

Adam
Adam Prime [ Do, 09 April 2009 21:16 ] [ ID #1997029 ]

Re: Redirects and Cache-Control

Justin Wyllie wrote:
> I am trying to use:
>
> $headers = $r->headers_out;
> $r->no_cache(1);
> $headers->set( Location => url );
> return REDIRECT.

You didn't specify your Apache/mod_perl version. For 2.x this is what I have
and it works fine:

$r->no_cache(1);
$r->status(Apache2::Const::HTTP_MOVED_TEMPORARILY);
$r->headers_out->add(Location => url);
return Apache2::Const::OK;
dstroma [ Do, 09 April 2009 22:15 ] [ ID #1997030 ]
Webserver » gmane.comp.apache.mod-perl » Redirects and Cache-Control

Vorheriges Thema: how did I get here?
Nächstes Thema: generic question on input filters