stubb icon indicating copy to clipboard operation
stubb copied to clipboard

Add configurable delay in frontmatter

Open knuton opened this issue 11 years ago • 7 comments

knuton avatar Nov 24 '13 23:11 knuton

+1

Something like following in yaml (in milliseconds)

---
status: 200
delay: 3000
header:
  Cache-Control: no-cache
---
{"name":"Stubb"}

menemy avatar Apr 14 '14 14:04 menemy

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.

knuton avatar Apr 16 '14 10:04 knuton

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

menemy avatar Apr 16 '14 13:04 menemy

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.

knuton avatar Apr 16 '14 13:04 knuton

I've tried your example without success. I get:

Rack::Lint::LintError: invalid header name: stubb.response_file

devel-pa avatar Oct 03 '14 15:10 devel-pa

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.

knuton avatar Oct 03 '14 16:10 knuton

@devel-pa Fixed in v0.2.0.

knuton avatar Oct 03 '14 17:10 knuton