Module: Rack::AMF::Middleware
- Included in:
- PassThrough, ServiceManager
- Defined in:
- lib/rack/amf/middleware.rb,
lib/rack/amf/middleware/pass_through.rb,
lib/rack/amf/middleware/service_manager.rb
Overview
:nodoc:
Defined Under Namespace
Classes: PassThrough, ServiceManager
Constant Summary collapse
- APPLICATION_AMF =
:nodoc:
'application/x-amf'.freeze
Instance Method Summary collapse
-
#call(env) ⇒ Object
Standard middleware call method.
-
#should_handle?(env) ⇒ Boolean
Check if we should handle it based on the environment.
Instance Method Details
#call(env) ⇒ Object
Standard middleware call method. Calls “handle” with the environment after creating the request and response objects, and handles serializing the response after the middleware is done.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rack/amf/middleware.rb', line 10 def call env #:nodoc: return @app.call(env) unless should_handle?(env) # Wrap request and response env['rack.input'].rewind env['rack-amf.request'] = RocketAMF::Envelope.new.populate_from_stream(env['rack.input'].read) env['rack-amf.response'] = RocketAMF::Envelope.new # Call handle on "inheriting" class handle env # Calculate length and return response response = env['rack-amf.response'].to_s [200, {"Content-Type" => APPLICATION_AMF, 'Content-Length' => response.length.to_s}, [response]] end |
#should_handle?(env) ⇒ Boolean
Check if we should handle it based on the environment
27 28 29 30 31 |
# File 'lib/rack/amf/middleware.rb', line 27 def should_handle? env #:nodoc: return false unless env['CONTENT_TYPE'] == APPLICATION_AMF return false if Rack::AMF::Environment.url && env['PATH_INFO'] != Rack::AMF::Environment.url true end |