| Class | PhusionPassenger::Utils::RewindableInput |
| In: |
lib/phusion_passenger/utils/rewindable_input.rb
|
| Parent: | Object |
Class which can make any IO object rewindable, including non-rewindable ones. It does this by buffering the data into a tempfile, which is rewindable.
rack.input is required to be rewindable, so if your input stream IO is non-rewindable by nature (e.g. a pipe or a socket) then you can wrap it in an object of this class to easily make it rewindable.
Don‘t forget to call #close when you‘re done. This frees up temporary resources that RewindableInput uses, though it does not close the original IO object.
# File lib/phusion_passenger/utils/rewindable_input.rb, line 18
18: def initialize(io)
19: @io = io
20: @rewindable_io = nil
21: @unlinked = false
22: end
Closes this RewindableInput object without closing the originally wrapped IO oject. Cleans up any temporary resources that this RewindableInput has created.
This method may be called multiple times. It does nothing on subsequent calls.
# File lib/phusion_passenger/utils/rewindable_input.rb, line 49
49: def close
50: if @rewindable_io
51: if @unlinked
52: @rewindable_io.close
53: else
54: @rewindable_io.close!
55: end
56: @rewindable_io = nil
57: end
58: end
# File lib/phusion_passenger/utils/rewindable_input.rb, line 34
34: def each(&block)
35: make_rewindable unless @rewindable_io
36: @rewindable_io.each(&block)
37: end
# File lib/phusion_passenger/utils/rewindable_input.rb, line 24
24: def gets
25: make_rewindable unless @rewindable_io
26: @rewindable_io.gets
27: end