* 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.

0.1-prestable
lbsa71 2007-03-29 19:22:01 +00:00
parent 514a323056
commit 30c5be3704
3 changed files with 24 additions and 12 deletions

View File

@ -35,8 +35,8 @@ namespace OpenSim.CAPS
server.AddRestHandler("POST", "/Admin/NewAccount", PostNewAccount );
server.AddRestHandler("POST", "/Admin/Login", PostLogin );
}
private string GetWelcomePage( string request )
private string GetWelcomePage(string request, string path)
{
string responseString;
responseString = "Welcome to the OpenSim Admin Page";
@ -44,7 +44,7 @@ namespace OpenSim.CAPS
return responseString;
}
private string PostLogin(string requestBody)
private string PostLogin(string requestBody, string path)
{
string responseString;
// Console.WriteLine(requestBody);
@ -61,7 +61,7 @@ namespace OpenSim.CAPS
return responseString;
}
private string PostNewAccount(string requestBody)
private string PostNewAccount(string requestBody, string path)
{
string responseString;
string firstName = "";
@ -110,7 +110,7 @@ namespace OpenSim.CAPS
return responseString;
}
private string GetConnectedClientsPage( string request )
private string GetConnectedClientsPage(string request, string path)
{
string responseString;
responseString = " <p> Listing connected Clients </p>";
@ -128,7 +128,7 @@ namespace OpenSim.CAPS
return responseString;
}
private string GetAccountsPage( string request )
private string GetAccountsPage(string request, string path)
{
string responseString;
responseString = "<p> Account management </p>";
@ -138,7 +138,7 @@ namespace OpenSim.CAPS
return responseString;
}
private string GetAdminPage( string request )
private string GetAdminPage(string request, string path)
{
return AdminPage;
}

View File

@ -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 )
{
response = handler(request);
if( requestKey.StartsWith( currentKey ))
{
if(currentKey.Length > bestMatch.Length )
{
bestMatch = currentKey;
}
}
}
if (m_restHandlers.TryGetValue(bestMatch, out handler))
{
response = handler(request, path);
}
else

View File

@ -4,5 +4,5 @@ using System.Text;
namespace OpenSim.CAPS
{
public delegate string RestMethod( string request );
public delegate string RestMethod( string request, string path );
}