Class: Rack::AMF::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/amf/application.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, mode) ⇒ Application

Returns a new instance of Application.



6
7
8
9
# File 'lib/rack/amf/application.rb', line 6

def initialize app, mode
  @app = app
  @mode = mode
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rack/amf/application.rb', line 11

def call env
  if env['CONTENT_TYPE'] != APPLICATION_AMF
    return [200, {"Content-Type" => "text/plain"}, ["Hello From Rack::AMF"]]
  end

  # Wrap request and response
  env['amf.request'] = Request.new(env)
  env['amf.response'] = Response.new(env['amf.request'])

  # Handle request
  if @mode == :pass_through
    @app.call env
  elsif @mode == :internal
    # Have the service manager handle it
    Services.handle(env)
  end

  response = env['amf.response'].to_s
  [200, {"Content-Type" => APPLICATION_AMF, 'Content-Length' => response.length.to_s}, [response]]
end