You are here iC Home > Perl > mod_perl > Customizing the Fixup Phase (Apache::HttpEquiv)

Perl

8.2 Customizing the Fixup Phase (Apache::HttpEquiv)

20.11.2008
8.1 Apache Handler [  up  ] - [ a - z ] - [ search PC ] - [ top ] 9 Advanced Features in Perl

Apache::HttpEquiv, a module written by Rob Hartill.
Patched to run under mod_perl 2.0 (1.99) by me

package Apache::HttpEquiv;
use strict;

use Apache::Const
 -compile
 => qw(:common REDIRECT HTTP_NO_CONTENT DIR_MAGIC_TYPE HTTP_NOT_MODIFIED);

use Apache::RequestRec;
use APR::Table;

sub handler {
   my $r = shift;
   local(*FILE);

	open(FILE, $r->filename);

   while(<FILE>) {
	last if m!<BODY>|</HEAD>!i; # exit early if in BODY
	if (m/META HTTP-EQUIV="([^"]+)"\s+CONTENT="([^"]+)"/i) {
	   $r->headers_out->{$1} = $2;
	}
   }
   close(FILE);
   return Apache::OK;
}

1;

Test / Output

# telnet localhost 81
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /httpequiv/index.html HTTP/1.0
Host: www.example.com

HTTP/1.1 200 OK
Date: Mon, 05 Apr 2004 20:21:55 GMT
Server: Apache/2.0.48 (Unix) mod_perl/1.99_13 Perl/v5.6.1 mod_ssl/2.0.48 OpenSSL/0.9.7d
Expires: Wed, 31 Jul 1998 16:40:00 GMT
Set-Cookie: open=sesame
Last-Modified: Mon, 05 Apr 2004 20:19:18 GMT
ETag: "9eeaa-d2-a4d9dd80"
Accept-Ranges: bytes
Content-Length: 210
Connection: close
Content-Type: text/html; charset=ISO-8859-1

<HTML>
<HEAD>
<TITLE>My Page</TITLE>
<b>
<META HTTP-EQUIV="Expires" CONTENT="Wed, 31 Jul 1998 16:40:00 GMT">
<META HTTP-EQUIV="Set-Cookie" CONTENT="open=sesame">
</b><pre>
</HEAD>
<body>
</body>
</HTML>
Connection closed by foreign host.


Tip


Comments

Gesendet: Donnerstag, 21. April 2005 18:52

  Name :  Chris
E-Mail :  chris@********
  Tel. :    9 - 17 Uhr (CET+0)

Mitteilung:

Hi

Just to let you know I tweaked your Apache::HttpEquiv to support setting Content-Type:

https://wiki.slugbug.org.uk/Setting_Content-Type_with_mod_perl

Chris



Advanced search tips
8.1 Apache Handler [  up  ] - [ top ] 9 Advanced Features in Perl



[ home ] - [ search ] - [ feedback ]

copyright by reto - created with mytexi