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.

Methods

close   each   gets   new   read   rewind  

Classes and Modules

Class PhusionPassenger::Utils::RewindableInput::Tempfile

Public Class methods

[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

Public Instance methods

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.

[Source]

    # 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

[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

[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

[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

[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

[Validate]