class XMLRPC::RackApplication

Implements a XML-RPC application, which works with Rack

Public Instance Methods

call(env) click to toggle source

This method processes a XML-RPC method call and sends the answer back to the client.

# File lib/xmlrpc/server.rb, line 464
def call(env)
  length = env['CONTENT_LENGTH'].to_i

  return http_error(405, "Method Not Allowed") unless env['REQUEST_METHOD'] == "POST"
  return http_error(400, "Bad Request")        unless parse_content_type(env['CONTENT_TYPE']).first == "text/xml"
  return http_error(411, "Length Required")    unless length > 0

  req = Rack::Request.new(env)
  data = req.body.read(length)

  return http_error(400, "Bad Request")        if data.nil? or data.bytesize != length

  [200, { "Content-type" => "text/xml; charset=utf-8" }, [process(data)]]
end

Private Instance Methods

http_error(status, message) click to toggle source
# File lib/xmlrpc/server.rb, line 482
  def http_error(status, message)
    err = "#{status} #{message}"
    msg = <<-"MSGEND"
      <html>
        <head>
          <title>#{err}</title>
        </head>
        <body>
          <h1>#{err}</h1>
          <p>Unexpected error occurred while processing XML-RPC request!</p>
        </body>
      </html>
    MSGEND

    [status, { "Content-Type" => "text/html" }, [msg]]
  end