[prev in list] [next in list] [prev in thread] [next in thread] 

List:       apache-modperl
Subject:    Rewrite HTTP Headers
From:       "J Amuse" <jamuse () gmail ! com>
Date:       2008-04-23 9:52:05
Message-ID: 8c1870620804230252i2849dacaq1c65e9de9e59715b () mail ! gmail ! com
[Download RAW message or body]

I wrote a simple module that parses the HTTP response body and updates
certain text. I want the script to be able to parse and manipulate the HTTP
response headers as well. For example add secure and HttpOnly flags to
certain cookies, or add a redirection when a 500 error code is returned. The
code I have so far is:

======================================================================================
package TE::ST;
# $Header:$
use strict;
use warnings;

use Apache2::Filter ();
use Apache2::RequestRec ();
use APR::Table ();

use Apache2::Const -compile => qw(OK);

use constant BUFF_LEN => 9999;
no warnings qw(redefine);

sub handler {
    my $f = shift;

    while ($f->read(my $buffer, BUFF_LEN)) {
        # Disable autocomplete
        $buffer =~ s/login method="post"/login method="post"
autocomplete="off" /g;

        $f->print($buffer);
    }

    return Apache2::Const::OK;
}
1;
======================================================================================

when using f->read it appears as though the HTTP headers are not including.
I know err_headers_out should have access to the headers, but is there a way
to force f->read to access the HTTP headers as well? I've seen the set and
add methods for err_headers_out, but can someone point me to a code example
of either editing the HTTP headers or rewriting the server response when
certain response codes are received?

Thanks.

[Attachment #3 (text/html)]

I wrote a simple module that parses the HTTP response body and updates
certain text. I want the script to be able to parse and manipulate the
HTTP response headers as well. For example add secure and HttpOnly
flags to certain cookies, or add a redirection when a 500 error code is
returned. The code I have so far is:<br>
<br>======================================================================================<br><div \
id="1fgv" class="ArwC7c ckChnd">package TE::ST;<br># $Header:$<br>use strict;<br>use \
warnings;<br><br>use Apache2::Filter ();<br> use Apache2::RequestRec ();<br>
use APR::Table ();<br><br>use Apache2::Const -compile =&gt; qw(OK);<br><br>use \
constant BUFF_LEN =&gt; 9999;<br>no warnings qw(redefine);<br><br>sub handler \
{<br>&nbsp;&nbsp;&nbsp; my $f = shift;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; \
while ($f-&gt;read(my $buffer, BUFF_LEN)) {<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Disable \
autocomplete<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $buffer =~ s/login \
method=&quot;post&quot;/login method=&quot;post&quot; autocomplete=&quot;off&quot; \
/g;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
$f-&gt;print($buffer);<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; return \
Apache2::Const::OK;<br>

}<br>1;<br>======================================================================================<br><br>when
 using f-&gt;read it appears as though the HTTP headers are not
including. I know err_headers_out should have access to the headers,
but is there a way to force f-&gt;read to access the HTTP headers as
well? I&#39;ve seen the set and add methods for err_headers_out, but can
someone point me to a code example of either editing the HTTP headers
or rewriting the server response when certain response codes are
received? <br>
<br>Thanks.</div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic