On Sun, Nov 25, 2001 at 11:11:09PM -0500, Jason Boxman wrote:
> 

[...]

> First, *HTTPD wants to tack on a duplicate protocol and version to each 
> outgoing stream:

[...]

Sorry about that.  I've committed a fix for it to CVS, and it'll be in
the next release.

The next release is waiting for me to rewrite testomatic so I can
resume the automated cross-platform tests.

> Second, as you'll note above you cannot send a response header to a browser 
> without content, because the trailing network lines indicate to the browser 
> that the content will follow.
> 
> In my application, I'm using PoCoCi::UserAgent and LWP::UserAgent's callback 
> for data chunks which means I'll be passing data back later on.  Forcing the 
> browser to think content follows the header as above thwarts this.

I don't understand this part.  Artur Bergman, the author of
Filter::HTTPD, wrote a simple streaming mp3 server that sends headers
first and then chunks of content later.  Here's the part that answers
requests:

sub got_request {
  my $request = $_[ARG0];
  print "got $request\n";

  my $response = HTTP::Response->new(200,"Ok");
  $response->push_header("Content-type", "audio/x-mpeg");

  # Probably could push a content-length header by getting
  # the size of $mp3_file_name here.

  $_[HEAP]->{wheel}->put($response);
}

sub got_flush {

  # If the mp3 file isn't open, we've just flushed the headers.
  # Open the mp3 file here, and switch the filter from HTTPD to
  # stream.

  unless ($_[HEAP]->{mp3}) {
    my $mp3 = $_[HEAP]->{mp3} = gensym();
    open($mp3, "<$mp3_file_name") or die $!;

    $_[HEAP]->{wheel}->set_output_filter(POE::Filter::Stream->new());
  }

  # Write the next chunk of the mp3 to the client.

  my $read = sysread( $_[HEAP]->{mp3}, my $buffer = '', 4096);
  if ($read) {
    $_[HEAP]->{wheel}->put($buffer);
  }
  else {
    $_[HEAP]->{close}++;
  }

  # If we flushed the last part of the mp3 file, close it and
  # shut down the server.

  if($_[HEAP]->{close}) {
    delete($_[HEAP]->{wheel});
    close $_[HEAP]->{mp3};
  }
}

The newline doesn't seem to hurt this application, but the remote
client is an mp3 player.  Does it really break browsers?

-- Rocco Caputo / [EMAIL PROTECTED] / poe.perl.org / poe.sourceforge.net

Reply via email to