diff options
Diffstat (limited to 'lib/Apache/Inject')
-rw-r--r-- | lib/Apache/Inject/Filter.pm | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/lib/Apache/Inject/Filter.pm b/lib/Apache/Inject/Filter.pm index f87cdc1..67511e2 100644 --- a/lib/Apache/Inject/Filter.pm +++ b/lib/Apache/Inject/Filter.pm @@ -49,15 +49,29 @@ sub handler : FilterRequestHandler { return DECLINED; } - my ($buf, $content); - $content .= $buf while $f->read($buf); - return DECLINED if not $content =~ /$doc/; - - $f->print($+{head}) if $+{head}; - inject($f, "InjectHead"); - $f->print($+{body}) if $+{body}; - inject($f, "InjectFoot"); - $f->print($+{rest}) if $+{rest}; + # First pass + if (not $f->ctx) { + my ($buf, $content); + $content .= $buf while $f->read($buf); + if (not $content =~ /$doc/) { + $f->r->warn('Inject: Cannot find <body> (<head> too long?)'); + return DECLINED; + } + + $f->print($+{head}) if $+{head}; + inject($f, "InjectHead"); + $f->print($+{body}) if $+{body}; + inject($f, "InjectFoot"); + $f->print($+{rest}) if $+{rest}; + + $f->ctx(1); + } + + # Any subsequent pass + else { + my $buf; + $f->print($buf) while $f->read($buf); + } return OK; } |