1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/xmlrpc/server.rb (XMLRPC::Server): Switch from GServer over to

WEBrick. This makes file lib/xmlrpc/httpserver.rb obsolete (at least it is
		no further used by the XML-RPC library).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mneumann 2005-07-10 20:37:32 +00:00
parent e3fa33da38
commit 9222f534cf
2 changed files with 49 additions and 96 deletions

View file

@ -1,3 +1,9 @@
Sun Jul 10 22:18:17 CEST 2005 Michael Neumann <mneumann@ruby-lang.org>
* lib/xmlrpc/server.rb (XMLRPC::Server): Switch from GServer over to
WEBrick. This makes file lib/xmlrpc/httpserver.rb obsolete (at least it is
no further used by the XML-RPC library).
Mon Jul 11 02:50:23 2005 GOTOU Yuuzou <gotoyuzo@notwork.org> Mon Jul 11 02:50:23 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/cgi.rb (WEBrick::CGI::Socket#request_line): * lib/webrick/cgi.rb (WEBrick::CGI::Socket#request_line):

View file

@ -1,6 +1,6 @@
=begin =begin
= xmlrpc/server.rb = xmlrpc/server.rb
Copyright (C) 2001, 2002, 2003 by Michael Neumann (mneumann@ntecs.de) Copyright (C) 2001, 2002, 2003, 2005 by Michael Neumann (mneumann@ntecs.de)
Released under the same term of license as Ruby. Released under the same term of license as Ruby.
@ -145,7 +145,6 @@ the same class.
require "xmlrpc/parser" require "xmlrpc/parser"
require "xmlrpc/create" require "xmlrpc/create"
require "xmlrpc/config" require "xmlrpc/config"
require "xmlrpc/httpserver"
require "xmlrpc/utils" # ParserWriterChooseMixin require "xmlrpc/utils" # ParserWriterChooseMixin
@ -573,9 +572,6 @@ class ModRubyServer < BasicServer
end end
=begin =begin
= XMLRPC::Server = XMLRPC::Server
== Synopsis == Synopsis
@ -607,7 +603,7 @@ Implements a standalone XML-RPC server. The method (({serve}))) is left if a SIG
program. program.
== Superclass == Superclass
((<XMLRPC::BasicServer>)) ((<XMLRPC::WEBrickServlet>))
== Class Methods == Class Methods
--- XMLRPC::Server.new( port=8080, host="127.0.0.1", maxConnections=4, stdlog=$stdout, audit=true, debug=true, *a ) --- XMLRPC::Server.new( port=8080, host="127.0.0.1", maxConnections=4, stdlog=$stdout, audit=true, debug=true, *a )
@ -615,12 +611,10 @@ program.
port ((|port|)) and accepts requests for the host ((|host|)), which is by default only the localhost. port ((|port|)) and accepts requests for the host ((|host|)), which is by default only the localhost.
The server is not started, to start it you have to call ((<serve|XMLRPC::Server#serve>)). The server is not started, to start it you have to call ((<serve|XMLRPC::Server#serve>)).
The parameters ((|maxConnections|)), ((|stdlog|)), ((|audit|)) and ((|debug|)) are passed to the HTTP server and Parameters ((|audit|)) and ((|debug|)) are obsolete!
specify it's behaviour more precise.
All additionally given parameters in ((|*a|)) are by-passed to ((<XMLRPC::BasicServer.new>)). All additionally given parameters in ((|*a|)) are by-passed to ((<XMLRPC::BasicServer.new>)).
== Instance Methods == Instance Methods
--- XMLRPC::Server#serve --- XMLRPC::Server#serve
Call this after you have added all you handlers to the server. Call this after you have added all you handlers to the server.
@ -629,22 +623,18 @@ program.
--- XMLRPC::Server#shutdown --- XMLRPC::Server#shutdown
Stops and shuts the server down. Stops and shuts the server down.
--- XMLRPC::Server#set_valid_ip( *ip_addr )
Specifies the valid IP addresses that are allowed to connect to the server.
Each IP is either a (({String})) or a (({Regexp})).
--- XMLRPC::Server#get_valid_ip
Return the via method ((<set_valid_ip|XMLRPC::Server#set_valid_ip>)) specified
valid IP addresses.
=end =end
class Server < BasicServer class WEBrickServlet < BasicServer; end # forward declaration
class Server < WEBrickServlet
def initialize(port=8080, host="127.0.0.1", maxConnections=4, stdlog=$stdout, audit=true, debug=true, *a) def initialize(port=8080, host="127.0.0.1", maxConnections=4, stdlog=$stdout, audit=true, debug=true, *a)
super(*a) super(*a)
@server = ::HttpServer.new(self, port, host, maxConnections, stdlog, audit, debug) require 'webrick'
@valid_ip = nil @server = WEBrick::HTTPServer.new(:Port => port, :BindAddress => host, :MaxClients => maxConnections,
:Logger => WEBrick::Log.new(stdlog))
@server.mount("/RPC2", self)
end end
def serve def serve
@ -662,80 +652,8 @@ class Server < BasicServer
@server.shutdown @server.shutdown
end end
def set_valid_ip(*ip_addr)
if ip_addr.size == 1 and ip_addr[0].nil?
@valid_ip = nil
else
@valid_ip = ip_addr
end
end
def get_valid_ip
@valid_ip
end
# methods that get called by HttpServer ------------------------------------------
def request_handler(request, response)
$stderr.puts "in request_handler" if $DEBUG
if request.method != "POST"
# Method not allowed
response.status = 405
return
end
if parse_content_type(request.header['Content-type']).first != "text/xml"
# Bad request
response.status = 400
return
end
length = request.content_length || 0
unless length > 0
# Length required
response.status = 411
return
end
data = request.data.read(length)
if data.nil? or data.size != length
# Bad request
response.status = 400
return
end
resp = process(data)
raise if resp.nil? or resp.size <= 0 # => Internal Server Error
response.status = 200
response.header['Content-Length'] = resp.size
response.header['Content-Type'] = "text/xml"
response.body = resp
end
##
# Is called before request_handler and should return true if
# the client is allowed to connect to the server.
# `io' is a Socket object.
def ip_auth_handler(io)
if @valid_ip
client_ip = io.peeraddr[3]
@valid_ip.each { |ip|
return true if client_ip =~ ip
}
false
else
true
end
end
end end
=begin =begin
= XMLRPC::WEBrickServlet = XMLRPC::WEBrickServlet
== Synopsis == Synopsis
@ -765,6 +683,17 @@ end
httpserver.mount("/RPC2", s) httpserver.mount("/RPC2", s)
trap("HUP") { httpserver.shutdown } # use 1 instead of "HUP" on Windows trap("HUP") { httpserver.shutdown } # use 1 instead of "HUP" on Windows
httpserver.start httpserver.start
== Instance Methods
--- XMLRPC::WEBrickServlet#set_valid_ip( *ip_addr )
Specifies the valid IP addresses that are allowed to connect to the server.
Each IP is either a (({String})) or a (({Regexp})).
--- XMLRPC::WEBrickServlet#get_valid_ip
Return the via method ((<set_valid_ip|XMLRPC::Server#set_valid_ip>)) specified
valid IP addresses.
== Description == Description
Implements a servlet for use with WEBrick, a pure Ruby (HTTP-) server framework. Implements a servlet for use with WEBrick, a pure Ruby (HTTP-) server framework.
@ -777,6 +706,7 @@ class WEBrickServlet < BasicServer
def initialize(*a) def initialize(*a)
super super
require "webrick/httpstatus" require "webrick/httpstatus"
@valid_ip = nil
end end
# deprecated from WEBrick/1.2.2. # deprecated from WEBrick/1.2.2.
@ -790,7 +720,24 @@ class WEBrickServlet < BasicServer
self self
end end
def set_valid_ip(*ip_addr)
if ip_addr.size == 1 and ip_addr[0].nil?
@valid_ip = nil
else
@valid_ip = ip_addr
end
end
def get_valid_ip
@valid_ip
end
def service(request, response) def service(request, response)
if @valid_ip
raise WEBrick::HTTPStatus::Forbidden unless @valid_ip.any? { |ip| request.peeraddr[3] =~ ip }
end
if request.request_method != "POST" if request.request_method != "POST"
raise WEBrick::HTTPStatus::MethodNotAllowed, raise WEBrick::HTTPStatus::MethodNotAllowed,
"unsupported method `#{request.request_method}'." "unsupported method `#{request.request_method}'."