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.
| [reply] [d/l] |
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;
...
| [reply] [d/l] |
| [reply] [d/l] |
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
| [reply] |
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.
| [reply] |
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. | [reply] |
This looks like what I need. Thanks for the hint.
| [reply] |
Yesterday I heard about a proxy with this feature that runs on windows. It is called fiddler and you can download it from www.fiddler2.com. | [reply] |