Class: XMLRPC::ModRubyServer

Inherits:
BasicServer show all
Defined in:
lib/xmlrpc/server.rb

Overview

XMLRPC::ModRubyServer

Description

Implements a XML-RPC server, which works with Apache mod_ruby.

Use it in the same way as CGIServer!

Superclass

((<XMLRPC::BasicServer>))

Constant Summary

Constants inherited from BasicServer

BasicServer::ERR_MC_EXPECTED_STRUCT, BasicServer::ERR_MC_MISSING_METHNAME, BasicServer::ERR_MC_MISSING_PARAMS, BasicServer::ERR_MC_RECURSIVE_CALL, BasicServer::ERR_MC_WRONG_PARAM, BasicServer::ERR_MC_WRONG_PARAM_PARAMS, BasicServer::ERR_METHOD_MISSING, BasicServer::ERR_UNCAUGHT_EXCEPTION

Instance Method Summary collapse

Methods inherited from BasicServer

#add_handler, #add_introspection, #add_multicall, #get_default_handler, #get_service_hook, #process, #set_default_handler, #set_service_hook

Methods included from ParseContentType

#parse_content_type

Methods included from ParserWriterChooseMixin

#set_parser, #set_writer

Constructor Details

#initialize(*a) ⇒ ModRubyServer

Returns a new instance of ModRubyServer.



514
515
516
517
# File 'lib/xmlrpc/server.rb', line 514

def initialize(*a)
  @ap = Apache::request
  super(*a)
end

Instance Method Details

#serveObject



519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# File 'lib/xmlrpc/server.rb', line 519

def serve
  catch(:exit_serve) {
    header = {}
    @ap.headers_in.each {|key, value| header[key.capitalize] = value}

    length = header['Content-length'].to_i

    http_error(405, "Method Not Allowed") unless @ap.request_method  == "POST"
    http_error(400, "Bad Request")        unless parse_content_type(header['Content-type']).first == "text/xml"
    http_error(411, "Length Required")    unless length > 0

    # TODO: do we need a call to binmode?
    @ap.binmode
    data = @ap.read(length)

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

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