Ticket #2831: class-snoopy.php.patch

File class-snoopy.php.patch, 2.7 KB (added by Phantagom, 6 years ago)

patch file to add gzip support in class-snoopy.php

  • class-snoopy.php

     
    77Copyright (c): 1999-2000 ispi, all rights reserved 
    88Version: 1.01 
    99 
     10Added Gzip Support for Wordpress by Dennis Kruyt (http://kruyt.org). 
     11 
    1012 * This library is free software; you can redistribute it and/or 
    1113 * modify it under the terms of the GNU Lesser General Public 
    1214 * License as published by the Free Software Foundation; either 
     
    100102                                                                                                // library functions built into php, 
    101103                                                                                                // as these functions are not stable 
    102104                                                                                                // as of this Snoopy release. 
     105        // send Accept-encoding: gzip? 
     106        var $use_gzip           = true; 
    103107 
    104108        /**** Private variables ****/ 
    105109 
     
    802806                } 
    803807                if(!empty($this->accept)) 
    804808                        $headers .= "Accept: ".$this->accept."\r\n"; 
     809 
     810                if($this->use_gzip) { 
     811                        // make sure PHP was built with --with-zlib 
     812                        // and we can handle gzipp'ed data 
     813                        if ( function_exists(gzinflate) ) { 
     814                           $headers .= "Accept-encoding: gzip\r\n"; 
     815                        } 
     816                        else { 
     817                           trigger_error( 
     818                                "use_gzip is on, but PHP was built without zlib support.". 
     819                                "  Requesting file(s) without gzip encoding.", 
     820                                E_USER_NOTICE); 
     821                        } 
     822                } 
     823 
    805824                if(!empty($this->referer)) 
    806825                        $headers .= "Referer: ".$this->referer."\r\n"; 
    807826                if(!empty($this->cookies)) 
     
    853872                $this->_redirectaddr = false; 
    854873                unset($this->headers); 
    855874 
     875                // content was returned gzip encoded? 
     876                $is_gzipped = false; 
     877 
    856878                while($currentHeader = fgets($fp,$this->_maxlinelen)) 
    857879                { 
    858880                        if ($this->read_timeout > 0 && $this->_check_timeout($fp)) 
     
    892914                } 
    893915                                $this->response_code = $currentHeader; 
    894916                        } 
    895  
     917                        if (preg_match("/Content-Encoding: gzip/", $currentHeader) ) { 
     918                                $is_gzipped = true; 
     919                        } 
    896920                        $this->headers[] = $currentHeader; 
    897921                } 
    898922 
     
    905929                $results .= $_data; 
    906930                } while(true); 
    907931 
     932               // gunzip 
     933                if ( $is_gzipped ) { 
     934                        // per http://www.php.net/manual/en/function.gzencode.php 
     935                        $results = substr($results, 10); 
     936                        $results = gzinflate($results); 
     937                } 
     938 
    908939                if ($this->read_timeout > 0 && $this->_check_timeout($fp)) 
    909940                { 
    910941                        $this->status=-100;