File: sleep_step.ru

package info (click to toggle)
puma 6.6.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,884 kB
  • sloc: ruby: 17,542; ansic: 2,003; java: 1,006; sh: 379; makefile: 10
file content (11 lines) | stat: -rw-r--r-- 386 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
# call with "GET /sleep<d>-<s> HTTP/1.1\r\n\r\n", where <d> is the number of
# seconds to sleep (can be a float or an int) and <s> is the step

regex_delay = /\A\/sleep(\d+(?:\.\d+)?)/
run lambda { |env|
  p = env['REQUEST_PATH']
  delay = (p[regex_delay,1] || '0').to_f
  step = p[/(\d+)\z/,1].to_i
  sleep delay
  [200, {"Content-Type" => "text/plain"}, ["Slept #{delay} #{step}"]]
}