Module: PumaPlus::Input

Defined in:
lib/puma_plus/input.rb

Defined Under Namespace

Classes: FrameStream, NullIO

Constant Summary collapse

EMPTY =

Frozen, which NullIO can afford because it holds no state at all. Two reasons, and the first stands on its own: a rack.input shared across every bodyless request must not be mutable, or one request could scribble on another's. The second is that a frozen stateless object is Ractor-shareable, and this constant is on the request path -- unfrozen, it raises IsolationError the first time a Ractor worker serves a GET.

NullIO.new.freeze

Class Method Summary collapse

Class Method Details

.for(mode, body, conn = nil) ⇒ Object

Build a rack.input for a decoded REQUEST.

NONE -> the shared frozen NullIO. INLINE -> a StringIO over a byteslice of the frame payload. Rewindable for free, and covers essentially every form post and JSON API. STREAM -> FrameStream, pulling BODY_CHUNK frames on demand.



203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/puma_plus/input.rb', line 203

def self.for(mode, body, conn = nil)
  case mode
  when Wire::BODY_NONE   then EMPTY
  when Wire::BODY_INLINE then StringIO.new(body)
  when Wire::BODY_STREAM
    raise ArgumentError, "STREAM body requires a connection" unless conn

    FrameStream.new(conn, body)
  else
    raise ArgumentError, "unknown body_mode #{mode}"
  end
end