stubb
stubb copied to clipboard
Add configurable delay in frontmatter
+1
Something like following in yaml (in milliseconds)
---
status: 200
delay: 3000
header:
Cache-Control: no-cache
---
{"name":"Stubb"}
Would also be nice to have some amount of randomness. For example, if delay
is an array [3000, 5000]
, the delay would be some random time between 3000 and 5000 milliseconds.
Maybe it's best to look for existing Rack middleware to do this. For example, mastropinguino/rack-delay seems to offer something akin to what is needed.
Disclaimer: I'm not sure when I might find the time to look into this more.
Thanks for the link.
I created file 'config.ru' in folder with stubb files, installed gem install rack-delay
#config.ru require 'stubb' require 'rack/delay'
use Rack::Delay, { :min => 500, # ms :max => 2000, # ms }
run Stubb::app
From now it is possible to start server with 'rackup' command, moreover i can install any other web server (e.g. thin instead of webrick 'gem install thin') and use any other rack middleware
Cool, thanks for sharing! Maybe there is actually no need for this as a dedicated feature then.
Or if a feature needs to be added, it might be to allow an alternative, even more convenient way of configuring additional middleware to use with Stubb.
I've tried your example without success. I get:
Rack::Lint::LintError: invalid header name: stubb.response_file
That should be from using rackup
, which adds the linter middleware. If you can, work around it by composing Stubb and rack-delay differently.
I will try to push out a fix later today.
@devel-pa Fixed in v0.2.0.