in reply to Perl http daemon with network delay

I had good success with using HTTP::Daemon as a local "fake" server (in Test::HTTP::LocalServer and log-server). If you want to send a response slow, just add a sleep before calling $c->send_response(). If you want to have that response sent in a trickling fashion, like (say) only transferring 1k/s, I fear that HTTP::Daemon does not provide a direct avenue. But from looking at the code, you can pass in a code reference instead of a HTTP::Response, and that code reference can send the pieces in small bits I think.

Replies are listed 'Best First'.
Re^2: Perl http daemon with network delay
by danmihai (Initiate) on Aug 26, 2010 at 12:41 UTC
    The trickling way is what I need, unfortunately it looks like there is no way of sending the response in pieces, because the code reference refers to a HTTP::Response object, that is evaluated before sending. This is the interesting part from HTTP::Daemon, line 445
    sub send_response { my $self = shift; my $res = shift; if (!ref $res) { $res ||= RC_OK; $res = HTTP::Response->new($res, @_); } my $content = $res->content; ...