You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by gerard such <ge...@gmail.com> on 2005/11/13 20:02:04 UTC

HTTP headers question

Hi, i'm trying to avoid the "304 Not Modified" status when testing my
updated handlers in localhost. From documentation, i read that phase
PerlHeaderParserHandler is the most adequate to launch handlers when
in Directories scopes to manage HTTP response headers.

My apache directive
--------------------------------------------------------
FileETag None
PerlOptions +ParseHeaders

<Directory /home/blogs/camandules.info>
PerlHeaderParserHandler Blogum::BlogumHeaders::nocache
<Files *.js>
PerlHeaderParserHandler Blogum::BlogumHeaders::cache
</Files>
<Files *.gif>
PerlHeaderParserHandler Blogum::BlogumHeaders::cache
</Files>
<Files *.jpg>
PerlHeaderParserHandler Blogum::BlogumHeaders::cache
</Files>
...
</Directory>
--------------------------------------------------------



And my handler
--------------------------------------------------------
package Blogum::BlogumHeaders;

use Apache2::RequestRec();
use Apache2::RequestIO();
use Apache2::RequestUtil();
use Apache2::ServerUtil();
use Apache2::ServerRec();
use Apache2::Process();
use Apache2::Response();
use APR::Table();
# perhaps too modules?
use Apache2::Const -compile => qw(DECLINED);
use strict;
no strict 'refs';
no strict 'subs';

sub nocache {
        my ($r) = @_;
warn 'STATUS '.$apache->status();
        $r->err_headers_out->add('Pragma' => "no-cache");
        $r->err_headers_out->add('Cache-control' => "max-age=0");
        $r->err_headers_out->add('Cache-control' => "no-cache");
        $r->err_headers_out->add('Cache-control' => "must-revalidate");
        $r->err_headers_out->add('Expires' => "-1");
        return Apache2::Const::DECLINED;
        }
sub cache {
        my ($r) = @_;
        $r->err_headers_out->add('Pragma' => "public");
        $r->err_headers_out->add('Cache-control' => "public");
        return Apache2::Const::DECLINED;
        }
1;
--------------------------------------------------------


Following HTTP headers negotiation with firefox extension "live http
headers", and the warning of my module, i only get warnings in GET
requests with a status of "200" (in logs there is the 200 number as
expected).
The problem is that when i get the "304" status i get no warning, that
therefore means that the handler is not being executed.

In consequence, how can i avoid this status of 304 with modperl? I
don't know why the server is responding with this status (it
shouldn't), but despite this it seems that it cannot be solves with
modperl.




An example of one HTTP headers negotiation:
--------------------------------------------------------
http://localhost/camandules.info/
GET /camandules.info/ HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12)
Gecko/20051010 Firefox/1.0.7 (Ubuntu package 1.0.7)
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: blogum=blogum#1959913555115135510915259521; blogum_counter_sesion=1
If-Modified-Since: Tue, 05 Jul 2005 06:25:08 GMT
If-None-Match: "1bcbb8-ca-25467900"


HTTP/1.x 304 Not Modified
Date: Sun, 13 Nov 2005 19:00:52 GMT
Server: mod-xslt/1.3.8 Apache/2.0.55 (Unix)
mod_apreq2-20050712/2.1.3-dev mod_perl/2.0.1 Perl/v5.8.7
Connection: Keep-Alive
Keep-Alive: timeout=15, max=100
Etag: "1bcbb8-ca-25467900"
Expires: -1
Cache-Control: max-age=0, no-cache, must-revalidate
--------------------------------------------------------

Note: ETAG is still generated although apache directive "FileETag
None" is included



Now forcing the total reload with shift+reload button
--------------------------------------------------------
http://localhost/camandules.info/
GET /camandules.info/ HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12)
Gecko/20051010 Firefox/1.0.7 (Ubuntu package 1.0.7)
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: blogum=blogum#1959913555115135510915259521;
blogum_counter_pages=main#; blogum_counter_sesion=1
Pragma: no-cache
Cache-Control: no-cache


HTTP/1.x 200 OK
Date: Sun, 13 Nov 2005 19:03:36 GMT
Server: mod-xslt/1.3.8 Apache/2.0.55 (Unix)
mod_apreq2-20050712/2.1.3-dev mod_perl/2.0.1 Perl/v5.8.7
Pragma: no-cache
Cache-Control: max-age=0, no-cache, must-revalidate
Expires: -1
Last-Modified: Tue, 05 Jul 2005 06:25:08 GMT
Etag: "1bcbb8-ca-25467900"
Accept-Ranges: bytes
Content-Type: text/html; charset=ISO-8859-1
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 7355
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
--------------------------------------------------------

Note: Etag values should be different as content has changed, but it is not:
Etag: "1bcbb8-ca-25467900"
Etag: "1bcbb8-ca-25467900"




I don't know if it is a problem with modperl or with apache, but i
need to solve it before the update to the working server. Do you have
any suggestion of what i can test?
Is it something about mp2 or should i resend this to apache mailing list?
Thanks.


Server:
mod-xslt/1.3.8
Apache/2.0.55 (Unix)
mod_apreq2-20050712/2.1.3-dev
mod_perl/2.0.1
Perl/v5.8.7

Re: HTTP headers question

Posted by gerard such <ge...@gmail.com>.
Apparently it works :D
However, it's very strange the headers that "my" server sends! Now
there is a Last-Modified header that points to July?!?!?
Also the ETAG tag is still there ...

Anyway, it seems that effectively the two noisy tags are removed, and
that the OK status is sent (if not i will disturb again the list :).

In addition, just browsing for the web pages (of my modules), I've
discovered an extra header! one "301 Moved Permanently" ... After it,
it's like an extra request is performed and then an OK is responded.
Perhaps the computer is trying to communicate with me?

I attach the two negotiations, the last with the 301 status, followed
by the spontaneous extra request.

-----------------------------------------
http://localhost/camandules.info/

GET /camandules.info/ HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12)
Gecko/20051010 Firefox/1.0.7 (Ubuntu package 1.0.7)
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: blogum=blogum#1959913555115135510915259521;
blogum_counter_pages=main#; blogum_counter_sesion=1
If-Modified-Since: Tue, 05 Jul 2005 06:25:08 GMT
If-None-Match: "1bcbb8-ca-25467900"



HTTP/1.x 200 OK
Date: Sun, 13 Nov 2005 20:38:35 GMT
Server: mod-xslt/1.3.8 Apache/2.0.55 (Unix)
mod_apreq2-20050712/2.1.3-dev mod_perl/2.0.1 Perl/v5.8.7
Pragma: no-cache
Cache-Control: max-age=0, no-cache, must-revalidate
Expires: -1
Last-Modified: Tue, 05 Jul 2005 06:25:08 GMT
Etag: "1bcbb8-ca-25467900"
Accept-Ranges: bytes
Content-Type: text/html; charset=ISO-8859-1
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 7366
Keep-Alive: timeout=15, max=97
Connection: Keep-Alive
-----------------------------------------



-----------------------------------------
http://localhost/camandules.info


GET /camandules.info HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12)
Gecko/20051010 Firefox/1.0.7 (Ubuntu package 1.0.7)
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: blogum=blogum#1959913555115135510915259521;
blogum_counter_pages=article_new#main#; blogum_counter_sesion=1


HTTP/1.x 301 Moved Permanently
Date: Sun, 13 Nov 2005 20:44:09 GMT
Server: mod-xslt/1.3.8 Apache/2.0.55 (Unix)
mod_apreq2-20050712/2.1.3-dev mod_perl/2.0.1 Perl/v5.8.7
Pragma: no-cache
Cache-Control: max-age=0, no-cache, must-revalidate
Expires: -1
Location: http://localhost/camandules.info/
Content-Length: 386
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
----------------------------------------------------------

http://localhost/camandules.info/


GET /camandules.info/ HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12)
Gecko/20051010 Firefox/1.0.7 (Ubuntu package 1.0.7)
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: blogum=blogum#1959913555115135510915259521;
blogum_counter_pages=article_new#main#; blogum_counter_sesion=1
If-Modified-Since: Tue, 05 Jul 2005 06:25:08 GMT
If-None-Match: "1bcbb8-ca-25467900"


HTTP/1.x 200 OK
Date: Sun, 13 Nov 2005 20:44:10 GMT
Server: mod-xslt/1.3.8 Apache/2.0.55 (Unix)
mod_apreq2-20050712/2.1.3-dev mod_perl/2.0.1 Perl/v5.8.7
Pragma: no-cache
Cache-Control: max-age=0, no-cache, must-revalidate
Expires: -1
Last-Modified: Tue, 05 Jul 2005 06:25:08 GMT
Etag: "1bcbb8-ca-25467900"
Accept-Ranges: bytes
Content-Type: text/html; charset=ISO-8859-1
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 7366
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
-----------------------------------------


2005/11/13, Geoffrey Young <ge...@modperlcookbook.org>:
>
> > PerlHeaderParserHandler Blogum::BlogumHeaders::nocache
>
> >         $r->err_headers_out->add('Pragma' => "no-cache");
> >         $r->err_headers_out->add('Cache-control' => "max-age=0");
> >         $r->err_headers_out->add('Cache-control' => "no-cache");
> >         $r->err_headers_out->add('Cache-control' => "must-revalidate");
> >         $r->err_headers_out->add('Expires' => "-1");
> >         return Apache2::Const::DECLINED;
>
> in this case, it might be easier to remove the cache headers from the
> request on the way in.  so, try something like
>
>   $r->headers_in->unset('If-Modified-Since');
>   $r->headers_in->unset('If-None-Match');
>
> so that the server isn't aware of any caching on the client (as opposed to
> asking the client to behave in such and such a way).
>
> HTH
>
> --Geoff
>


--
(signatura)
Eps, el meu bloc personal
http://www.camandules.info

Re: HTTP headers question

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> PerlHeaderParserHandler Blogum::BlogumHeaders::nocache

>         $r->err_headers_out->add('Pragma' => "no-cache");
>         $r->err_headers_out->add('Cache-control' => "max-age=0");
>         $r->err_headers_out->add('Cache-control' => "no-cache");
>         $r->err_headers_out->add('Cache-control' => "must-revalidate");
>         $r->err_headers_out->add('Expires' => "-1");
>         return Apache2::Const::DECLINED;

in this case, it might be easier to remove the cache headers from the
request on the way in.  so, try something like

  $r->headers_in->unset('If-Modified-Since');
  $r->headers_in->unset('If-None-Match');

so that the server isn't aware of any caching on the client (as opposed to
asking the client to behave in such and such a way).

HTH

--Geoff