evil ruby ownage

git-svn-id: file:///home/svn/incoming/trunk@2825 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Matt Miller 2005-07-25 02:39:14 +00:00
parent cfe5d10a48
commit 342c9f1cbf
2 changed files with 58 additions and 0 deletions

View File

@ -127,6 +127,31 @@ class Server
end
end
#
# Adds a resource handler, such as one for /, which will be called whenever
# the resource is requested. The ``opts'' parameter can have any of the
# following:
#
# Proc (proc) - The procedure to call when a request comes in for this resource.
# LongCall (bool) - Hints to the server that this resource may have long
# request processing times.
#
def add_resource(name, opts)
if (self.resources[name])
raise RuntimeError,
"The supplied resource '#{name}' is already added.", caller
end
self.resources[name] = opts
end
#
# Removes the supplied resource handler.
#
def remove_resource(name)
self.resources.delete(name)
end
#
# Adds Server headers and stuff
#

View File

@ -29,6 +29,39 @@ class Rex::Proto::Http::Server::UnitTest < Test::Unit::TestCase
end
end
def test_resource
begin
s = start_srv
c = CliKlass.new(ListenHost, ListenPort)
s.add_resource('/foo',
'Proc' => Proc.new { |cli, req|
resp = Rex::Proto::Http::Response::OK.new
resp.body = "Chickens everywhere"
cli.send_response(resp)
})
1.upto(10) {
req = Rex::Proto::Http::Request::Get.new('/foo')
res = c.send_request(req)
assert_not_nil(res)
assert_equal(200, res.code)
assert_equal("Chickens everywhere", res.body)
}
s.remove_resource('/foo')
req = Rex::Proto::Http::Request::Get.new('/foo')
res = c.send_request(req)
assert_not_nil(res)
assert_equal(404, res.code)
ensure
stop_srv
end
end
protected
def start_srv