[Help] How to change the content of response on the fly���

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey Experts,
 
   User can write content handlers for the Apache response phase. My purpose is to write an Apache module to intervene all response right before the response write back to client. Here is an example how we can do this using mod_perl:
sub handler {
 my $r = shift;
 my $footer = "something";
 return DECLINED unless $r->content_type() eq 'text/html';
 my $file = $r->filename;
 unless (-e $r->finfo) {
  $r->log_error("File does not exist: $file");
  return NOT_FOUND;
 }
 unless (-r _) {
  $r->log_error("File permissions deny access: $file");
  return FORBIDDEN;
 }
 unless ($fh = Apache::File->new($file)) {
  $r->log_error("Couldn't open $file for reading: $!");
  return SERVER_ERROR;
 }
 $r->send_http_header;

 while (<$fh>) {
  s!(</BODY>)!$footer$1!oi;
 } continue {
  $r->print($_);
 }
 return OK;
}
 
As you can see, I have to open the actual file before do anything. This approach doesn't work if the requested URI doesn't correspond to real file in the OS or the request file should be parsed before sending out, such as PHP source file. Is there a way to build such an Apache module which can intervene all response right before it being sent to client in any cases?
   Any ideas are highly appreciated.
 
Thanks,
Yushui


Windows Live Writer 让您告别龟速网络,轻松写日志! 立即使用!

[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux