Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

Redirects and Cache-Control

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


enquiries at mms-oxford

Apr 9, 2009, 10:58 AM

Post #1 of 3 (806 views)
Permalink
Redirects and Cache-Control

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.

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


adam.prime at utoronto

Apr 9, 2009, 12:16 PM

Post #2 of 3 (732 views)
Permalink
Re: Redirects and Cache-Control [In reply to]

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


dstroma at verizon

Apr 9, 2009, 1:15 PM

Post #3 of 3 (726 views)
Permalink
Re: Redirects and Cache-Control [In reply to]

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;

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.