From 30c5be370489f9620e0f199526c80f5c34f16faa Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Thu, 29 Mar 2007 19:22:01 +0000 Subject: * Now the rest handlers try to match path as close as possibly, so it's possible to add handlers for just a beginning of a path. --- Servers/BaseHttpServer.cs | 20 ++++++++++++++++---- Servers/IRestHandler.cs | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'Servers') diff --git a/Servers/BaseHttpServer.cs b/Servers/BaseHttpServer.cs index 7c2a195..174402a 100644 --- a/Servers/BaseHttpServer.cs +++ b/Servers/BaseHttpServer.cs @@ -76,11 +76,23 @@ namespace OpenSim.Servers string response; RestMethod handler; - string methodKey = String.Format("{0}: {1}", method, path); - - if (m_restHandlers.TryGetValue(methodKey, out handler)) + string requestKey = String.Format("{0}: {1}", method, path); + + string bestMatch = String.Empty; + foreach( string currentKey in m_restHandlers.Keys ) + { + if( requestKey.StartsWith( currentKey )) + { + if(currentKey.Length > bestMatch.Length ) + { + bestMatch = currentKey; + } + } + } + + if (m_restHandlers.TryGetValue(bestMatch, out handler)) { - response = handler(request); + response = handler(request, path); } else diff --git a/Servers/IRestHandler.cs b/Servers/IRestHandler.cs index deb77d8..46459ff 100644 --- a/Servers/IRestHandler.cs +++ b/Servers/IRestHandler.cs @@ -4,5 +4,5 @@ using System.Text; namespace OpenSim.CAPS { - public delegate string RestMethod( string request ); + public delegate string RestMethod( string request, string path ); } -- cgit v1.1