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.
Constant Summary collapse
- BUFFERED_MEDIA_TYPES =
%r{ application/x-www-form-urlencoded| multipart/form-data| multipart/related| multipart/mixed }x
- POST =
'POST'.freeze
Instance Method Summary collapse
-
#call(request) ⇒ Protocol::HTTP::Response
Wrap the request body in a rewindable buffer.
-
#initialize(app) ⇒ Rewindable
constructor
A new instance of Rewindable.
- #needs_rewind?(request) ⇒ Boolean
Constructor Details
#initialize(app) ⇒ Rewindable
Returns a new instance of Rewindable.
36 37 38 |
# File 'lib/falcon/adapters/rewindable.rb', line 36 def initialize(app) super(app) end |
Instance Method Details
#call(request) ⇒ Protocol::HTTP::Response
Wrap the request body in a rewindable buffer.
56 57 58 59 60 61 62 |
# File 'lib/falcon/adapters/rewindable.rb', line 56 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
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/falcon/adapters/rewindable.rb', line 40 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 |