Module: Rack::AMF::Middleware
- Included in:
- PassThrough, ServiceManager
- Defined in:
- lib/rack/amf/middleware/service_manager.rb,
lib/rack/amf/middleware/pass_through.rb,
lib/rack/amf/middleware.rb
Overview
Provide some helper items that can be included in the various middleware being offered.
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.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rack/amf/middleware.rb', line 13 def call env #:nodoc: return @app.call(env) unless should_handle?(env) # Wrap request and response env['rack-amf.request'] = Request.new(env) env['rack-amf.response'] = Response.new(env['rack-amf.request']) # 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
29 30 31 32 33 |
# File 'lib/rack/amf/middleware.rb', line 29 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 |