Esempio n. 1
0
 function filter_func(&$lf, $args)
 {
     global $htreq_headers, $out_add_headers, $first_chunk, $chunky;
     if ($first_chunk) {
         $this->gz_method = false;
         foreach (array("deflate", "gzip", "compress") as $m) {
             if (strpos($htreq_headers["ACCEPT-ENCODING"], $m) !== false) {
                 $this->gz_method = $m;
                 break;
             }
         }
         if (!($this->gz_level = access_query("gziplevel", 0))) {
             $this->gz_level = 3;
         }
         $this->engaged = $this->gz_method && empty($out_add_headers["Content-Encoding"]);
         $this->engaged = $this->engaged && (!($chunky || nw_use_chunked_encoding() == true) || access_query("gzipenable", 0) >= 2);
     }
     if ($this->engaged) {
         switch ($this->gz_method) {
             case "deflate":
                 $gz_content = gzdeflate($lf, $this->gz_level);
                 break;
             case "compress":
                 $gz_content = gzcompress($lf, $this->gz_level);
                 break;
             case "gzip":
                 $gz_content = gzencode($lf, $this->gz_level);
                 //(..., FORCE_DEFLATE) ??
             //(..., FORCE_DEFLATE) ??
             default:
         }
         #techo("compressing " . strlen($lf) . " bytes using " . $this->gz_method . " level=".$this->gz_level);
         if (!$chunky || isset($this->pp->content_length)) {
             if (!($maxratio = access_query("gzipmaxratio", 0) / 100)) {
                 $maxratio = 0.9;
             }
             if (!(strlen($gz_content) < strlen($lf) * $maxratio)) {
                 return 0;
             }
             $this->content_length = strlen($gz_content);
         }
         $lf = $gz_content;
         $out_add_headers["Content-Encoding"] = $this->gz_method;
     } else {
         $this->content_length = $this->pp->content_length;
     }
 }
Esempio n. 2
0
         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) {
         $chunk_header = dechex(strlen($buf)) . "\r\n";
         $metasize = strlen($chunk_header) + 2;
         $rbytes = send_response($hbuf . ($buf !== "" ? $chunk_header . $buf . "\r\n" : ""), $sck_connected);
         $sent_len += $rbytes - $metasize;