Class: Falcon::Adapters::Rewindable

Inherits:
Protocol::HTTP::Middleware
  • Object
show all
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

Constructor Details

#initialize(app) ⇒ Rewindable

Returns a new instance of Rewindable.



38
39
40
# File 'lib/falcon/adapters/rewindable.rb', line 38

def initialize(app)
	super(app)
end

Instance Method Details

#call(request) ⇒ Protocol::HTTP::Response

Wrap the request body in a rewindable buffer.

Returns:

  • (Protocol::HTTP::Response)

    the response.



58
59
60
61
62
63
64
# File 'lib/falcon/adapters/rewindable.rb', line 58

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

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/falcon/adapters/rewindable.rb', line 42

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