Stas Bekman wrote:

So can flushing be held off until either (1) blank line is printed,
(2) the 8k buffer fills, or (3) send_http_header is called?
1) is relevant only for handler that print headers, rather than set them
2) absolutely not, what if you want to flush data before?
3) send_http_header doesn't exist in Apache2/mod_perl2

I didn't realise that mp2 doesn't use send_http_header. That explains the appearance of wb->r->content_type in the mp2 code. So is it true that if headers are sent using the API then no output filtering and transmission occurs until the 8k buffer is either filled or flushed (explcitly or after exit)?


Only in the case that your handler is configured with:

PerlOptions +ParseHeaders

*and*

it prints headers ala:

print "Content-type: ...."

In all other cases where headers are set via the API, e.g. $r->content_type, $r->headers_out, etc, there is no such a thing as "the handler has send an empty line signaling the end of sending headers", because it never sends any headers at all, but uses api to set them.

Is +ParseHeaders always indicative of explicit header printing, or can it also be set when using the API? If the former, then yes, if +ParseHeaders is set flushing could be held off until a blank line is seen.



With the current mp2 code, if you decide to
wait for the end of headers before doing cgi parsing and flushing then
the code is assuming that either the headers are less than 8k or that any
Status header is in the first 8k.  Otherwise the code would have to
be re-written to use continuous (spilling and merging) buffer buckets
like mod_cgi.  It can hold off on flushing indefinitely.


That approach will break this handler:

sub handler {
  my $r = shift;
  $r->content_type('text/plain');
  $r->rflush; # send something to the client immediately
  long_job();
  return Apache::OK
}

However notice that it doesn't have to set content_type() because some earlier handler could have done that and that should work as well:

sub handler {
  my $r = shift;
  $r->rflush; # send something to the client immediately
  long_job();
  return Apache::OK
}

So as you can see, this handler doesn't tell us when it's done with headers.

OK, you may say that that previous handler should have marked the end of headers settings, but that would be wrong if the response handler wants to set other headers as well.

Do we now agree that the event of "end of sending headers" is possible only in the case explained at the top?

Yes, the key I was missing is that mp2 no longer uses send_http_header. Can you just lock out flushing when nothing has been printed and content_type is undefined? (You impliy above that the content_type setting is persistent, so the script would have to undef it if necessary.) Then all the user script has to do is to make sure any Status header is either printed or set via headers_out in the first batch of printing/setting code before flush is called (again).




Reply via email to