Redirects and Cache-Control

Redirects and Cache-Control

am 09.04.2009 19:58:33 von kropotkin

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 );=20
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?=20

Many thanks

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



charset=3Diso-8859-1">




Hi

 

I am trying to use:

 

$headers =3D =
$r->headers_out;

$r->no_cache(1);

$headers->set( Location =
=3D> url  );=20

return REDIRECT.

 

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

 

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

 

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

 

Second question:

 

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

 

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

 

Many thanks

 

Justin =
Wyllie


------=_NextPart_000_0049_01C9B945.2E5F0170--

Re: Redirects and Cache-Control

am 09.04.2009 21:16:06 von Adam Prime

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

Re: Redirects and Cache-Control

am 09.04.2009 22:15:38 von dstroma

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;