Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Cherokee: users

Transfer file via php not including content-length when gzip compression active

 

 

Cherokee users RSS feed   Index | Next | Previous | View Threaded


email at davebv

Oct 19, 2009, 11:51 AM

Post #1 of 4 (458 views)
Permalink
Transfer file via php not including content-length when gzip compression active

Hi,
I have been experiencing problems with gzip compression and php, and I kind
of isolate the problem by transfering a file via php.

I set up the headers and send a file like this (implementing private file
system):

$headers = array(
'Pragma: public',
'Expires: 0',
'Cache-Control: must-revalidate, post-check=0, pre-check=0, private',
'Content-Type: '. mime_header_encode($filemime),
'Content-Length: '. $filesize,
'Content-Disposition: inline;',
'Content-Transfer-Encoding: binary',
);

foreach ($headers as $header) {
// To prevent HTTP header injection, we delete new lines that are
// not followed by a space or a tab.
// See http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
$header = preg_replace('/\r?\n(?!\t| )/', '', $header);
header($header);
}


// $source is the path to the file
// Transfer file in 1024 byte chunks to save memory usage.
if ($fd = fopen($source, 'rb')) {
if (!ini_get('safe_mode')) {
set_time_limit(0);
}
while (!feof($fd)) {
print fread($fd, 1024);
}
fclose($fd);
}

exit();

Without gzip compression in encoding in the php behavior I get the correct
headers, for example:


1. Cache-Control:
post-check=0, pre-check=0, must-revalidate, post-check=0, pre-check=0,
private
2. Connection:
Keep-Alive
3. Content-Disposition:
inline;
4. Content-Length:
6514014
5. Content-Transfer-Encoding:
binary
6. Content-Type:
application/octet-stream
7. Date:
Mon, 19 Oct 2009 18:31:55 GMT
8. Expires:
0
9. Keep-Alive:
timeout=1000
10. Last-Modified:
Mon, 19 Oct 2009 18:31:55 GMT
11. Pragma:
public
12. Server:
Cherokee/0.99.24 (Ubuntu)
13. X-Powered-By:
PHP/5.2.6-3ubuntu4.2


Adding gzip compression in encoding in the php behavior I do not get the
content-length when sending the file:


1. Cache-Control:
post-check=0, pre-check=0, must-revalidate, post-check=0, pre-check=0,
private
2. Connection:
Keep-Alive
3. Content-Disposition:
inline;
4. Content-Encoding:
gzip
5. Content-Transfer-Encoding:
binary
6. Content-Type:
application/octet-stream
7. Date:
Mon, 19 Oct 2009 18:35:36 GMT
8. Expires:
0
9. Keep-Alive:
timeout=1000
10. Last-Modified:
Mon, 19 Oct 2009 18:35:36 GMT
11. Pragma:
public
12. Server:
Cherokee/0.99.24 (Ubuntu)
13. Transfer-Encoding:
Identity
14. Vary:
Accept-Encoding
15. X-Powered-By:
PHP/5.2.6-3ubuntu4.2


I do not know what is the real problem, and do not know how to "debug", if
this is cherokee issue, php, etc...

Thanks for the help!


aperez at skarcha

Oct 21, 2009, 11:09 AM

Post #2 of 4 (447 views)
Permalink
Re: Transfer file via php not including content-length when gzip compression active [In reply to]

Hello David,

On Mon, Oct 19, 2009 at 8:51 PM, David Becerril <email[at]davebv.com> wrote:

> Adding gzip compression in encoding in the php behavior I do not get the
> content-length when sending the file:

As far as I know, that is the correct behaviour, because Cherokee
can't figure out what's the length of the gziped data when the headers
are sent to the client.

Anyway, I can see a problem here:

> Connection: Keep-Alive
> Content-Encoding: gzip
> Transfer-Encoding: Identity

You can use gzip encoding with "Keep-Alive" only if
"Transfer-Encoding" is "chunked".


--
Saludos:
Antonio Pérez
_______________________________________________
Cherokee mailing list
Cherokee[at]lists.octality.com
http://lists.octality.com/listinfo/cherokee


aperez at skarcha

Oct 21, 2009, 4:02 PM

Post #3 of 4 (447 views)
Permalink
Re: Transfer file via php not including content-length when gzip compression active [In reply to]

Hello again,

2009/10/21 Antonio Pérez <aperez[at]skarcha.com>:

> Hello David,
>
> On Mon, Oct 19, 2009 at 8:51 PM, David Becerril <email[at]davebv.com> wrote:
>
>> Adding gzip compression in encoding in the php behavior I do not get the
>> content-length when sending the file:
>
> As far as I know, that is the correct behaviour, because Cherokee
> can't figure out what's the length of the gziped data when the headers
> are sent to the client.
>
> Anyway, I can see a problem here:
>
>> Connection: Keep-Alive
>> Content-Encoding: gzip
>> Transfer-Encoding: Identity
>
> You can use gzip encoding with "Keep-Alive" only if
> "Transfer-Encoding" is "chunked".

Seems that "identity" is deprecated[1]

[1] http://trac.tools.ietf.org/wg/httpbis/trac/ticket/16


--
Saludos:
Antonio Pérez
_______________________________________________
Cherokee mailing list
Cherokee[at]lists.octality.com
http://lists.octality.com/listinfo/cherokee


email at davebv

Oct 22, 2009, 12:46 AM

Post #4 of 4 (447 views)
Permalink
Re: Transfer file via php not including content-length when gzip compression active [In reply to]

Thanks you for the answers.
I will have a deeper look into my problem, which now seems more like a
safari issue, (in firefox the length is detected ok)

2009/10/22 Antonio Pérez <aperez[at]skarcha.com>

Hello again,
>
> 2009/10/21 Antonio Pérez <aperez[at]skarcha.com>:
>
> > Hello David,
> >
> > On Mon, Oct 19, 2009 at 8:51 PM, David Becerril <email[at]davebv.com>
> wrote:
> >
> >> Adding gzip compression in encoding in the php behavior I do not get the
> >> content-length when sending the file:
> >
> > As far as I know, that is the correct behaviour, because Cherokee
> > can't figure out what's the length of the gziped data when the headers
> > are sent to the client.
> >
> > Anyway, I can see a problem here:
> >
> >> Connection: Keep-Alive
> >> Content-Encoding: gzip
> >> Transfer-Encoding: Identity
> >
> > You can use gzip encoding with "Keep-Alive" only if
> > "Transfer-Encoding" is "chunked".
>
> Seems that "identity" is deprecated[1]
>
> [1] http://trac.tools.ietf.org/wg/httpbis/trac/ticket/16
>
>
> --
> Saludos:
> Antonio Pérez
>

Cherokee users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.