Class: Rack::RPC::Endpoint
- Inherits:
-
Middleware
- Object
- Middleware
- Rack::RPC::Endpoint
- Defined in:
- lib/rack/rpc/endpoint.rb,
lib/rack/rpc/endpoint/jsonrpc.rb,
lib/rack/rpc/endpoint/xmlrpc.rb
Overview
A Rack middleware for RPC endpoints.
Defined Under Namespace
Constant Summary collapse
- DEFAULT_PATH =
'/rpc'
Instance Attribute Summary collapse
- #server ⇒ Server readonly
Attributes inherited from Middleware
Instance Method Summary collapse
- #call(env) ⇒ Array
-
#initialize(app, server, options = {}) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #path ⇒ String
Constructor Details
#initialize(app, server, options = {}) ⇒ Endpoint
Returns a new instance of Endpoint.
21 22 23 24 |
# File 'lib/rack/rpc/endpoint.rb', line 21 def initialize(app, server, = {}) @server = server super(app, ) end |
Instance Attribute Details
#server ⇒ Server (readonly)
11 12 13 |
# File 'lib/rack/rpc/endpoint.rb', line 11 def server @server end |
Instance Method Details
#call(env) ⇒ Array
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rack/rpc/endpoint.rb', line 35 def call(env) return super unless env['PATH_INFO'].eql?(path) return super unless env['REQUEST_METHOD'].eql?('POST') case content_type = env['CONTENT_TYPE'] when %r(^application/xml), %r(^text/xml) XMLRPC::Server.new(server).execute(Rack::Request.new(env)).finish when %r(^application/json) JSONRPC::Server.new(server).execute(Rack::Request.new(env)).finish else super end end |
#path ⇒ String
28 29 30 |
# File 'lib/rack/rpc/endpoint.rb', line 28 def path @path ||= [:path] || DEFAULT_PATH end |