t/GNUmakefile: cleanup test dependencies
[rainbows.git] / t / close-has-env.ru
blob471f605d275b32adb051a51d30e9d635f7531dfe
1 #\ -E none
2 use Rainbows::DevFdResponse
3 class ClosablePipe < ::IO
4   attr_accessor :env
6   def self.new(env)
7     rv = popen "echo hello", "rb"
8     rv.env = env
9     rv
10   end
12   def close
13     super
14     $stdout.syswrite "path_info=#{@env['PATH_INFO']}\n"
15   end
16 end
18 class ClosableFile < ::File
19   attr_accessor :env
20   alias to_path path
21   def close
22     super
23     $stdout.syswrite "path_info=#{@env['PATH_INFO']}\n"
24   end
25 end
27 class Blob
28   def initialize(env)
29     @env = env
30   end
32   def each(&block)
33     yield "BLOB\n"
34   end
36   def close
37     $stdout.syswrite "path_info=#{@env['PATH_INFO']}\n"
38   end
39 end
41 run(lambda { |env|
42   case env["PATH_INFO"]
43   when %r{\A/pipe/}
44     [ 200,
45       [ %w(Content-Length 6), %w(Content-Type text/plain)],
46       ClosablePipe.new(env)
47     ]
48   when %r{\A/file/}
49     f = ClosableFile.open("env.ru", "rb")
50     f.env = env
51     [ 200, {
52       'X-Req-Path' => env["PATH_INFO"],
53       'Content-Length' => f.stat.size.to_s,
54       'Content-Type' => 'text/plain' },
55       f
56     ]
57   when %r{\A/blob/}
58     [ 200,
59       [%w(Content-Length 5), %w(Content-Type text/plain)],
60       Blob.new(env)
61     ]
62   else
63     [ 404, [%w(Content-Length 0), %w(Content-Type text/plain)], [] ]
64   end