Page 1 of 1

v132 / output compression wont work in every cases

Posted: Sat Aug 15, 2009 8:33 pm
by stefan_m
hello,

at first, thanks for your great solution, very very well... tiny, simple and very fast. THANK YOU!

response.php

the lines which dealing with the accepted encoding given an incorrect answer

Code: Select all

if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
    $encoding = 'gzip';
} 

if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip')) {
    $encoding = 'x-gzip';
}

Code: Select all

echo $_SERVER['HTTP_ACCEPT_ENCODING'] ; 
gzip,deflate // gzip at first position

Code: Select all

var_dump (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'));
int(0)

Code: Select all

var_dump (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip'));
bool(false)

Code: Select all

if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
    echo 'gzip accepted';
} else {
    echo 'result of int(0) seems to be interpreted as false in if-condition';
}
result of int(0) seems to be interpreted as false in if-condition
the solution is to check if strpos not false

Code: Select all

if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])
    && strpos ($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) {
    $encoding = 'gzip';
}
elseif (isset($_SERVER['HTTP_ACCEPT_ENCODING'])
    && strpos ($_SERVER['HTTP_ACCEPT_ENCODING'],'x-gzip') !== false) {
    $encoding = 'x-gzip';
}
this working in my case and maybe also in others.

ciao, Stefan

Re: v132 / output compression wont work in every cases

Posted: Sat Aug 15, 2009 8:53 pm
by Daniel
ok thanks!

I have added this to the next release.

Re: v132 / output compression wont work in every cases

Posted: Sun Aug 16, 2009 6:33 am
by SuperJuice
Very nice find stefan_m, well done! 8)

Re: v132 / output compression wont work in every cases

Posted: Sun Aug 16, 2009 9:31 pm
by stefan_m
hello juice,

thanks, but its not really a big thing, i am just wondering about the missing compression, so i found it.

adios, stefan

PS: You can call me "stefan" thats enough. "stefan_m" looks strange :-)

Re: v132 / output compression wont work in every cases

Posted: Mon Sep 14, 2009 10:13 pm
by banane
just a question, why scripts and css are not compressed?
thanks