unicorn.git  about / heads / tags
Rack HTTP server for Unix and fast clients
blob 12eb3e8b446e72743db5645e0e8a54af3de932af 674 bytes (raw)
$ git show no-kgio-wip:lib/unicorn/preread_input.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
# -*- encoding: binary -*-

module Unicorn
# This middleware is used to ensure input is buffered to memory
# or disk (depending on size) before the application is dispatched
# by entirely consuming it (from TeeInput) beforehand.
#
# Usage (in config.ru):
#
#     require 'unicorn/preread_input'
#     if defined?(Unicorn)
#       use Unicorn::PrereadInput
#     end
#     run YourApp.new
class PrereadInput

  # :stopdoc:
  def initialize(app)
    @app = app
  end

  def call(env)
    buf = ""
    input = env["rack.input"]
    if input.respond_to?(:rewind)
      true while input.read(16384, buf)
      input.rewind
    end
    @app.call(env)
  end
  # :startdoc:
end
end

git clone https://yhbt.net/unicorn.git