}
         }
         $cnx = false;
     } else {
         if ($rq_err >= 301) {
             $lf = $null_response;
         }
     }
 }
 if ($http_action == "HEAD") {
     $plen = $lf->content_length;
     $hlf = $lf;
     $lf = $null_response;
     $lf->content_length = $plen;
 }
 core_modules_hook("before_response");
 if (!$rq_err) {
     $rq_err = 500;
 }
 $chunked = nw_use_chunked_encoding();
 if ($chunked === "CLOSE") {
     $cnx = $keepalive = $chunked = false;
 }
 // Send the response headers and content
 $sent_len = 0;
 $first_chunk = true;
 while (($buf = $lf->parser_get_output()) !== "" || $first_chunk) {
     if ($first_chunk) {
         $hbuf = build_response_headers() . "\r\n";
     }
     if ($chunked) {
 function main()
 {
     global $pfilters, $lf, $out_contenttype, $chunky, $keepalive, $http_version;
     $used_filters = array();
     $chunky = !isset($lf->content_length) || $lf->content_length == NW_PLF_MAGIC;
     $hbn = basename($GLOBALS["http_uri"]);
     $hbnext = array_flip(explode(".", $hbn));
     // assign filters
     if (access_query("filterenable", 0)) {
         foreach (access_query("filter") as $filter_rule) {
             // split rule into: [ mime/ext _ filter _ fargs ]
             list($mimematch, $filter_rule) = explode(" ", ltrim($filter_rule), 2);
             @(list($fname, $fargs) = explode(" ", ltrim($filter_rule), 2));
             $fargs = trim($fargs);
             // check for missing mime match
             if (empty($fname) || empty($pfilters[strtolower($fname)])) {
                 if (strpos($mimematch, "/") === false && strpos($mimematch, "|") === false && strpos($mimematch, "*") === false && strpos($mimematch, ".") === false) {
                     $fargs = $fname . " " . $fargs;
                     $fname = $mimematch;
                     $mimematch = "*/*";
                 }
             }
             // is filter available
             $fname = strtolower($fname);
             if (empty($pfilters[$fname])) {
                 techo("filter '{$fname}' not available", NW_EL_ERROR);
                 continue;
             }
             // match mime / extension
             @(list($mime, $uu) = explode(";", $out_contenttype, 2));
             $mime = trim($mime);
             $no_match = true;
             foreach (explode("|", $mimematch) as $match) {
                 $ext = ltrim($match, ".");
                 if ($match == $mime || $match == "*/*" || $match == "*" || strpos($match, '*') !== false && strpos($mime, rtrim($match, "*")) !== false || $hbn == $match || isset($hbnext[$ext])) {
                     $no_match = false;
                     break;
                 }
             }
             if ($no_match) {
                 continue;
             }
             // most filters _may_ be used once only
             if (@$used_filters[$fname]++ && !($pfilters[$fname][1] & NW_PFILTER_MORE)) {
                 continue;
             }
             // convert to parser object (this should have been done already in the core)
             if (!is_object($lf)) {
                 $lf = new static_response($lf);
             }
             // real-static or parsed/chunked
             $fflags = $pfilters[$fname][1];
             if (NW_PFILTER_IMMEDIATE & $fflags || NW_PFILTER_STATIC & $fflags && is_a($lf, "static_response")) {
                 // filter content on the fly / immediate
                 $GLOBALS["first_chunk"] = true;
                 $pfilters[$fname][0]->filter_func($lf->str, $fargs);
                 $lf->content_length = strlen($lf->str);
                 techo("filter '{$fname}' run on static \$lf content", NW_EL_DEBUG);
             } elseif (($fflags & NW_PFILTER_ALL) >= NW_PFILTER_PARSED) {
                 if ($chunky && !($fflags & NW_PFILTER_CHUNKY)) {
                     continue;
                 }
                 // create wrapper around current $lf
                 $newf = $pfilters[$fname][0];
                 $newf->pp = $lf;
                 $newf->args = $fargs;
                 $newf->fflags = $fflags;
                 $newf->content_length = $lf->content_length;
                 $lf = $newf;
                 unset($newf);
                 techo("filter object '{$fname}' wrapped around current \$lf object", NW_EL_DEBUG);
             }
         }
     }
     #foreach(filter_rule)
     core_modules_hook("after_pfilters");
 }