Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Perl http daemon with network delay

by danmihai (Initiate)
on Aug 26, 2010 at 08:32 UTC ( #857388=perlquestion: print w/replies, xml ) Need Help??
danmihai has asked for the wisdom of the Perl Monks concerning the following question:

Hi I am trying to create a test environment to simulate a http server over slow connections. HTTP::Daemon from cpan looks like the right thing as to what I need, however it lacks any mean of sending clients responses slower. Can somebody help?

Replies are listed 'Best First'.
Re: Perl http daemon with network delay
by Corion (Pope) on Aug 26, 2010 at 08:37 UTC

    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.

      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; ...
Re: Perl http daemon with network delay
by salva (Abbot) on Aug 26, 2010 at 09:12 UTC
    On Linux, you can do that at the kernel level, we use that feature frequently for testing purposes. I don't know the details, other than it is configured with the tc utility.

    Reading the Linux Traffic Control HOWTO may help.

      This can also be achieved by making webserver from netcat and use the "-i" option. The problem with these methods is the portability to various platforms
        The problem with these methods is the portability to various platforms

        Well, you said it was for a testing environment, so I suppose you want to run your application on several boxes with different operative systems in an environment of your own.

        In that case, the non-portability of my proposed solution shouldn't be a problem because you can run the web servers and the traffic shaper on different machines.

        Actually we just do that, we have a Linux box where we run the traffic shaper and via NAT we redirect some ports to other servers in the same LAN. We can connect directly to the servers or through the shaper and compare the results.

Re: Perl http daemon with network delay
by pemungkah (Priest) on Aug 26, 2010 at 17:54 UTC
    If you need a good mock server, you really can't do better than Mojolicious::Lite. It's trivially easy to set up a server to time out, run slowly, or fail with any error code you like.
      This looks like what I need. Thanks for the hint.
Re: Perl http daemon with network delay
by superfrink (Curate) on Aug 26, 2010 at 19:43 UTC
    Yesterday I heard about a proxy with this feature that runs on windows. It is called fiddler and you can download it from

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://857388]
Approved by marto
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2018-04-26 22:19 GMT
Find Nodes?
    Voting Booth?