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.
[ show source ]
# 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.
[ show source ]
# File lib/phusion_passenger/utils/rewindable_input.rb, line 54 54: def close 55: if @rewindable_io 56: if @unlinked 57: @rewindable_io.close 58: else 59: @rewindable_io.close! 60: end 61: @rewindable_io = nil 62: end 63: end
[ show source ]
# 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
[ show source ]
# 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
[ show source ]
# File lib/phusion_passenger/utils/rewindable_input.rb, line 29 29: def read(*args) 30: make_rewindable unless @rewindable_io 31: @rewindable_io.read(*args) 32: end
[ show source ]
# File lib/phusion_passenger/utils/rewindable_input.rb, line 39 39: def rewind 40: make_rewindable unless @rewindable_io 41: @rewindable_io.rewind 42: end
[ show source ]
# File lib/phusion_passenger/utils/rewindable_input.rb, line 44 44: def size 45: make_rewindable unless @rewindable_io 46: @rewindable_io.size 47: end