Class: Falcon::Adapters::Rewindable
- Inherits:
 - 
      Protocol::HTTP::Middleware
      
        
- Object
 - Protocol::HTTP::Middleware
 - Falcon::Adapters::Rewindable
 
 
- Defined in:
 - lib/falcon/adapters/rewindable.rb
 
Overview
Content-type driven input buffering, specific to the needs of `rack`.
Constant Summary collapse
- BUFFERED_MEDIA_TYPES =
          
Media types that require buffering.
 %r{ application/x-www-form-urlencoded| multipart/form-data| multipart/related| multipart/mixed }x- POST =
 'POST'.freeze
Instance Method Summary collapse
- 
  
    
      #call(request)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Wrap the request body in a rewindable buffer if required.
 - 
  
    
      #initialize(app)  ⇒ Rewindable 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Initialize the rewindable middleware.
 - 
  
    
      #needs_rewind?(request)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Determine whether the request needs a rewindable body.
 
Constructor Details
#initialize(app) ⇒ Rewindable
Initialize the rewindable middleware.
      41 42 43  | 
    
      # File 'lib/falcon/adapters/rewindable.rb', line 41 def initialize(app) super(app) end  | 
  
Instance Method Details
#call(request) ⇒ Object
Wrap the request body in a rewindable buffer if required.
      65 66 67 68 69 70 71  | 
    
      # File 'lib/falcon/adapters/rewindable.rb', line 65 def call(request) if body = request.body and needs_rewind?(request) request.body = Async::HTTP::Body::Rewindable.new(body) end return super end  | 
  
#needs_rewind?(request) ⇒ Boolean
Determine whether the request needs a rewindable body.
      48 49 50 51 52 53 54 55 56 57 58 59 60  | 
    
      # File 'lib/falcon/adapters/rewindable.rb', line 48 def needs_rewind?(request) content_type = request.headers['content-type'] if request.method == POST and content_type.nil? return true end if BUFFERED_MEDIA_TYPES =~ content_type return true end return false end  |