Sha256: 07e5ec547c4c6b0c4e1b83703873c9564ed5e73805f12af2ace93e1df78a3378

Contents?: true

Size: 1.17 KB

Versions: 21

Compression:

Stored size: 1.17 KB

Contents

#\ -E none
use Rainbows::DevFdResponse
class ClosablePipe < ::IO
  attr_accessor :env

  def self.new(env)
    rv = popen "echo hello", "rb"
    rv.env = env
    rv
  end

  def close
    super
    $stdout.syswrite "path_info=#{@env['PATH_INFO']}\n"
  end
end

class ClosableFile < ::File
  attr_accessor :env
  alias to_path path
  def close
    super
    $stdout.syswrite "path_info=#{@env['PATH_INFO']}\n"
  end
end

class Blob
  def initialize(env)
    @env = env
  end

  def each(&block)
    yield "BLOB\n"
  end

  def close
    $stdout.syswrite "path_info=#{@env['PATH_INFO']}\n"
  end
end

run(lambda { |env|
  case env["PATH_INFO"]
  when %r{\A/pipe/}
    [ 200,
      [ %w(Content-Length 6), %w(Content-Type text/plain)],
      ClosablePipe.new(env)
    ]
  when %r{\A/file/}
    f = ClosableFile.open("env.ru", "rb")
    f.env = env
    [ 200, {
      'X-Req-Path' => env["PATH_INFO"],
      'Content-Length' => f.stat.size.to_s,
      'Content-Type' => 'text/plain' },
      f
    ]
  when %r{\A/blob/}
    [ 200,
      [%w(Content-Length 5), %w(Content-Type text/plain)],
      Blob.new(env)
    ]
  else
    [ 404, [%w(Content-Length 0), %w(Content-Type text/plain)], [] ]
  end
})

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rainbows-4.6.2 t/close-has-env.ru
rainbows-4.6.1 t/close-has-env.ru
rainbows-4.6.0.4.g4108 t/close-has-env.ru
rainbows-4.6.0 t/close-has-env.ru
rainbows-4.5.0 t/close-has-env.ru
rainbows-4.4.3 t/close-has-env.ru
rainbows-4.4.2 t/close-has-env.ru
rainbows-4.4.1.1.gd5c8c t/close-has-env.ru
rainbows-4.4.1 t/close-has-env.ru
rainbows-4.4.0 t/close-has-env.ru
rainbows-4.3.1 t/close-has-env.ru
rainbows-4.3.0 t/close-has-env.ru
rainbows-4.2.0 t/close-has-env.ru
rainbows-4.1.0 t/close-has-env.ru
rainbows-4.0.0 t/close-has-env.ru
rainbows-3.4.0 t/close-has-env.ru
rainbows-3.3.0 t/close-has-env.ru
rainbows-3.2.0 t/close-has-env.ru
rainbows-3.1.0 t/close-has-env.ru
rainbows-3.0.0 t/close-has-env.ru