You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Ben RUBSON <be...@gmail.com> on 2017/02/06 17:33:50 UTC

Flush headers ?

Hi,

I'm using mod_perl2 and I'm trying to flush headers before the body content.

$r->content_type('application/zip');
$r->headers_out->add('Content-Disposition' => 'attachment');
$r->rflush;
long_operation();

Unfortunately this does not work.

The following works, but of course corrupts my output :

$r->content_type('application/zip');
$r->headers_out->add('Content-Disposition' => 'attachment');
print "\0";
$r->rflush;
long_operation();

Any clue ?

Many thanks !

Ben

Re: Flush headers ?

Posted by Ben RUBSON <be...@gmail.com>.
> On 07 Feb 2017, at 02:40, André Warnier (tomcat) <aw...@ice-sa.com> wrote:
> 
> On 06.02.2017 18:33, Ben RUBSON wrote:
>> Hi,
>> 
>> I'm using mod_perl2 and I'm trying to flush headers before the body content.
>> 
>> $r->content_type('application/zip');
>> $r->headers_out->add('Content-Disposition' => 'attachment');
>> $r->rflush;
>> long_operation();
>> 
>> Unfortunately this does not work.
> 
> When you say "this does not work", can you be more explicit ?

Yes,

> If you trace the browser request/response headers, what does it show exactly ?

the headers on client side do not arrive until there is also some body content.
So in the quoted code below, due to the little body addition (\0), headers correctly immediately arrive on client side.

>> The following works, but of course corrupts my output :
>> 
>> $r->content_type('application/zip');
>> $r->headers_out->add('Content-Disposition' => 'attachment');
>> print "\0";
>> $r->rflush;
>> long_operation();

In the documentation :
https://perl.apache.org/docs/2.0/user/coding/coding.html#Forcing_HTTP_Response_Headers_Out
"Apache 2.0 doesn't provide a method to force HTTP response headers sending (what used to be done by send_http_header() in Apache 1.3).
HTTP response headers are sent as soon as the first bits of the response body are seen by the special core output filter that generates these headers."

What is strange is that just below this extract is given the rflush example I'm trying to use.

Ben

Re: Flush headers ?

Posted by Jie Gao <J....@sydney.edu.au>.
* Ben RUBSON <be...@gmail.com> wrote:

> I investigated further and found that the following example :
> my $r = shift;
> $r->content_type('text/html');
> $r->rflush();
> sleep(10);
> $r->print("HelloWorld");
> $r->rflush();
> sleep(10);
> 
> Works as expected with Debian 7, Apache 2.2.22-13+deb7u6, mod_perl 2.0.7-3.
> Works as expected with Debian 8, Apache 2.4.10-10+deb8u5, mod_perl 2.0.9~1624218-2+deb8u1.
> 
> But does not work with FreeBSD 11, Apache 2.4.25_1, mod_perl 2.0.10,3.
> (headers only flushed after the first 10 seconds)

It works for me with Apache/2.4.23 (Unix) + mod_perl/2.0.10 + Perl/v5.20.2, all manually compiled locally on a RHEL6 box.

In testing with the following registry script:

#!/usr/local/bin/perl -w
use strict;

my $r = Apache2::RequestUtil->request;
$r->content_type("text/html");

$r->rflush();

sleep 60;

print "Delayed output: ", time(), "\n"; 
# END

, the headers were sent right away and were followed by the response body 60sec later.


Regards,


Jie 


Re: Flush headers ?

Posted by Ben RUBSON <be...@gmail.com>.
> On 07 Feb 2017, at 03:21, Jie Gao <J....@sydney.edu.au> wrote:
> 
> Try moving the header addition line to after the flush statement.
> 
> Regards,
> 
> Jie 

Unfortunately it does not help :-/
Even keeping only one header line (the content-type one).

I investigated further and found that the following example :
my $r = shift;
$r->content_type('text/html');
$r->rflush();
sleep(10);
$r->print("HelloWorld");
$r->rflush();
sleep(10);

Works as expected with Debian 7, Apache 2.2.22-13+deb7u6, mod_perl 2.0.7-3.
Works as expected with Debian 8, Apache 2.4.10-10+deb8u5, mod_perl 2.0.9~1624218-2+deb8u1.

But does not work with FreeBSD 11, Apache 2.4.25_1, mod_perl 2.0.10,3.
(headers only flushed after the first 10 seconds)

All packages installed using compiled repositories (apt / pkg).

Ben

Re: Flush headers ?

Posted by Jie Gao <J....@sydney.edu.au>.
Try moving the header addition line to after the flush statement.

Regards,

Jie 

* André Warnier (tomcat) <aw...@ice-sa.com> wrote:

> Date: Tue, 7 Feb 2017 02:40:44 +0100
> From: "André Warnier (tomcat)" <aw...@ice-sa.com>
> To: modperl@perl.apache.org
> Subject: Re: Flush headers ?
> User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:38.0) Gecko/20100101
>  Thunderbird/38.5.0
> 
> On 06.02.2017 18:33, Ben RUBSON wrote:
> >Hi,
> >
> >I'm using mod_perl2 and I'm trying to flush headers before the body content.
> >
> >$r->content_type('application/zip');
> >$r->headers_out->add('Content-Disposition' => 'attachment');
> >$r->rflush;
> >long_operation();
> >
> >Unfortunately this does not work.
> 
> When you say "this does not work", can you be more explicit ?
> If you trace the browser request/response headers, what does it show exactly ?
> 
> >
> >The following works, but of course corrupts my output :
> >
> >$r->content_type('application/zip');
> >$r->headers_out->add('Content-Disposition' => 'attachment');
> >print "\0";
> >$r->rflush;
> >long_operation();
> >
> >Any clue ?
> >
> >Many thanks !
> >
> >Ben
> >
> 


Re: Flush headers ?

Posted by "André Warnier (tomcat)" <aw...@ice-sa.com>.
On 06.02.2017 18:33, Ben RUBSON wrote:
> Hi,
>
> I'm using mod_perl2 and I'm trying to flush headers before the body content.
>
> $r->content_type('application/zip');
> $r->headers_out->add('Content-Disposition' => 'attachment');
> $r->rflush;
> long_operation();
>
> Unfortunately this does not work.

When you say "this does not work", can you be more explicit ?
If you trace the browser request/response headers, what does it show exactly ?

>
> The following works, but of course corrupts my output :
>
> $r->content_type('application/zip');
> $r->headers_out->add('Content-Disposition' => 'attachment');
> print "\0";
> $r->rflush;
> long_operation();
>
> Any clue ?
>
> Many thanks !
>
> Ben
>